Port of the per-FMA "active/passive" (a.k.a. contributing/non-contributing) landbase-status processing formerly repeated across the LandWeb_preamble study-area helpers. Reads a landbase coverage, keeps only the polygons within aoi and only the status column, repairs and dissolves them by status, and clips the result to aoi.

prep_landbase(
  src,
  aoi,
  status_col,
  layer = NULL,
  crs = NULL,
  status_out = "lbstatus",
  dissolve = c("raster", "vector", "none"),
  dissolve_res = 30,
  mask = TRUE
)

Arguments

src

A SpatVector, or a file path / data source readable by terra::vect() (e.g. a shapefile, GeoPackage, or File Geodatabase).

aoi

A SpatVector (or a source readable by terra::vect()) defining the area of interest. May be in any CRS.

status_col

Character. Name of the source attribute holding the landbase status (e.g. "f_active", "LBC_LBStatus", "F_CONDITIO", "LBC_Landbase").

layer

Optional layer name, for sources (e.g. a File Geodatabase) with more than one layer.

crs

Target coordinate reference system, in any form accepted by terra::project(). Defaults to the CRS of aoi.

status_out

Character. Name to give the standardised status column in the output (default "lbstatus").

dissolve

How to dissolve features by status: "raster" (the default, fast, grid-snapped), "vector" (exact but slow), or "none" (keep individual features).

dissolve_res

Numeric. Grid resolution (in the units of the source CRS) for dissolve = "raster" (default 30).

mask

Logical. If TRUE (the default), clip the result precisely to the aoi polygon; if FALSE, keep whole (intersecting) features.

Value

A SpatVector in crs, with a single status_out column, dissolved by status (unless dissolve = "none") and clipped to aoi (when mask = TRUE). Empty (nrow == 0) when no landbase features fall in aoi.

Details

The read is spatially and column-filtered up front (see read_vector_aoi()), so an enormous source coverage is reduced to the AOI before any geometry repair or dissolve, and only the handful of dissolved polygons are reprojected and clipped.

Two dissolve methods are offered because an exact vector union of a large landbase (hundreds of thousands of overlay polygons) is very slow – minutes to hours for the whole thing:

  • "raster" (the default) rasterises the features by status at dissolve_res and polygonises the result – orders of magnitude faster, with boundaries snapped to the dissolve_res grid. For reporting polygons (which are rasterised to the simulation grid downstream anyway) this is immaterial as long as dissolve_res is finer than the analysis grid.

  • "vector" uses an exact terra::aggregate() union (v2-equivalent boundaries), at a large time cost.

Examples

aoi <- terra::vect("POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))")
terra::crs(aoi) <- "EPSG:3857"
a1 <- terra::vect("POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))")
a2 <- terra::vect("POLYGON ((2 0, 4 0, 4 2, 2 2, 2 0))")
p1 <- terra::vect("POLYGON ((0 2, 4 2, 4 4, 0 4, 0 2))")
src <- rbind(a1, a2, p1)
src$f_active <- c("Active", "Active", "Passive")
terra::crs(src) <- "EPSG:3857"
prep_landbase(src, aoi, status_col = "f_active")
#> Warning: [] empty SpatVector
#> Warning: [] empty SpatVector
#> class       : SpatVector
#> geometry    : none
#> dimensions  : 0, 0  (geometries, attributes)
#> extent      : nan, nan, nan, nan  (xmin, xmax, ymin, ymax)
#> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857)