[R-sig-Geo] Clipping grid using shapefile?

Edzer Pebesma edzer.pebesma at uni-muenster.de
Mon Mar 1 20:35:39 CET 2010


Hi Chris,

please tell us what was unexpected after you overlayed vector and ppt01.

Christopher Swingley wrote:
> 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
>   

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster 
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251 
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de 
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list