[R-sig-Geo] How do I use neighbourhood list to recursively merge adjacent polygons

Roger Bivand Roger.Bivand at nhh.no
Tue Sep 7 14:01:02 CEST 2010


On Tue, 7 Sep 2010, christiaan pauw wrote:

> Hallo Everybody
>
> I have a SpatialPolygonsDataFrame where residential stands in a town
> are given as polygons.  The streets are "represented" by the empty
> space between the polygons. I want to dissolve the stand boundaries
> within a street block to get just the outer extent of a street block.
> My aim is this to move from a map of individual houses to a map of
> street blocks.
>
> The criterion for merging is that they touch an neighbouring polygon
> (queen). Merging should continue until there are no polygons left
> touch each other i.e until you only have the street blocks separated
> by the empty space where the streets are.  I have tried to use
> unionSpatialPolygons but have not found a way in which is can define
> which polygons to merge since I do not know how to define the "IDs"
> argument correctly. I had a feeling that I could specify which
> polygons to merge with poly2nb but poly2nb does not work recursively -
> i.e. the same polygon can be found in more than one entry on the nb
> list.
>
> I was also looking for a data set to build a self-contained example
> with (like a map of the world where one can dissolve the country
> boundaries and end up only with continents) but could not find one
>
> Can anyone offer me some advice

Please look at ?n.comp.nb in spdep. This finds the number of separate 
graph components in an nb object, returns the count, and a vector saying 
which observation belongs to which disjoint connected subgraph. If there 
are no contiguities across the streets, you should see each subgraph 
matching your street blocks. Try using the subgraph vector to colour a map 
of the residential polygons, or nodes in a plot of the nb object (see the 
example for n.comp.nb. From there on unionSpatialPolygons() if n.comp.nb() 
makes the classification you need.

Hope this helps,

Roger


> Regards
> Christiaan
>
> _______________________________________________
> 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