[R-sig-Geo] polygons to grid?

Robert J. Hijmans r.hijmans at gmail.com
Sat Nov 21 19:21:51 CET 2009


Agus,

Please see   raster::polygonsToRaster

Let 'p' be a SpatialPolygonsDF. Create an appropriate RasterLayer
object, for example use the extent of the polygons and set the
resolution.

r <- raster(extent(p))
res(r) <- 1

# then:
r <- polygonsToRaster(p, r)   # there are additional arguments to consider

# to coerce into a SPGDF
spg <- as(r, 'SpatialGridDataFrame')


There was a discussion earlier this year, I believe, where there was
also an example to do this entirely in sp (using point in polygon
overlays)

Robert


On Sat, Nov 21, 2009 at 5:20 AM, Agustin Lobo <alobolistas at gmail.com> wrote:
> Hi?
>
> Is it possible to perform a vector to raster conversion in R,
> from SpatialPolygonsDataFrame to a SpatialGrid (providing the final
> resolution?
>
> In particular, is it possible to do it using package raster?
>
> (I know this can be done using gdal or grass etc, but I'm trying
> to find an "only R" solution)
>
> Thanks
>
> Agus
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list