Skip to content
Prev 2280 / 29559 Next

vector to raster

Agustin Lobo wrote:
Yes, using the classes and methods in sp -- you'd first have to create a 
grid e.g. with spsample, sampling type regular or makegrid. Next, if you 
want to have the polygon values at grid cell centres, overlay the 
polygons with the grid, using the overlay method.

 > library(sp)
 > data(meuse.riv)
 > meuse.sr = SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)), "x")))
 >
 > plot(meuse.sr)
 > points(spsample(meuse.sr, n = 1000, "regular"), pch = 3)
 > class(meuse.sr)
[1] "SpatialPolygons"
attr(,"package")
[1] "sp"
 > pts = spsample(meuse.sr, n = 1000, "regular")
 > class(pts)
[1] "SpatialPoints"
attr(,"package")
[1] "sp"
 > gridded(pts)=T
 > class(pts)
[1] "SpatialPixels"
attr(,"package")
[1] "sp"

--
Edzer