[R-sig-Geo] Clipping grid using shapefile?
Christopher Swingley
cswingle at gmail.com
Mon Mar 1 20:03:06 CET 2010
Greetings!
I'm quite new to the spatial functions in R (and to R as well), and am
having trouble getting R to clip an ASCII grid using a shapefile raster.
What I've got are ASCII grids that store climatological variables (one
grid for each variable; temperature, precip, etc.). I also have a
shapefile containing a series of watershed polygons. What I want to do
is clip the ASCII grid using each polygon in the shapefile and calculate
the mean and standard deviation of the climate data within each polygon.
Reading the data in:
> library(rgdal)
> library(sp)
> vector <- readOGR("shapefiles", "watersheds")
> ppt01 <- readGDAL("ppt01.asc")
> proj4string(ppt01) <- CRS("+proj=aea +lat_1=55 +lat_2=65 +lat_0=50
+lon_0=-154 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs
+towgs84=0,0,0")
I think overlay() is the function I want, but I'm not getting the
results I expect. After the clipping, I'd like to be able to do:
> means <- mean(ppt01_clip, na.rm = TRUE)
> sds < -sd(ppt01_clip, na.rm = TRUE)
And get a table of watershed IDs with their means, and a table of
watershed IDs with their standard deviations.
Thanks,
Chris
--
Christopher S. Swingley
http://swingleydev.com/
<cswingle at gmail.com>
More information about the R-sig-Geo
mailing list