Construct Spatial Covariates from Polygon Data

Provides a consistent interface for constructing commonly used spatial covariates from polygon data. Computes polygon areas, distances to reference features, point and line intersection counts, line lengths within polygons, polygon overlap areas and shares, and raster zonal summaries. Handles coordinate reference system validation, geometry repair, unit conversion, row preservation, and standardised missing value semantics while relying on established spatial libraries for the underlying geometry operations.


spatcovar

R-CMD-check

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 development version from GitHub:

# install.packages("pak")
pak::pak("emre-cebeci/spatcovar")

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

  • Area, distance, and overlap (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.
  • Line length (spat_length()) strictly requires a projected CRS for planar clipping and measurement (either on the input data or supplied via the crs argument).
  • Feature counting and raster extraction (spat_count(), spat_raster()) validate coordinate reference systems and align source layers internally.

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.

License

MIT

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("spatcovar")

0.1.0 by Emre Cebeci, a month ago


https://github.com/emre-cebeci/spatcovar


Report a bug at https://github.com/emre-cebeci/spatcovar/issues


Browse source code at https://github.com/cran/spatcovar


Authors: Emre Cebeci [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports exactextractr, sf, terra, units

Suggests covr, knitr, rmarkdown, testthat


See at CRAN