[R-sig-Geo] convert point data to count data

Adrian.Baddeley at csiro.au Adrian.Baddeley at csiro.au
Fri Jun 12 17:36:30 CEST 2009

Karla Falk writes:

> I have a data set of points that I would like to convert to grid cell counts.

> Ultimately I would like to end up with a table that has an x-y coordinate for each grid cell,

> and the count of the # of points falling in each grid cell.  Does anyone know a way to do this in R?

> I have been playing around with using quadratcounts in spatstat, and the overlay methods in sp,

> but with both I can't figure out how to get an output table of the cell counts (including counts of zero's)

> with the corresponding x-y utm of the grid cell.

You can use the command 'pixellate' in spatstat.



Z <- pixellate(redwood, eps=0.1, padzero=TRUE)

df <- data.frame(x=rasterx.im(Z), y=rastery.im(Z), count=as.vector(as.matrix(Z)))

Then 'df' is the output table you wanted. To display it,


with(df, text(x,y,count))

The size of the grid cells can be controlled using 'eps' (for squares of side length 'eps')

or 'dimyx' (specifying the number of rows and columns of cells).

Adrian Baddeley

More information about the R-sig-Geo mailing list