Removes polygon holes from an sf, sfc, or sfg object. With a positive max_area, only holes smaller than the threshold are removed.

remove_geom_holes(x, max_area = 0)

Arguments

x

An sf, sfc, or sfg object of type POLYGON or MULTIPOLYGON.

max_area

Maximum area of holes to remove, in the units of x (or square metres for geographic coordinates). Default 0 removes all holes.

Value

An object of the same class as x, with selected holes removed.

Note

For a faster alternative when max_area is unnecessary, see sfheaders::sf_remove_holes(): https://github.com/dcooley/sfheaders.

Acknowledgment

This implementation is adapted from nngeo::st_remove_holes(), written by Michael Dorman and distributed under the MIT License.

References

Adapted from the StackOverflow answer by user lbusett: https://stackoverflow.com/questions/52654701/removing-holes-from-polygons-in-r-sf.