View source: R/data-facelayer-resample.R
gridensity | R Documentation |
Spatial density estimation algorithm based on rotation of icosahedral grids.
gridensity(x, y, out, trials = 100, FUN = mean)
x |
Matrix of longitude, latitude data, |
y |
|
out |
|
trials |
|
FUN |
|
Any points set can be binned to an icosahedral grid (i.e. number of incidences can be counted), which will be dependent on the exact positions of grid cells. Rotating the grid in 3d space will result in a different distribution of counts. This distribution can be resampled to a standard orientation structure. The size of the icosahedral grid cells act as a bandwidth parameter.
The implemented algorithm 1) takes a point cloud (x
)) and an icosahedral grid y
2) randomly rotates the icosahedral grid, 3) looks up the points falling on grid cells, 4) resamples the grid to a constant orientation object (either trigrid
, hexagrid
or SpatRaster
). Steps 2-4 are repeated trial
times, and then FUN
is applied to every vector of values that have same spatial position.
Either named numeric vector, or a SpatRaster
object. If FUN is set to NULL
, the output will be either a matrix
or SpatRaster
.
# example to be run if terra is present
if(requireNamespace("terra", quietly=TRUE)){
# randomly generated points
x <- rpsphere(100, output="polar")
# bandwidth grid
y <- hexagrid(deg=13)
# output structure
out <- terra::rast(res=5)
# the function
o <- gridensity(x, y, out, trials=7)
# visualize results
terra::plot(o)
points(x, pch=3)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.