After dissolving polygons, some of the internal lines remain. It seem to be a problem common also to ther softwares (ArcGis and Qgis at least). The dissolve result is this:

enter image description here

To dissolve using R, I'm following this recommendation.

Replication code:


cities <- read_municipality(code_muni = "all",  year = 2010)
dissolved <- st_make_valid(cities) %>% group_by(code_state) %>% summarize()

How to solve it on R?

  • That happens when vertices are not exactly the same; you may try to buffer by some milimeters, dissolve and then buffer back, clean with rmapshaper (which modifies the total area), or clean with grass gis v.clean (which is the most precise)
    – Elio Diaz
    Aug 31, 2022 at 18:14
  • Can you explain how to buffer? I'm not familiar with it
    – Oalvinegro
    Sep 1, 2022 at 18:33

1 Answer 1


As I commented, your problem might be solved by buffering -which means to extend the polygon homogeneously-, dissolve and then use a negative buffer to approximately restore it to its original size; your polygons had remarkably large gaps of around 100 m, usually 0.1 m works for cleaning these kind of polygons.

At the end, change in total area is 0.0007%, which may be negligible.


cities <- read_municipality(code_muni = "all",  year = 2010)

# first we buffer
dissolved = cities |> 
  st_transform(3857) |> st_buffer(100) 
# then dissolve
dissolved = dissolved |> group_by(code_state) |> summarise() 
# buffer back
dissolved = dissolved |> st_buffer(-100) |>

st_area(dissolved) |> sum()
#8.548294e+12 [m^2]

st_make_valid(cities) |> st_area() |>
#8.548232e+12 [m^2]

dissolved polygons

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.