I have a set of georeferenced points within an area for which I want to know the spatial distribution (sparse/clustered) according to a regular grid.
I thought to describe the pattern using the Clark-Evans index (from spatstat.core
package) so that I get a single value describing it...and this could be spatialised within the whole study area through a raster (I know that aggregation is scale-dependent but that's also part of the research interest).
Unfortunately, I can't achieve the rasterization process in a "smooth" way with R
. The two approaches which I though of look something like:
my_fun = function(x,y){
out = spatstat.core::clarkevans(spatstat.geom::ppp(x,y,window = ?))
return(out)
}
terra::rasterize(data, myraster, fun=my_fun)
or
lidR::pixel_metrics(data, fun=my_fun(X,Y), res=1)
Both approaches lack of a fondamental parameter: the window
...and indeed points are dropped. ppp
objects need a owin
object which, in this case, it would be constituted by the pixel boundaries. But how can I provide a window at that stage? I guess creating a method?
Right now I'm using a pretty time-consuming workaround such as:
- convert raster pixels to polygons
- loop the aggregation function through each polygon/window
- revert back to raster making use of
X,Y
from the centroid and the index value I get.
Any smooth solution or methodological alternative?