[R-sig-Geo] Union sp polygons ID (rgoes and sp)

Omphalodes Verna omphalodes.verna at yahoo.com
Sat Mar 16 15:38:29 CET 2013


Dear list.

I would like to do union of many polygons in R (rgeos) with ''gUnion'' function (in attached code only 5). Final result should be polygons with unique ID (using attached code it is), but when I plot them (colors by ID value), there are only 5 polygons. Please, give me some idea.
Thanks to all,
OV

RCode:
library(rgeos)
library(sp)
n <- 5
xy <- cbind(runif(n), runif(n), runif(n), runif(n))
LLine <- vector("list", n)
LLines <- vector("list", n)
for(i in 1:n) LLine[[i]] <- Line(rbind(xy[i, 1:2], xy[i, 3:4]))
for(i in 1:n) LLines[[i]] <- Lines(LLine[[i]], ID = i)
SPLines <- SpatialLines(LLines)
SPLpoly <- gBuffer(SPLines, width = 0.05, byid = TRUE)
plot(SPLines, col = getSLLinesIDSlots(SPLines))
plot(SPLpoly, add = TRUE, col = getSLLinesIDSlots(SPLines))
SPLpolyA <- SPLpoly
SPLpolyB <- SPLpoly
gU = gUnion(SPLpolyA, SPLpolyB,  byid = TRUE)
plot(gU, col = rainbow(length(gU)))




More information about the R-sig-Geo mailing list