[R-sig-Geo] dissolve internal borders of polygons using st_union and group_by

Andy Teucher @ndy@teucher @end|ng |rom gm@||@com
Thu Oct 17 21:25:45 CEST 2019


Another option you have available is ‘ms_dissolve()’ in the ‘rmapshaper' package (full disclosure - I am the author). The javascript library that powers it (maphsaper[1]) builds topology with a small tolerance to repair slivers and gaps, and thus can often fix issues like this:

require(rnaturalearth)
require(sf)
library(rmapshaper)
world_map <- ne_countries(scale = 'small', returnclass = "sf")

# World countries:
world_map
object.size(world_map)

# Dissolve borders within continents with ms_dissolve()
world_dissolved <- ms_dissolve(world_map, field = "continent”)
plot(world_dissolved)

Cheers,
Andy Teucher

[1] mapshaper: https://github.com/mbloch/mapshaper

> On Oct 17, 2019, at 8:47 AM, Marta Rufino <marta.m.rufino using gmail.com> wrote:
> 
> Thank you very much to all :)
> 
> Barry+Roger contributions sorted the problem for the moment, although in my
> mind there are still things to be understood.
> Mike, yep, thank you for alerting me of rnaturalearth issues- I was not
> aware of it. In this case, I am really interested in the process to
> apply in other polygons, not in the data *per se*, but will take this into
> account in the future.
> 
> Once I have the doc produced (distribution of world
> estuaries/bays/transition waters), I will post on the list :)
> 
> Best wishes,
> M.
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list