Skip to content

Commit 49b5fbd

Browse files
committed
address #2442
1 parent 35f5f8b commit 49b5fbd

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* fix build failure with GDAL < 3.4.0 #2436
44

5+
* `st_simplify()` now accepts feature-wise tolerance values when `s2` is switched on #2442
6+
57
# version 1.0-17
68

79
* add `st_transform()` method for `bbox` objects; this uses OGRCoordinateTransformation::TransformBounds(), densifying first and antemeridian proof; #2415

R/geom-transformers.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,12 @@ st_simplify.sfc = function(x, preserveTopology, dTolerance = 0.0) {
286286
if (ll && sf_use_s2()) {
287287
if (!missing(preserveTopology) && isFALSE(preserveTopology))
288288
warning("argument preserveTopology cannot be set to FALSE when working with ellipsoidal coordinates since the algorithm behind st_simplify always preserves topological relationships")
289-
st_as_sfc(s2::s2_simplify(x, dTolerance), crs = st_crs(x))
289+
if (length(dTolerance) == 1) {
290+
st_as_sfc(s2::s2_simplify(x, dTolerance), crs = st_crs(x))
291+
} else {
292+
simplify <- function(x, dTolerance) st_as_sfc(s2::s2_simplify(x, dTolerance))
293+
st_as_sfc(mapply(simplify, x, dTolerance), crs = st_crs(x))
294+
}
290295
} else {
291296
if (missing(preserveTopology)) {
292297
preserveTopology = FALSE

tests/gdal_geom.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ x = st_convex_hull(nc)
2020

2121
x = st_simplify(nc_tr, dTolerance = 1e4)
2222

23+
x = st_simplify(nc_tr, dTolerance = rep(1e4, nrow(nc_tr)))
24+
2325
x = st_simplify(nc_tr, preserveTopology = TRUE)
2426

2527
if (sf:::CPL_geos_version() >= "3.4.0")

0 commit comments

Comments
 (0)