【发布时间】:2021-10-06 12:47:50
【问题描述】:
我正在尝试使用 ngeo 包中的 st_remove_holes 函数从 shapefile 中删除孔,但即使在运行之后,仍然存在一些孔。
library(dplyr)
library(sf)
library(nngeo)
library(geobr)
sf_use_s2(FALSE)
shape.muni <- read_census_tract(year = 2010, code_tract = 3304557) # download the shapefile
shape.muni <- shape.muni %>%
group_by(code_neighborhood, name_neighborhood) %>%
summarise(geometry = st_union(geom)) %>%
st_remove_holes()
结果是: enter image description here
但它应该是: enter image description here
【问题讨论】:
-
这可能对你有用github.com/r-spatial/sf/issues/609#issuecomment-357426716。评论建议循环遍历每个
MULTIPOLYGON并每次使用st_multipolygon(lapply(my_polys, function(x) x[1]))拉出第一个POLYGON。 -
试试
sfheaders::sf_remove_holes()
标签: r dplyr geospatial sf