[R-sig-Geo] Neighbor matrix from shp file

Roger Bivand Roger.Bivand at nhh.no
Tue May 11 22:40:32 CEST 2010


On Tue, 11 May 2010, Barry Rowlingson wrote:

> On Tue, May 11, 2010 at 9:10 PM, Peter Larson <pslarson2 at gmail.com> wrote:
>> Hello,
>>
>> I have a shp file of polygons of US counties and want to generate an
>> adjacency matrix (neighbor matrix).
>>
>> Is there an easy way to do this? It seems like it should be trivial.
>
> poly2nb in the spdep package will produce a list of adjacencies, and
> from that you can make a full adjacency matrix if you want, but it
> will probably be very sparse.
>
> However... polygons that look adjacent might be very very close and
> not found as adjacent by poly2nb. I'm investigating this with some of
> my data at the moment...

Use the snap= argument to poly2nb() set to a larger but still small value 
than default in that case, say 10m for projected coordinates.

Barry, if you'd like to try SVN spdep from R-forge (and maybe also SVN 
rgeos from R-forge), you'll find a number of speedups. Any feedback on 
those would be very welcome.

Roger

>
> Barry
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list