[R-sig-Geo] overlay raster by polygons: average values

Robert Hijmans r.hijmans at gmail.com
Wed Mar 2 08:41:20 CET 2011


>I've got a SpatialGridDataFrame SG with density values given by spatstat 
>package 
>I want to get the average values of this grid for each polygon of a dataset 
>named iris 

Mathieu,  

I think you can do this:

library(raster)
#make a RasterLayer
r <- raster(SG)
# extract mean values for polygons in iris.b
v <- extract(r, iris.b, fun=mean)
# assign these to a new variable
iris.b$newvalues <- v

I think you can also accomplish this with %over% (sp package) in stead of
extract

Robert

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/overlay-raster-by-polygons-average-values-tp6076739p6079949.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list