This helper function prepares and aggregates an sf object
to produce clean, valid, and unified geometries.
geo_prepare(x, crs = 2154, buffer = 10)An sf object with cleaned, projected, and aggregated geometries as POLYGONs.
An sf object to process.
Integer. Code of the target CRS. Default is 2154.
Numeric. Buffer distance (in map units) used to merge nearby features. Default is 10.
The function performs a complete geometric preparation workflow:
Geometry validation: ensures that all geometries belong to allowed classes (POINT, LINE, or POLYGON).
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.
Coordinate transformation: all geometries are transformed to the specified CRS using sf::st_transform().
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.