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

Marta Rufino m@rt@@m@ru||no @end|ng |rom gm@||@com
Thu Oct 17 12:47:58 CEST 2019


Hi,

I am trying to dissolve the internal borders of larger polygons (sf object)
by a grouping variable or by proximity (adjacent)
and after looking in the web I found several alternatives, but none is
doing what I wanted.

## Reproducible example:
# World map
require(rnaturalearth); require(sf)
world_map <- rnaturalearth::ne_countries(scale = 'small', returnclass =
c("sf"))

# World countries:
world_map
object.size(world_map)

# 1st alternative: in this case we have the groups by continent, but the
country boundaries are still there, although without label:
(kk <- world_map %>%
  dplyr::group_by(continent) %>%
  summarise())
object.size(kk)
kk %>%
  st_transform(crs = 42310) %>%
  ggplot()+
  geom_sf()

# 2nd alternative : apparently different, but very similar...
(kk1 <- world_map %>%
  dplyr::group_by(continent) %>%
  summarise(st_union(.)))
object.size(kk1)
kk1 %>%
  st_transform(crs = 42310) %>%
  ggplot()+
  geom_sf()

# 3rd alternative
(kk2 <- world_map %>%
  dplyr::group_by(continent) %>%
  summarise(geom = st_union(geometry)))
object.size(kk2)
kk2 %>%
  st_transform(crs = 42310) %>%
  ggplot()+
  geom_sf()

# 4th alternative
(kk3 <- world_map %>%
  dplyr::group_by(continent) %>%
  summarise(geom = st_combine(geometry)))
object.size(kk3)
kk3 %>%
  st_transform(crs = 42310) %>%
  ggplot()+
  geom_sf()


# In all cases the objects produced are actually very similar at a first
glance, bur in fact they differ on the properties (as reflected by their
sizes).
object.size(world_map)
object.size(kk1)
object.size(kk2)
object.size(kk3)
object.size(kk4)

# And more importantly, in no case the borders between countries were
actually dissolved, which was my objective.


So, the question is how can I get the continents with the country borders
dissolved?
Further, could I dissolve all contiguous borders (instead of having a
grouping variable)- I saw this in a couple of posts but the answers were
very complex.

Any help will be greatly appreciated,
Best wishes,
M.



-- 
Marta M. Rufino (auxiliary researcher)

*____________________________________________________*MARE - Marine and
Environmental Sciences Centre
Faculty of Sciences, University of Lisbon
Campo Grande, 1749-016 Lisboa,
Portugal
Tel: + 351 21 750 00 00, extension: 22576

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list