r - st_simplify dTolerence 与十进制度
问题描述
我试图sf
通过应用来减小对象的大小st_simplify
。CRS 是 4267 并尝试使用正确的dTolerance
. 我知道单位dTolerance
必须是 CRS 的单位,所以我从 0.1 开始,但我不断收到此错误消息。
test <- st_read("comm_sf.shp") %>%
+ st_simplify(preserveTopology = T,
+ dTolerance = 0.1)
Simple feature collection with 11321 features and 21 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -124.4375 ymin: 24.5441 xmax: -66.94983 ymax: 49.00249
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
Warning message:
In st_simplify.sfc(st_geometry(x), preserveTopology, dTolerance) :
st_simplify does not correctly simplify longitude/latitude data, dTolerance needs to be in decimal degrees
我使用两种设置dTolerance = 1000
(以米为单位)和dTolerance = 0.1
(以长/纬度为单位),但我收到相同的错误消息。CRS = 4267 也会发生这种情况。我怎样才能解决这个问题?
解决方案
那么它是一个警告而不是一个错误。但一般来说,您应该在投影坐标系上执行 Douglas-Peucker - 因为它使用距离作为缓冲区,而经度单位的实际大小随纬度而变化。请注意,st_simplify 容差使用的单位将始终与地图单位相同。
这是一个可重现的示例:
library(sf)
library(maptools)
states = st_as_sf(maps::map("state", plot = FALSE, fill = TRUE))
states_simple = st_simplify(states)
##Warning message:
## In st_simplify.sfc(st_geometry(x), preserveTopology, dTolerance) :
## st_simplify does not correctly simplify longitude/latitude data, dTolerance needs to be in decimal degrees
但如果我们先转换到投影坐标系,则不会出现警告:
states = st_transform(states, 54032) #azimuthal equidistant
states_simple = st_simplify(states)
简化后您始终可以返回 WGS84 lat-long
states = st_transform(states, 4326)
推荐阅读
- javascript - 递归函数对评论进行排序
- javascript - 在 catch 块中测试 console.log
- java - 密码由 ARGON2id 编码时的 JBoss 身份验证
- visual-studio-code - 无法加载 VScode,因为在此系统上禁用了运行脚本
- python - 在 pandas DataFrame 中选择与一列的前两个不同项匹配的行
- c++ - 双重构造是未定义的行为吗?
- node.js - 将大文件上传到 blob 存储而不在本地保存文件意味着堆栈
- powershell - 文件夹中每个文件中的 Powershell 更新字符串的问题
- c++ - GD32V 输入引脚没有被拉低,而是像一个浮动引脚
- javascript - 替换表中值的函数