几何体修正
library(sf)
library(tidyverse)
library(magrittr)
`%nin%` = Negate(`%in%`)
xz <- st_read("D:\\乡镇边界\\乡镇边界.shp") %>%
select(Name) %>%
st_make_valid() %>% #几何体修正几何图形
st_write("D:\\乡镇边界\\乡镇边界.geojson")
xz %>%
st_make_valid()
xz %>%
st_is_valid() %>%
as_tibble() -> tst
xz %>%
filter(na.omit(st_is_valid(xz)) == TRUE) -> xz
#过滤冒犯的几何图形(通过基于结果的空间对象的子集)
# empty geometries, using any(is.na(st_dimension(x)))
# corrupt geometries, using any(is.na(st_is_valid(x)))
# invalid geometries, using any(na.omit(st_is_valid(x)) == FALSE); in case of corrupt and/or invalid geometries,
# in case of invalid geometries, query the reason for invalidity by st_is_valid(x, reason = TRUE)
# you may be succesful in making geometries valid using st_make_valid(x) or, if st_make_valid is not supported by
# st_buffer(x, 0.0) on non-corrupt geometries (but beware of the bowtie example above, where st_buffer removes one half).
# After succesful a st_make_valid, you may want to select a particular type subset using st_is, or cast GEOMETRYCOLLECTIONS to MULTIPOLYGON by
评论
发表评论