[R-sig-Geo] raster::polygonValues?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Apr 18 20:55:14 CEST 2012


On Wed, Apr 18, 2012 at 6:32 PM, Christopher Swingley
<cswingle at gmail.com> wrote:
> Greetings!
>
> I'm re-running a script I used in 2009 that looked similar to the
> following.  The idea is to intersect a series of watershed polygons
> with rasters of climate data and calculate some basin statistics for
> each basin x climate raster.
>
> library(raster)
> library(rgdal)
> grids <- list.files('climatology', pattern = '*.tif$')
> basins <- readOGR('basins', 'all_basins')
> for (grid in grids) {
>  r <- raster(grid)
>  v <- polygonValues(basins, r)
>  basin_means <- sapply(v, mean)
>  basin_sd <- sapply(v, sd)
>  basin_n <- sapply(v, length)
> }
>
> But now I get 'Error: could not find function "polygonValues"'.
> Searches on the Internet lead me to believe 'polygonValues' is in the
> raster package, and it's mentioned in four places in the raster
> package changelog, but I can't find mention of it's removal.
>
> Has polygonValues been replaced with something else?  Did this
> morning's "install.packages('raster')" not build the whole thing
> somehow?

 I think you probably want to use extract(raster,polys) - I answered a
very similar question on gis.stackexchange.com the other day:

http://gis.stackexchange.com/questions/23614/get-raster-values-from-a-polygon-overlay-in-opensource-gis-solutions/23628#23628

Barry



More information about the R-sig-Geo mailing list