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

Christopher Swingley cswingle at gmail.com
Tue Mar 2 22:31:04 CET 2010


All,

* Christopher Swingley <cswingle at gmail.com> [2010-Mar-02 07:24 AKST]:
>     > library(rgdal)
>     > library(sp)
>     > vector <- readOGR("Watersheds", "DENA")
>     > ppt01 <- readGDAL("Climate/ppt01.asc")
>     > clip <- overlay(ppt01, vector[vector$SITECODE=='DENA-001',])
>     > mean(ppt01 at data[[1]][!is.na(clip)])
>     > sd(ppt01 at data[[1]][!is.na(clip)])

An alternative, and quite a bit faster, method:

    > library(raster)
    > library(rgdal)
    > polygons <- readOGR("Watersheds", "DENA")
    > r <- raster("grid_dir")
    > v_dena <- polygonValues(dena, r)
    > means_dena <- lapply(v_dena, mean)

Cheers,

Chris
-- 
Christopher S. Swingley
http://swingleydev.com/
<cswingle at gmail.com>



More information about the R-sig-Geo mailing list