safe_clip_multipoligon: Safely Clip a Multipolygon Vector Layer

View source: R/sigugr_clip.R

safe_clip_multipoligonR Documentation

Safely Clip a Multipolygon Vector Layer

Description

This function clips a 'MULTIPOLYGON' vector layer using a polygon layer, handling specific issues that might arise with geometries encoded incorrectly or containing unknown WKB types. It serves as a fallback when the 'clip_vector()' function fails due to errors like 'ParseException: Unknown WKB type 12', which is associated with *MULTIPOLYGON* types.

Usage

safe_clip_multipoligon(vector, polygon)

Arguments

vector

A 'sf' multipolygon vector layer to be clipped.

polygon

A 'sf' polygon layer used as the clipping geometry.

Details

The function ensures that the input layer is correctly encoded as 'MULTIPOLYGON' and uses GDAL utilities for re-encoding if necessary. The output is projected to the CRS of the clipping polygon.

This solution is inspired by a discussion on handling WKB type errors in R: <https://gis.stackexchange.com/questions/389814/r-st-centroid-geos-error-unknown-wkb-type-12>.

Value

A 'sf' vector layer with the clipped geometries.

Examples

gpkg_path <- system.file("extdata", "clc.gpkg", package = "clc")

clc <- sf::st_read(gpkg_path, layer = "clc")
lanjaron <- sf::st_read(gpkg_path, layer = "lanjaron")

clc_clipped <- safe_clip_multipoligon(clc, lanjaron)


clc documentation built on April 4, 2025, 5:17 a.m.