Construct Spatial Covariates from Polygon Data
Overview
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.
Initial release of spatcovar, an R package providing a consistent, pipeable
interface for constructing commonly used spatial covariates directly on sf
polygon data frames.
Core Functions
spat_area(): Calculates polygon geometric areas with conversion across metric and customary area units ("m2","km2","ha","mi2"). Uses geodesic measurement on geographic coordinate reference systems (viasf/s2) and planar measurement on projected systems.spat_distance(): Computes shortest geometry-to-geometry ("minimum"), centroid-to-feature ("centroid"), or interior point-on-surface ("point_on_surface") distances from target polygons to reference features. Employs indexed nearest-feature search to avoid computing full pairwise distance matrices. Supports output in"m","km", and"mi".
Show all changes in 0.1.0Hide the rest of the changes in 0.1.0
spat_count(): Counts source points, lines, or polygons intersecting each target polygon using explicit topological intersection semantics (including boundary-touching features). Multi-geometry features count as single source features.spat_length(): Clips line features to polygon boundaries and measures total linework length per polygon. Explicitly handles native linear units of the projected coordinate reference system before converting to the requested unit ("m","km","mi").spat_overlap(): Evaluates spatial overlap between target and source polygon layers, returning total overlap area (measure = "area"), coverage fraction relative to target area (measure = "share"), or intersecting polygon counts (measure = "count"). Issues an informative warning when source polygons have positive-area duplicate coverage among themselves.spat_raster(): Computes coverage-fraction-weighted zonal summary statistics ("mean","median","min","max","sum","count","stdev") from single-layer raster grids using theexactextractrengine. Preserves valid zero values and returnsNAacross all requested statistics when a polygon has zero valid non-NA raster cell support.spat_diagnostics(): Retrieves structured operation metadata attached whendiagnostics = TRUEis passed to any core function.
Synthetic Example Datasets
- Provides five lightweight, self-contained synthetic fixtures in EPSG:32632 for examples, testing, and reproducible workflows without external file dependencies:
example_polygons(),example_points(),example_lines(),example_grid(), andexample_raster().
Design Guarantees & Semantics
- **Row and Geometry Preservation**: Output data frames retain the exact row count, row order, and original geometry of the input target polygons.
- **Safe Geometry Repair**: Invalid geometries are repaired on internal copies used for computation (
repair = TRUEby default); the geometry column returned to the user is never altered. - **Coordinate Reference System Policy**: Enforces strict validation requiring known coordinate reference systems on all vector and raster inputs.
spat_length()strictly requires a projected (planar) CRS. - **Dynamic Output Column Naming**: Derives deterministic, unit-aware column names by default (e.g.
area_km2,dist_m,length_km,overlap_share), with user override via thenameargument. - **Collision Protection**: Prevents accidental overwriting of existing data frame columns unless explicitly allowed with
overwrite = TRUE.
From NEWS.md in the release
Install
Health
- OK13 OKNow
- OK6 OK2026-09-09
Documentation
- Help pages
- 13 (1 internal)includes a package overview page
- Examples that run
- 100%12 run in a plain check
- Exported functions with examples
- 100%
- Documented parameters
- 100%
- Return-value docs
- 100%
- Help pages citing references
- 0%
Downloads
Repository
Stars over time
Commits over time
6 development-tooling and community-health practices detected across 5 families in the upstream repository
Checks run against github.com/emre-cebeci/spatcovar on 2026-10-21.
The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel
Show all practicesHide 1 practice
Dependencies
Code & Tests
People & History
- 0.1.0Latest2026-09-08 · current release
- RR 4.6.0 released · 2026-04-24
Package metadata
- First published
- 2026-09-08
- Total releases
- 1 / 1 yrs
- License
- MIT + file LICENSE OSI
- Download size
- 43 KB
Cite
Cite this package
Run in R for the authors' entry:
citation("spatcovar")The package provides a citation file, so citation() returns the authors' own entry.
The repository also keeps a CITATION.cff.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-23, which the citation names so these numbers can be found later. More on citing and the projects behind them.