Skip to content
Prev 4251 / 29559 Next

polygons from pixels.

On Mon, 29 Sep 2008, milton ruser wrote:

            
Something like this is in sp:

el1 <- as(el, "SpatialPixelsDataFrame")
el2 <- as(el1, "SpatialPolygons")
IDs <- sapply(slot(el2, "polygons"), function(x) slot(x, "ID"))
df <- as(el1, "data.frame")
row.names(df) <- IDs
el3 <- SpatialPolygonsDataFrame(el2, data=df)
spplot(el3, "band1", col.regions=heat.colors(20))

The actual coercion is from SpatialPixels to SpatialPolygons, so the data 
need to be put back in.

Roger