An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100409/6d06d655/attachment.pl>
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:
Dear All,
I have created a grid for the State of FL using following command:
locpred = expand.grid(X=seq(-117026, 582149, 10000), Y=seq(2783590, 3443337, 10000))
plot(locpred)
The Gulf of Mexico is also included in the above grid.
I am using following command to import a shape file of FL:
library(maptools)
vector = readShapePoly("County_BND.shp")
plot(vector)
Now, I am looking for some code which can help me in obtaining exact grid of FL using above imported shape file as a clipping surface.
It will be great if somebody can guide me on the same as I am not getting any success in finding the code. Alternate procedure is also welcome!
Cheers,
Puneet Dwivedi
? ? ? ?[[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