KDE for spatial data. The algorithm is heavily inspired by Heatmap tool in QGIS. The help for QGIS tools is provided at the QGIS website. The a tutorial is provided here.
sf
data.frame
containing only POINTS.
numeric
specifying the band width for KDE.
numeric
specifying the decay parameter for "triangular"
kernel. For
other kernels besides "triangular"
the parameter is not used.
character
specifying type of kernel to use. Available implemented kernels are
"uniform", "quartic", "triweight", "epanechnikov", "triangular"
. Default is "quartic"
and if
unknown kernel name is used it falls back to the default value.
logical
specifying if the output values should be scaled. Default value is
FALSE
.
numeric
vector of weights for individual points
.
either sf
data.frame
(outcome of function
create_grid_rectangular
or create_grid_hexagonal
) or
Raster-class
(outcome of function create_raster
).
Does not have to be specified if cell_size
is set.
numeric
specifying the distance for equal spaced points. Must be
higher than 0. Can be left out if grid
is provided as grid
is used instead.
The code used to generate grid is create_grid_rectangular(points, cell_size, band_width)
.
Should printing of progress bar be suppressed? Default `FALSE`.
grid
parameter specifies output of the function. KDE is calculated on the specified grid
.
If grid is Raster-class
then outcome is also Raster-class
.
If grid is sf
data.frame
then outcome is also sf
data.frame
.
library(sf)
nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(32031)
#> Reading layer `nc' from data source
#> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS: NAD27
grid <- create_grid_hexagonal(nc, cell_size = 100000)
points <- st_sample(nc, 500) %>% st_as_sf()
kde_estimate_grid <- kde(points, band_width = 150000, grid = grid)
#> Using centroids instead of provided `grid` geometries to calculate KDE estimates.
raster <- create_raster(nc, cell_size = 100000)
kde_estimate_raster <- kde(points, band_width = 150000, grid = raster)