Dear list, Trying to find out a solution for obtaining the mean of interpolated values within several polygons I found 2 ways for solving it, but the results are slightly different:
Using the meuse dataset and a gstat example: r1 = cbind(c(180114, 180553, 181127, 181477, 181294, 181007, 180409, 180162, 180114), c(332349, 332057, 332342, 333250, 333558, 333676, 332618, 332413, 332349)) r2 = cbind(c(180042, 180545, 180553, 180314, 179955, 179142, 179437, 179524, 179979, 180042), c(332373, 332026, 331426, 330889, 330683, 331133, 331623, 332152, 332357, 332373)) r3 = cbind(c(179110, 179907, 180433, 180712, 180752, 180329, 179875, 179668, 179572, 179269, 178879, 178600, 178544, 179046, 179110), c(331086, 330620, 330494, 330265, 330075, 330233, 330336, 330004, 329783, 329665, 329720, 329933, 330478, 331062, 331086)) sr1=Polygons(list(Polygon(r1)),"r1") sr2=Polygons(list(Polygon(r2)),"r2") sr3=Polygons(list(Polygon(r3)),"r3") sr=SpatialPolygons(list(sr1,sr2,sr3)) srdf=SpatialPolygonsDataFrame(sr, data.frame(cbind(1:3,5:3), row.names=c("r1","r2","r3"))) data(meuse) coordinates(meuse) = ~x+y data(meuse.grid) coordinates(meuse.grid) = ~x+y gridded(meuse.grid) = TRUE # 1st Approach: Interpolating with IDW using the 'mueuse.grid' as 'newdata' and then 'overlay' x.idw <- krige(log(zinc)~1, locations=meuse, newdata=meuse.grid) # Getting the mean values in each polygon overlay(x.idw["var1.pred"], srdf, fn = mean) # var1.pred #X1 5.8697 #X2 5.6525 #X3 5.8536 # 2nd Approach: Interpolating with IDW using the 3 polygons as 'newdata' x.idw.block <- krige(log(zinc)~1, locations=meuse, newdata=srdf ) # Getting the mean values in each polygon x.idw.block["var1.pred"]...@data #var1.pred #r1 5.9090 #r2 5.6700 #r3 5.8564 I would really appreciate if you can give some hint about why the results are different for each polygon. Thanks in advance, Mauricio -- ============================================= Linux user #454569 -- Ubuntu user #17469 ============================================= "A journey of a thousand miles begins with a single step" (Lao Tse) _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo