我正在尝试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
Run Code Online (Sandbox Code Playgroud)
我使用了两种设置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
Run Code Online (Sandbox Code Playgroud)
但如果我们先转换到投影坐标系,则不会出现警告:
states = st_transform(states, 54032) #azimuthal equidistant
states_simple = st_simplify(states)
Run Code Online (Sandbox Code Playgroud)
简化后您可以随时返回 WGS84 lat-long
states = st_transform(states, 4326)
Run Code Online (Sandbox Code Playgroud)