First, let's set up the data. Download adjoining Seoul, Incheon, Gyeonggi-do region shapefiles from this website (in Korean). I attach the files, as they are not accessible outside Korea. Then read into R, name, and combine (credit):
library(sf)
#Read, name and combine regions
sca_nsdi <- rbind(cbind(st_read("LARD_ADM_SECT_SGG_11.shp"), Name="Seoul"),
cbind(st_read("LARD_ADM_SECT_SGG_28.shp"), Name="Incheon"),
cbind(st_read("LARD_ADM_SECT_SGG_41.shp"), Name="Gyeonggi-do"))
#Plotting reveals sub-regions (the legend was natively clipped)
plot(sca_nsdi[, "Name"])
I wish to merge the sub-regions of these 3 regions. I have tried applying this solution, but without success:
library(dplyr)
sca_nsdi <- sca_nsdi %>% group_by(Name) %>% summarise(geometry=st_union(geometry)) %>%
ungroup()
plot(sca_nsdi[, "Name"])
The sub-regions are imperfectly merged. (For some reason, the bounding box is also shrunk to the size of Seoul.)
ms_dissolve
from the rmapshaper package with thesnap = TRUE
argument, which corrects these to some degree. (And usefield = "Name"
to get the grouping you require.)snap
appears to be insufficient in this case. Most sub-regions are not dissolved.