Skip to content

Clip a shpae file with a grid

2 messages · Dwivedi,Puneet, Robert J. Hijmans

#
Dear Puneet,

To clip a grid with a your polygon 'vector' you can do:

library(raster)
r = raster( extent(-117026, 582149, 2783590, 3443337) )
res(r) = 10000
rc = crop(r, vector)

If you want to know which cells are land and which are not:
rp = polygonsToRaster(vector, rc, field=-1)
plot(rp)

# rp is now a RasterLayer object with cell values 1 where the polygons
overlaps the center of the cell and NA in other cells.

plot(rp)

Robert
On Fri, Apr 9, 2010 at 8:00 AM, Dwivedi,Puneet <puneetd at ufl.edu> wrote: