[R-sig-Geo] Overlaying a grid onto a set of points

Gavin Simpson gavin.simpson at ucl.ac.uk
Mon May 28 23:00:41 CEST 2012


Dear List,

I have a SpatialGrid object - a regular 5km by 5km over the entire land
mass of Great Britain & NI - and a SpatialPointsDataFrame containing a
@data slot with several attributes.

I want to identify which points are in each grid cell and average the
values of the individual attributes from the points within each cell.
Not all cells will contain a point (for those an `NA` returned value is
fine) though some cells will contain many points. Later I may wish to
calculate some other summary (min or max) rather than mean.

If I understand correctly, this gives the desired result:

aggregate(fabResults.sp, by = frameGrid, FUN = mean)

where `fabResults.sp` is my SpatialPointsDataFrame and `frameGrid` is my
Spatial Grid. This takes a while to compute however.

I was unable to come up with an `over()` call that worked.

Have I got the `aggregate()` step right? Is there a way to use `over()`
to do the same operation? Am I missing a better alternative?

Thanks in advance,

Gavin
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-sig-Geo mailing list