Useful 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)

Arguments

x, y

sf polygons object

xcol

character, name of the attribute column in x to use to identify features

areaThresh

numeric, proportion of minimum polygon area to use as threshold sliver size.

Value

sf polygons object covering the same area as st_intersection(x, y)

Details

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:

  1. identify the feature sets in x from the unique values of x[[xcol]];

  2. for each set, take the area of its smallest feature in x;

  3. intersect with y and repair the result;

  4. 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.

Changed behaviour

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.