From 49b5fbd18f23d3045278b385879c420ab56bb4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darius=20A=2E=20G=C3=B6rgen?= Date: Tue, 24 Sep 2024 04:42:30 +0000 Subject: [PATCH] address #2442 --- NEWS.md | 2 ++ R/geom-transformers.R | 7 ++++++- tests/gdal_geom.R | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 12add0430..610ad4491 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ * fix build failure with GDAL < 3.4.0 #2436 +* `st_simplify()` now accepts feature-wise tolerance values when `s2` is switched on #2442 + # version 1.0-17 * add `st_transform()` method for `bbox` objects; this uses OGRCoordinateTransformation::TransformBounds(), densifying first and antemeridian proof; #2415 diff --git a/R/geom-transformers.R b/R/geom-transformers.R index af13a68e3..1998997ed 100644 --- a/R/geom-transformers.R +++ b/R/geom-transformers.R @@ -286,7 +286,12 @@ st_simplify.sfc = function(x, preserveTopology, dTolerance = 0.0) { if (ll && sf_use_s2()) { if (!missing(preserveTopology) && isFALSE(preserveTopology)) warning("argument preserveTopology cannot be set to FALSE when working with ellipsoidal coordinates since the algorithm behind st_simplify always preserves topological relationships") - st_as_sfc(s2::s2_simplify(x, dTolerance), crs = st_crs(x)) + if (length(dTolerance) == 1) { + st_as_sfc(s2::s2_simplify(x, dTolerance), crs = st_crs(x)) + } else { + simplify <- function(x, dTolerance) st_as_sfc(s2::s2_simplify(x, dTolerance)) + st_as_sfc(mapply(simplify, x, dTolerance), crs = st_crs(x)) + } } else { if (missing(preserveTopology)) { preserveTopology = FALSE diff --git a/tests/gdal_geom.R b/tests/gdal_geom.R index 7785de0be..b18de15ef 100644 --- a/tests/gdal_geom.R +++ b/tests/gdal_geom.R @@ -20,6 +20,8 @@ x = st_convex_hull(nc) x = st_simplify(nc_tr, dTolerance = 1e4) +x = st_simplify(nc_tr, dTolerance = rep(1e4, nrow(nc_tr))) + x = st_simplify(nc_tr, preserveTopology = TRUE) if (sf:::CPL_geos_version() >= "3.4.0")