[R-sig-Geo] sum of point values within a grid square
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Sun Apr 6 23:03:14 CEST 2008
Andrew,
this is a bug; thanks for the clear report.
the code in cvs has it corrected, meaning that the next CRAN release
should work.
I also noted that fn is ignored for grids; it should work there too, so
that the lengthy
g.poly <- as(g, "SpatialPolygons")
wouldn't be required. This still needs some work.
--
Edzer
Andrew James Hoskins wrote:
> Hi all,
>
> I'm trying to get the sum of value z for all points that fall within a grid
> square. I've been trying to use the overlay function on a grid converted to
> polygons, however, it returns the sum of the coordinates and the z values,
> how can I have it return only the sum of z?
> Also, once I have the sum of z how then can I assign that to it's
> corresponding grid square?
>
> ## Example code
>
> g <- GridTopology(c(-10,-10), c(1,1), c(21,21))
> g.poly <- as(g, "SpatialPolygons")
>
> x <- c(1:10,1:10)
> y <- c(10:1,10:1)
> z <- 1:20
>
> xyz <- SpatialPointsDataFrame(cbind(x,y),data.frame(z))
>
> ol <- overlay(xyz, g.poly, fn=sum)
>
>
> Thanks in advance.
>
> Andrew.
>
>
>
>
More information about the R-sig-Geo
mailing list