st_simplify 十进制的 d 公差

st_simplify dTolerence with decimal degree

我正在尝试通过应用 st_simplify 来减小 sf 对象的大小。 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(以 long/lat 为单位),但我收到相同的错误消息。 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)