[R-sig-Geo] overlay spatialgrid on spatial polygons data frame
Agustin Lobo
alobolistas at gmail.com
Thu May 20 13:40:55 CEST 2010
I have an SpPolDF and a coarse SpatialGrid, i.e.,
srdf=SpatialPolygonsDataFrame(sr, data.frame(cbind(1:3,5:3),
row.names=c("r1","r2","r3")))
#the one used in help(overlay);
> srdf at data
X1 X2
r1 1 5
r2 2 4
r3 3 3
> bbox(srdf)
min max
x 178544 181477
y 329665 333676
> test <- SpatialGrid(GridTopology(cellcentre.offset=c(178440,329600), cellsize=c(500,500), cells.dim=c(8,10)))
> plot(srdf)
> plot(test,add=T)
My goal is to "overlay" test over srdf and tranfer the data in
srdf at data to a data frame associated
to test (=> test must become a SpatialGridDF) so that each cell has
the average value of the overlaid srdf at data polygon(s) weighted
by area: in case 25% of a given cell in test would overlay polygon r1
and 75% polygon r2, the value of X1 for that cell would be
0.25*1 + 0.75*2
According to help(overlay),
"Value
a numerical array of indices of x on locations of y, or a data.frame
with (possibly aggregate) properties of x in units of y"
I've tried this:
> overlay(srdf, test, fn=mean, na.rm)
X1 X2
NA NA NA
NA.1 NA NA
Cannot go beyond, perhaps overlay() is not suited for this: the
definition of overlay in its help page
"overlay combines points (or grids) and polygons by performing
point-in-polygon operation on all point-polygons combinations"
is a bit confusing, the first part of the sentence gives me some hope
but the second one seems to exclude what I'm trying to do.
Any help appreciated (or perhaps pointing to more doc?)
Agus
More information about the R-sig-Geo
mailing list