[R-sig-Geo] Polygon to raster?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Sun Aug 2 20:38:54 CEST 2009


On Sun, Aug 2, 2009 at 7:26 PM, Jonathan Greenberg<greenberg at ucdavis.edu> wrote:
> I'm trying to hunt down a function that will take a polygon (derived from a
> shapefile) and "rasterize" it at a given pixel resolution -- any hints?

 You could plot it to a png graphics device:

 require(rgdal)
 require(sp)
 myPolygon = readOGR("foo.shp") # or similar...

 png(file="raster.png",height=100,width=100)
 plot(myPolygon)
 dev.off()

 that might plot it with slightly too wide margins though, so there
may be some tweaking required with par(....) after opening the png
device.

Barry



More information about the R-sig-Geo mailing list