| Title: | Kernel Density Estimation for Spatial Data |
|---|---|
| Description: | Calculate Kernel Density Estimation (KDE) for spatial data. The algorithm is inspired by the tool 'Heatmap' from 'QGIS'. The method is described by: Hart, T., Zandbergen, P. (2014) <doi:10.1108/PIJPSM-04-2013-0039>, Nelson, T. A., Boots, B. (2008) <doi:10.1111/j.0906-7590.2008.05548.x>, Chainey, S., Tompson, L., Uhlig, S.(2008) <doi:10.1057/palgrave.sj.8350066>. |
| Authors: | Jan Caha [aut, cre] (ORCID: <https://orcid.org/0000-0003-0165-0606>) |
| Maintainer: | Jan Caha <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.8.2 |
| Built: | 2026-05-31 09:26:11 UTC |
| Source: | https://github.com/JanCaha/SpatialKDE |
Create grid of equally spaced rectangles or hexagons. The distance between centre points
in both x and y dimension is equal to cell_size. The function is effectively a wrapper around
st_make_grid with a little bit of preprocessing including generation of grid only inside
st_convex_hull.
create_grid_rectangular( geometry, cell_size, side_offset = 0, only_inside = FALSE ) create_grid_hexagonal( geometry, cell_size, side_offset = 0, only_inside = FALSE )create_grid_rectangular( geometry, cell_size, side_offset = 0, only_inside = FALSE ) create_grid_hexagonal( geometry, cell_size, side_offset = 0, only_inside = FALSE )
geometry |
|
cell_size |
|
side_offset |
|
only_inside |
|
sf data.frame.
create_grid_rectangular(): Create rectangular grid
create_grid_hexagonal(): Create hexagonal grid
library(sf) nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(32031) grid <- create_grid_hexagonal(nc, cell_size = 100000) grid <- create_grid_rectangular(nc, cell_size = 100000, only_inside = TRUE)library(sf) nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(32031) grid <- create_grid_hexagonal(nc, cell_size = 100000) grid <- create_grid_rectangular(nc, cell_size = 100000, only_inside = TRUE)
Create raster of equally spaced cells. The distance between centre of cells
in both x and y dimension is equal to cell_size.
create_raster(geometry, cell_size, side_offset = 0)create_raster(geometry, cell_size, side_offset = 0)
geometry |
|
cell_size |
|
side_offset |
|
library(sf) nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(32031) raster <- create_raster(nc, cell_size = 100000)library(sf) nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(32031) raster <- create_raster(nc, cell_size = 100000)
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.
kde( points, band_width, decay = 1, kernel = c("quartic", "uniform", "triweight", "epanechnikov", "triangular"), scaled = FALSE, weights = c(), grid, cell_size, quiet = FALSE )kde( points, band_width, decay = 1, kernel = c("quartic", "uniform", "triweight", "epanechnikov", "triangular"), scaled = FALSE, weights = c(), grid, cell_size, quiet = FALSE )
points |
|
band_width |
|
decay |
|
kernel |
|
scaled |
|
weights |
|
grid |
either |
cell_size |
|
quiet |
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.
either sf data.frame or Raster-class
depending on class of grid parameter.
library(sf) nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(32031) 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) raster <- create_raster(nc, cell_size = 100000) kde_estimate_raster <- kde(points, band_width = 150000, grid = raster)library(sf) nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(32031) 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) raster <- create_raster(nc, cell_size = 100000) kde_estimate_raster <- kde(points, band_width = 150000, grid = raster)