polygons from pixels.
On Mon, 29 Sep 2008, milton ruser wrote:
Dear RGeo-Gurus,
I have a ASC file, and would like that each pixel come to be a polygon.
Any help are welcome.
require(rgdal)
require(adehabitat)
(file1 <- paste(system.file(package = "adehabitat"),
"ascfiles/elevation.asc", sep = "/"))
el <- readGDAL(file1)
image(el, axes=T)
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
best wishes, miltinho astronauta brazil [[alternative HTML version deleted]]
_______________________________________________ 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