spatcovar provides a consistent interface for constructing commonly used
spatial covariates from polygon data. It computes polygon areas, distances to
reference features, intersection counts, line lengths within polygons, polygon
overlap areas and shares, and raster zonal summaries while handling coordinate
reference system validation, geometry repair, unit conversion, row
preservation, and standardised missing-value semantics.
spatcovar builds on established spatial engines
(sf,
terra,
exactextractr)
rather than reimplementing the underlying geometry operations.
Install the released version from CRAN:
install.packages("spatcovar")
Alternatively, install the development version from GitHub:
# install.packages("pak")
# pak::pak("emre-cebeci/spatcovar")
install.packages("spatcovar", repos = c('https://emre-cebeci.r-universe.dev', 'https://cloud.r-project.org'))
library(spatcovar)
regions <- example_polygons()
sites <- example_points()
routes <- example_lines()
zones <- example_grid()
rst <- example_raster()
# Build several covariates in a pipeline
result <- regions |>
spat_area(unit = "km2") |>
spat_count(sites, name = "n_sites") |>
spat_length(routes, unit = "km") |>
spat_distance(sites, name = "dist_to_sites") |>
spat_overlap(zones, measure = "share") |>
spat_raster(rst, stats = c("mean", "max"), name = "elev")
result
| Function | Description |
|---|---|
spat_area() |
Polygon area with unit conversion |
spat_distance() |
Distance to reference features (minimum, centroid, or point-on-surface) |
spat_count() |
Count of source features intersecting each polygon |
spat_length() |
Total length of line features within each polygon |
spat_overlap() |
Overlap area, target-area share, or intersecting-feature count |
spat_raster() |
Zonal raster statistics (mean, median, min, max, sum, count, stdev) |
spat_diagnostics() |
Retrieve operation diagnostics from a result |
spat_area(), spat_distance(),
spat_overlap()) use geodesic measurement on geographic CRS (via sf/s2).
An optional crs argument is provided when user-selected planar projection
is desired.spat_length()) strictly requires a projected CRS for
planar clipping and measurement (either on the input data or supplied via
the crs argument).spat_count(), spat_raster())
validate coordinate reference systems and align source layers internally.When repair = TRUE (the default), invalid geometries are repaired on
internal copies used for computation. The geometry returned to the user is
always the original target geometry.
spatcovar does not dospatcovar is a focused package for constructing common spatial covariates
from polygon data. It does not provide general GIS manipulation, mapping,
geocoding, boundary harmonization, persistent spatial identifiers, areal
interpolation methodology, raster processing pipelines, or causal inference
tools.
If you use spatcovar in your research, please cite:
Cebeci E (2026). spatcovar: Construct Spatial Covariates from Polygon Data. R package version 0.1.0. doi:10.32614/CRAN.package.spatcovar.
To retrieve the citation for your installed version, run:
citation("spatcovar")
For polygon data observed over time,
spatpersist creates
persistent identifiers and tracks lineages across boundary changes.
spatcovar can then append spatial covariates to those polygon observations.
The packages can also be used independently; neither requires the other.
MIT