Dissolve boundaries only of sf overlapping polygons

I have some sf polygons and would like to dissolve the boundaries of overlapping polygons. In other words I would like to have as a results only two polygons.

I tried with st_union but I didn't find options to achieve my objective.
Any suggestions? Stefano

This S/O post is probably the most direct solution, assuming the boundaries don't need to be preserved or if working with dual sf objects is not an objection.

When dissolving polygons you need a variable to dissolve by; for a more detailed walktru consider this earlier blog post Merging Geometry of {sf} Objects in R · Jindra Lacko

In your case - when one of your desired polygon groups seems to have only a single member - you could go by name of the isolated island polygon. Consider this piece of code built on the well known & much loved nc.shp shapefile:


shape <- st_read(system.file("shape/nc.shp", package="sf")) # included with sf package

merged_shape <- shape %>% 
  mutate(is_cnty_ashe = ifelse(NAME == "Ashe", TRUE, FALSE)) %>% 
  group_by(is_cnty_ashe) %>% 


What it does is that it dissolves 100 NC counties to two groups - one containing County Ashe, and the other for the rest of NC. Then it uses this grouping to dissolve boundaries using dplyr::summarise() call.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.