Package {GeoDensityR}


Type: Package
Title: Generate Density Rasters from Polygon and Census Data
Version: 0.2.2
Description: Creates continuous density raster surfaces by joining vector spatial layers with tabular data frameworks, normalizing values by ellipsoidal polygon area calculations. Reconciles discrete boundary-constrained census or survey counts with uniform grids. Accepts spatial objects in-memory or via file paths. Methods are based on spatial rasterization workflows implemented in the 'terra' package Hijmans (2025) https://rspatial.github.io/terra/.
License: MIT + file LICENSE
Encoding: UTF-8
Depends: R (≥ 4.1.0)
Imports: terra, tools, stats, utils
Suggests: testthat (≥ 3.0.0), knitr, rmarkdown
VignetteBuilder: knitr
URL: https://github.com/sahalpaladan/GeoDensityR
BugReports: https://github.com/sahalpaladan/GeoDensityR/issues
Config/roxygen2/version: 8.1.0
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-11-17 04:37:48 UTC; sahal_paladan
Author: Sahal Paladan [aut, cre], Mohammed Mudassar Chanda [aut]
Maintainer: Sahal Paladan <sahalpaladan@gmail.com>
Repository: CRAN
Date/Publication: 2026-11-17 08:40:18 UTC

Generate Density Raster from Polygon and Tabular Data

Description

Creates a continuous density raster surface by joining vector spatial layers with tabular data frameworks, normalizing values by ellipsoidal polygon area calculations.

Usage

generate_density_raster(
  spatial_target,
  attribute_table,
  join_spatial,
  join_attribute,
  value_col,
  resolution = 0.1,
  output = NULL
)

Arguments

spatial_target

A terra::SpatVector, sf::sf object, or a path string to a shapefile.

attribute_table

A data.frame, tibble, or path string to a CSV file.

join_spatial

Character. The indexing key column found within the spatial vector object.

join_attribute

Character. The indexing key column found within the attribute table.

value_col

Character. Numeric column containing values to evaluate for density calculation.

resolution

Numeric. The cell size of the output raster, in the units of the layer's coordinate reference system.

output

Optional character. A target filepath string (.tif or .asc) to write the raster to disk.

Details

Keys are matched without regard to case or surrounding whitespace. If several polygons share a key (for example a state made of separate islands), the value is divided by their combined area, so each of those polygons gets the same density and the total is not counted more than once. Polygons with no matching table row receive NA and a warning is issued. Duplicated keys in the attribute table are an error.

Areas are computed on the ellipsoid with terra::expanse(), whatever the coordinate reference system of the layer. The cell size resolution is, however, in the units of the layer's coordinate reference system (degrees for longitude/latitude, usually metres otherwise), and a warning is given if the layer is not in longitude/latitude. Each cell takes the density of the polygon containing its centre, so the sum of cell density times cell area can differ slightly from the original total.

Value

A terra::SpatRaster object representing computed density surfaces.

Examples

## Not run: 
result <- generate_density_raster(
  spatial_target = standard_polygon_object,
  attribute_table = census_dataframe,
  join_spatial = "District_ID",
  join_attribute = "ID",
  value_col = "Population",
  resolution = 0.05
)

## End(Not run)