Helper function to process and clean up polygons downloaded from OpenStreetMap.

polygons_clean(
  input,
  snap_tolerance = 5,
  min_area = units::set_units(0, "m^2"),
  aggregate_polygons = 15
)

Arguments

input

sf object (with projected coordinate reference system).

snap_tolerance

numeric. Argument for tolerance level passed to sf::st_snap(), used to rectify nearly coincident edges between polygons. Provided either as a units object (see units::set_units()), or a number in the units of the coordinate reference system. After sf::st_snap() is run, a polygon that is covered by another will be removed. Defaults to 5. Set to 0 if you do not wish to rectify minor overlaps.

min_area

numeric. Specify minimum area of each polygon to be retained in the output, passed to argument threshold in smoothr::drop_crumbs(). Provided either as a units object (see units::set_units()), or a number in the units of the coordinate reference system. Defaults to 0 m^2.

aggregate_polygons

numeric. Argument for dist passed to sf::st_buffer(). Buffered polygons that overlap will be aggregated into multipolygons. Set to NULL if you do not wish to aggregate to multipolygons.

Value

The processed polygons (sf object).

Details

Polygons contained in or overlapping others are removed. Polygons vertices are then snapped at a tolerance level based on snap_tolerance (if specified) to rectify nearly coincident edges, and polygons covered by others are subsequently removed. Polygons are then aggregated to multipolygons based on distance set in aggregate_polygons (if specified). All spatial relations (italicised) follow the DE-9IM standard.