1

I am joining multiple adjoining polygons together and removing any holes from the now single polygon using fill_holes in smoothr. However, if a hole has another polygon (or island) within it, the outline of that polygon remains. Is there a way these outlines can be removed/dissolved?

library(sf)
library(smoothr)

download.file("https://drive.google.com/uc?export=download&id=1-KcZce0jgIV0fwG797mq7FB5WjxwtKqX" , destfile="Zones.zip")
unzip("Zones.zip")

Zones <- st_read("Zones.gpkg")

Threshold <- units::set_units(1000, km^2)

Zones_No_Holes <- fill_holes(Zones %>% st_union, threshold = Threshold)

plot(Zones_No_Holes, col="aliceblue")

current output

Chris
  • 1,197
  • 9
  • 28

2 Answers2

2

Casting zones_no_holes to 'POLYGON' and then st_union the result should get you there.

zones_no_holes <- fill_holes(Zones %>% st_union, threshold = threshold) %>%
  st_cast('POLYGON') %>%
  st_union()

plot(zones_no_holes, col = 'aliceblue')

enter image description here

mrhellmann
  • 5,069
  • 11
  • 38
0

In case anyone needs to do this with multiple features that are a mixture of polygons and multipart polygons. Then a modification of @mrhellmann's method does the job:

zones_no_holes <- fill_holes(Zones %>% st_union, threshold = threshold) %>%
  st_cast('MULTIPOLYGON') %>%
  st_cast('POLYGON') %>%
  st_cast('MULTIPOLYGON') %>%
  group_by(objectid) %>%
  summarize(geom = st_union(geom))

(replace objectid with whatever unqiue group ID you have)

Chris
  • 1,197
  • 9
  • 28