[R-sig-Geo] Creating polygons out of an irregular data set to represent specific classes

Sébastien Durand v8extra at gmail.com
Fri Dec 3 05:09:23 CET 2010

I am getting there! I only need to find a way to merge the adjacent independent polygons!

Here is what I found a marvelous package : raster...  which have "rasterToPolygons"

ak.li=interp(akima$x, akima$y, akima$z, xo=seq(min(akima$x), max(akima$x), length = dimgrid),yo=seq(min(akima$y), max(akima$y), length = dimgrid),linear = TRUE, extrap=FALSE, duplicate = "mean")
with(akima, text(x, y, formatC(z,dig=2), adj = -0.1))

r <- raster(nrow=length(ak.li$y), ncol=length(ak.li$x), crs=NA)
xmin(r) <- min(ak.li$x, na.rm=TRUE)
xmax(r) <- max(ak.li$x, na.rm=TRUE)
ymin(r) <- min(ak.li$y, na.rm=TRUE)
ymax(r) <- max(ak.li$y, na.rm=TRUE)
tmp=apply(tmp, 1, rev)
r[] <- tmp

pol <- rasterToPolygons(r, fun=function(x){x>20 & x<25})
plot(pol, add=T, col='red')


So if any body have an hit on how to merge the adjacent polygons into one. (or different groups of adjacent polygons into larger polygons). 

I would be very happy to know it!


More information about the R-sig-Geo mailing list