首页 > 解决方案 > 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 也会发生这种情况。我怎样才能解决这个问题?

标签: rsf

解决方案


那么它是一个警告而不是一个错误。但一般来说,您应该在投影坐标系上执行 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) 

推荐阅读