Learn R Programming

frheritage (version 0.1.0)

geo_prepare: Prepare and aggregate an sf object

Description

This helper function prepares and aggregates an sf object to produce clean, valid, and unified geometries.

Usage

geo_prepare(x, crs = 2154, buffer = 10)

Value

An sf object with cleaned, projected, and aggregated geometries as POLYGONs.

Arguments

x

An sf object to process.

crs

Integer. Code of the target CRS. Default is 2154.

buffer

Numeric. Buffer distance (in map units) used to merge nearby features. Default is 10.

Details

The function performs a complete geometric preparation workflow:

  1. Geometry validation: ensures that all geometries belong to allowed classes (POINT, LINE, or POLYGON).

  2. Geometry cleaning: invalid features are fixed with sf::st_make_valid(), Z/M dimensions are dropped via sf::st_zm(), and multipart geometries are cast to simple forms.

  3. Coordinate transformation: all geometries are transformed to the specified CRS using sf::st_transform().

  4. Aggregation: small buffer zones (controlled by buffer) are applied to merge adjacent or overlapping features. The buffered geometries are then dissolved with sf::st_union() and cast to POLYGON type.

This process is useful for simplifying feature sets into larger contiguous study zones or analysis areas.