Skip to content

Instantly share code, notes, and snippets.

@mhweber
Last active December 12, 2024 23:31
Show Gist options
  • Save mhweber/21b44773b3b44b61145a7ddc1ccf0ca2 to your computer and use it in GitHub Desktop.
Save mhweber/21b44773b3b44b61145a7ddc1ccf0ca2 to your computer and use it in GitHub Desktop.
Fill holes inside polygons
basins <- read_sf('mybasins.shp')
library(smoothr)
mapview(basins[basins$SITE_ID =='ID',])
area_thresh <- units::set_units(100, km^2)
unique(st_geometry_type(basins$Shape))
oddballs <- basins |>
dplyr::filter(!grepl("POLYGON", st_geometry_type(Shape)) | !grepl("MULTIPOLYGON", st_geometry_type(Shape)))
basins <- smoothr::fill_holes(basins, threshold = area_thresh)
mapview(basins[basins$SITE_ID =='ID',])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment