safe_clip_multipoligon | R Documentation |
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.
safe_clip_multipoligon(vector, polygon)
vector |
A 'sf' multipolygon vector layer to be clipped. |
polygon |
A 'sf' polygon layer used as the clipping geometry. |
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>.
A 'sf' vector layer with the clipped geometries.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.