[R-sig-Geo] extracting simple list of adjacent neighbours

Moritz Lennert mlennert at club.worldonline.be
Tue Sep 6 10:54:22 CEST 2011


Hello,

I have a very simple problem, which I know will have a simple solution, 
but I just can't get my head wrapped around it.

I have a shapefile with regions, including an attribut containing a 
regional id.

I would like to extract a simple neighbourhood file, with neighbourhood 
defined by simple adjacency with symmetry of relationship in both 
directions.

Ideally, I would like to get something like this:

id_region_1 id_neighbour_1
id_region_1 id_neighbour_2
id_region_1 id_neighbour_3
id_region_2 id_neighbour_1
id_region_2 id_neighbour_2
id_region_3 id_neighbour_1
etc

What I've done so far:

originalmap<-readShapePoly("/path/to/shapefile.shp")
nb<-poly2nb(originalmap, row.names=originalmap$idcolumn)

With nb[] I can see that the list of lists of neighbours and the list of 
id's.

Here's where I'm stuck. How do I get a list as above with the row names 
defined in the poly2nb call ?
Or as an intermediate solution: how do I replace the line id's in the 
lists with the regional id's in the list of id's to at least get 
something like this:

id_region_1 id_neighbour_1 id_neighbour_2 id_neighbour_3
id_region_2 id_neighbour_1 id_neighbour_2
id_region_3 id_neighbour_1 etc..

?

I imagine that this is a very simple operation, but I just can't seem to 
find the way. Any pointers to doc is welcome.

Moritz



More information about the R-sig-Geo mailing list