Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

st_simplify dTolerence with decimal degree

Tags:

r

sf

I'm trying to reduce the size of sf object by applying st_simplify. CRS is 4267 and try to play around with the right level of dTolerance. I understand that the unit of dTolerance has to be that of the CRS, so I started with 0.1, but I constantly getting this error message.

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

I play around with both setting dTolerance = 1000 (in case it's in meters) and dTolerance = 0.1 (in case it's in long/lat), but I get the same error message. This happens with CRS = 4267 as well. How can I fix this?

like image 390
qnp1521 Avatar asked Jan 31 '20 16:01

qnp1521


1 Answers

Well its a warning rather than an error. But in general you should do Douglas-Peucker on a projected coordinate system - because it uses a distance as a buffer, whereas the actual size of a unit of longitude varies with latitude. Note that the unit used by st_simplify tolerance will always be in the same as the map units.

Here's a reproducible example:

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

But if we transform to a projected coordinate system first, then no warning:

states = st_transform(states, 54032) #azimuthal equidistant
states_simple = st_simplify(states)

You can always go back to WGS84 lat-long after the simplification

 states = st_transform(states, 4326) 
like image 66
dww Avatar answered Nov 16 '22 01:11

dww