【问题标题】:Removing the outlines of polygon islands within holes when using smoothr's fill_holes使用smoothr\'s fill_holes时去除孔内多边形岛的轮廓
【发布时间】:2022-11-04 16:15:18
【问题描述】:

我正在将多个相邻的多边形连接在一起,并使用smoothr 中的fill_holes 从现在的单个多边形中移除任何孔洞。但是,如果孔内有另一个多边形(或岛),则该多边形的轮廓仍然存在。有没有办法可以删除/溶解这些轮廓?

library(sf)
library(smoothr)

download.file("https://drive.google.com/uc?export=download&id=1-KcZce0jgIV0fwG797mq7FB5WjxwtKqX" , destfile="Zones.zip")
unzip("Zones.zip")

Zones <- st_read("Zones.gpkg")

Threshold <- units::set_units(1000, km^2)

Zones_No_Holes <- fill_holes(Zones %>% st_union, threshold = Threshold)

plot(Zones_No_Holes, col="aliceblue")

【问题讨论】:

  • 也许sf::st_union?哦,我看到你有它......嗯。

标签: r polygon sf


【解决方案1】:

zones_no_holes 转换为 'POLYGON' 然后st_union 结果应该会让你到达那里。

zones_no_holes <- fill_holes(Zones %>% st_union, threshold = threshold) %>%
  st_cast('POLYGON') %>%
  st_union()

plot(zones_no_holes, col = 'aliceblue')

【讨论】:

    【解决方案2】:

    如果有人需要使用混合了多边形和多部分多边形的多个特征来执行此操作。然后修改@mrhellmann 的方法就可以了:

    zones_no_holes <- fill_holes(Zones %>% st_union, threshold = threshold) %>%
      st_cast('MULTIPOLYGON') %>%
      st_cast('POLYGON') %>%
      st_cast('MULTIPOLYGON') %>%
      group_by(objectid) %>%
      summarize(geom = st_union(geom))
    

    (如果你有任何唯一的组替换 objectid)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多