[R-sig-Geo] merging polygons and IDs

David Depew depewd at gmail.com
Sun Jan 11 19:31:47 CET 2015


Dear list,

given a set of polygons created from points with a specified buffer
distance,

library(sp)
library(rgeos)
box <- readWKT("POLYGON((0 0, 0 1000, 1000 1000, 1000 0, 0 0))")
plot(box)
set.seed(1)
pts <- spsample(box, n=40, type="random")
pols <- gBuffer(pts, byid=TRUE, width=50)
plot(pols, add=TRUE)


I'd like to merge polygons where the buffers overlap
i.e.
merg.poly=gUnaryUnion(pols)
plot(merg.poly)

but I'm having difficulty figuring out how to specify that the merged
polygons retain some unique Id. Clearly in the package help, one would
specify this by use of the "id" argument, however since the polygons
started as points, overlapping points do not have the same ID. Suppose one
approach is to define a common ID for overlapping polys before using
gUnaryUnion, but I'm at a loss where to begin with that approach. Any
advice would be greatly appreciated,

Thanks,

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list