Skip to content

Counting points in a pixel grid

1 message · Adrian Baddeley

#
Heather Kharouba <kharouba at zoology.ubc.ca> writes:
Try 'pixellate.ppp' in the library 'spatstat'. 

First convert your point coordinates to a point pattern X (object of class "ppp") using ppp() or as.ppp().

Then, for example if you want square pixels of side length 3 units,
        Z <- pixellate(X, eps=3)
You can specify the exact coordinates of the pixel centres by 
        Z <- pixellate(X, xy=list(x=xcoord, y=ycoord))
where xcoord and ycoord are vectors of the pixel coordinates.

The result Z is an integer valued pixel image (object of class "im"). 
Use 'as.data.frame' to convert it to the format you wanted.
To write to an output file in the desired format,

      sink("results.txt")
     as.data.frame(Z)
     sink()


Adrian Baddeley