[R-sig-Geo] Counting number of points per pixel in a grid

Heather Kharouba kharouba at zoology.ubc.ca
Tue Oct 20 19:38:07 CEST 2009


Hi,

I would like to count the number of points per pixel in a grid(there are
thousands of points and thousands of pixels). I have a list of occurrence
points and a grid with a given cell size. Ideally I'd like them saved to
one file where there is a column listing the pixel number and one listing
number of points for that pixel. I've tried overlay (sp package) but it
just spits out a list of all the points in my list with NA value attached
to each point and it doesn't provide a count:

this is my code so far:
grid=readGDAL("mask50")
proj4string(grid)=CRS("+proj=lcc")
x1<-read.csv(file.choose(),header=TRUE,sep=",", na.strings="");
proj4string(x1)=CRS("+proj=lcc")
o<-overlay(grid, x1)
o
NA.33354  (49.71, -97.91)    NA
NA.33355   (50.7, -98.03)    NA
NA.33356  (56.35, -94.66)    NA
NA.33357    (50.83, -100)    NA
NA.33358  (49.36, -96.11)    NA

I'm wondering whether I need to set up a loop for each pixel.
I've also had no luck with count.points.id (adehabitat package). When I
use this function, I get a summary of my grid. Any thoughts would be much
appreciated!

Thanks,
Heather Kharouba



More information about the R-sig-Geo mailing list