Is there a way to eliminate the small "slivers" between polygons using R
? The desired solution would create a new SpatialPolygonsDataFrame
where the shared boundaries between polygons are coincident. I'm specifically interested in a solution that uses R
, rather than ArcMap or QGIS.
I would also be interested to hear an explanation as to why these gaps exist in the first place.
Here's a reproducible example of the spatial data I'm working with:
library(rgdal)
library(sp)
library(tigris)
library(magrittr)
library(leaflet)
library(gplots)
# This project will use WGS 84 projected coordinate system
crs_proj <- CRS("+init=epsg:4326")
# These are the FIPS codes of the specific block groups in my study area
sel <- c("530330079005", "530330079001", "530330079004",
"530330085002", "530330085003", "530330086003",
"530330087003", "530330085001", "530330090001",
"530330091001", "530330091002", "530330092001",
"530330092002", "530330086001", "530330090002",
"530330086002", "530330079003", "530330079002",
"530330087002", "530330087001")
# Create polygons
polygons <- tigris::block_groups(state = "WA",county = "King") %>%
.[.@data$GEOID %in% sel,] %>%
spTransform(CRSobj = crs_proj)
# Map the result
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = polygons,
stroke = F,
fillColor = col2hex("red"), fillOpacity = 1)
As you can see in the above screenshot, there are small gaps between the census block group polygons. These location of these gaps is rendered differently depending on the zoom level, but there are always some gaps visible.
Can anyone recommend an R
function (or a combination of functions) to programmatically adjust the polygons to eliminate these gaps?