spatcovar

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.

Installation

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'))

Quick start

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

Core functions

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

CRS handling

Geometry repair

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.

What spatcovar does not do

spatcovar 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.

Citation

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")

Related packages

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.

License

MIT