用R消除多边形之间的条缝


10

有没有一种方法可以消除使用多边形之间的小“条” R?理想的解决方案将创建一个新SpatialPolygonsDataFrame的多边形之间共享边界重合的地方。我对使用R而不是ArcMap或QGIS 的解决方案特别感兴趣。

我也想听听有关为什么首先存在这些差距的解释。

这是我正在处理的空间数据的可重现示例:

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)

多边形之间的恼人条子

如您在上面的屏幕截图中所见,人口普查区块组多边形之间存在很小的间隙。这些间隙的这些位置根据缩放级别而有所不同,但是始终有一些间隙可见。

谁能推荐一个R功能(或多个功能的组合)来以编程方式调整多边形以消除这些间隙?

Answers:


5

看来,解决办法在于设置smoothFactor论点AddPolygons0,在这相关的职位建议:单张GeoJSON的多边形造型之间的差距叶子

我还发现有必要在多边形上添加一个小笔画,以完全消除示例图中的条子间隙。

leaflet() %>% 
    addProviderTiles("CartoDB.Positron") %>% 
    addPolygons(data = polygons, smoothFactor = 0,
                weight = .75, color = col2hex("red"), opacity = 1,
                fillColor = col2hex("red"), fillOpacity = 1)

在此处输入图片说明

有趣的是,当我降低多边形的不透明度时,我发现不再需要添加笔触。

leaflet() %>% 
        addProviderTiles("CartoDB.Positron") %>% 
        addPolygons(data = polygons, smoothFactor = 0,
                    stroke = FALSE,
                    fillColor = col2hex("red"), fillOpacity = .5)

50%不透明度

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.