R/intersect_clean.R
intersect_clean.RdUseful where two sets of polygons do not align perfectly: intersecting them leaves slivers along every mismatched boundary (https://github.com/r-spatial/sf/issues/547), carrying attribute combinations that are artefacts of the misalignment rather than real.
intersect_clean(x, y, xcol, areaThresh = 0.05)sf polygons object covering the same area as st_intersection(x, y)
Each sliver is merged into the neighbouring polygon it shares the longest
border with (see eliminate_slivers()), so no area is lost and the sliver
takes the attributes of a real neighbour.
Slivers are judged, and absorbed, within each feature set separately:
identify the feature sets in x from the unique values of x[[xcol]];
for each set, take the area of its smallest feature in x;
intersect with y and repair the result;
within each set, treat any fragment smaller than
areaThresh * min(area) as a sliver and merge it into its
longest-shared-border neighbour in that same set.
Keeping the merge within a set is what repairs the misalignment: a sliver of
set A carrying the wrong y attributes is absorbed by the main body of
A, which carries the right ones.
This previously discarded slivers via smoothr::drop_crumbs(), so the
result no longer covered the same footprint as the intersection and the area
in the dropped fragments simply vanished. Merging is the geometrically
sensible treatment and is what the ArcGIS Eliminate tool does.