From 70e33c4facc9511d5c479e737dd93010a2325a3d Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 7 Jan 2025 15:52:11 +0100 Subject: [PATCH 1/2] allow max_cells and min_level to be set by feature addresses https://github.com/r-spatial/sf/issues/2488 --- R/s2-transformers.R | 4 ++-- README.Rmd | 4 ++-- README.md | 4 ++-- src/RcppExports.cpp | 6 +++--- src/s2-transformers.cpp | 15 +++++++++------ 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/R/s2-transformers.R b/R/s2-transformers.R index d5f64e54..ae075330 100644 --- a/R/s2-transformers.R +++ b/R/s2-transformers.R @@ -207,8 +207,8 @@ s2_rebuild <- function(x, options = s2_options()) { #' @export s2_buffer_cells <- function(x, distance, max_cells = 1000, min_level = -1, radius = s2_earth_radius_meters()) { - recycled <- recycle_common(as_s2_geography(x), distance / radius) - new_s2_geography(cpp_s2_buffer_cells(recycled[[1]], recycled[[2]], max_cells, min_level)) + recycled <- recycle_common(as_s2_geography(x), distance / radius, max_cells, min_level) + new_s2_geography(cpp_s2_buffer_cells(recycled[[1]], recycled[[2]], recycled[[3]], recycled[[4]])) } #' @rdname s2_boundary diff --git a/README.Rmd b/README.Rmd index f2464791..8cd80bc5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -113,8 +113,8 @@ nc_s2 %>% ## Acknowledgment -This project gratefully acknowledges financial [support](https://www.r-consortium.org/) from the +This project gratefully acknowledges financial [support](https://r-consortium.org/) from the - + diff --git a/README.md b/README.md index 52d7e2b1..1d7ffc00 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ nc_s2 %>% ## Acknowledgment This project gratefully acknowledges financial -[support](https://www.r-consortium.org/) from the +[support](https://r-consortium.org/) from the - + diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 24a5ac1b..5c33e1be 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -1307,15 +1307,15 @@ BEGIN_RCPP END_RCPP } // cpp_s2_buffer_cells -List cpp_s2_buffer_cells(List geog, NumericVector distance, int maxCells, int minLevel); +List cpp_s2_buffer_cells(List geog, NumericVector distance, IntegerVector maxCells, IntegerVector minLevel); RcppExport SEXP _s2_cpp_s2_buffer_cells(SEXP geogSEXP, SEXP distanceSEXP, SEXP maxCellsSEXP, SEXP minLevelSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< List >::type geog(geogSEXP); Rcpp::traits::input_parameter< NumericVector >::type distance(distanceSEXP); - Rcpp::traits::input_parameter< int >::type maxCells(maxCellsSEXP); - Rcpp::traits::input_parameter< int >::type minLevel(minLevelSEXP); + Rcpp::traits::input_parameter< IntegerVector >::type maxCells(maxCellsSEXP); + Rcpp::traits::input_parameter< IntegerVector >::type minLevel(minLevelSEXP); rcpp_result_gen = Rcpp::wrap(cpp_s2_buffer_cells(geog, distance, maxCells, minLevel)); return rcpp_result_gen; END_RCPP diff --git a/src/s2-transformers.cpp b/src/s2-transformers.cpp index 5601494f..7437d392 100644 --- a/src/s2-transformers.cpp +++ b/src/s2-transformers.cpp @@ -342,20 +342,23 @@ List cpp_s2_interpolate_normalized(List geog, NumericVector distanceNormalized) } // [[Rcpp::export]] -List cpp_s2_buffer_cells(List geog, NumericVector distance, int maxCells, int minLevel) { +List cpp_s2_buffer_cells(List geog, NumericVector distance, IntegerVector maxCells, IntegerVector minLevel) { class Op: public UnaryGeographyOperator { public: NumericVector distance; + IntegerVector maxCells, minLevel; S2RegionCoverer coverer; - Op(NumericVector distance, int maxCells, int minLevel): distance(distance) { - this->coverer.mutable_options()->set_max_cells(maxCells); - if (minLevel > 0) { - this->coverer.mutable_options()->set_min_level(minLevel); - } + Op(NumericVector distance, IntegerVector maxC, IntegerVector minL): distance(distance) { + maxCells = maxC; + minLevel = minL; } SEXP processFeature(XPtr feature, R_xlen_t i) { + this->coverer.mutable_options()->set_max_cells(this->maxCells[i]); + if (this->minLevel[i] > 0) { + this->coverer.mutable_options()->set_min_level(this->minLevel[i]); + } S2ShapeIndexBufferedRegion region; region.Init(&feature->Index().ShapeIndex(), S1ChordAngle::Radians(this->distance[i])); From e995c1c26b676068ccf79b6e91c7c142e0b72d94 Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 7 Jan 2025 16:26:20 +0100 Subject: [PATCH 2/2] add NEWS --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index b87194d8..19157419 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,14 @@ # s2 (development version) +* `s2_buffer_cells()` recycles `max_dist` and `min_level` arguments, allowing + to specify these by feature; #264 and https://github.com/r-spatial/sf/issues/2488 + * The Abseil dependency is resolved using pkg-config where possible. Where this is not possible, a vendored version of Abseil will be built using CMake (#258). +# s2 1.1.7 + # s2 1.1.6 * Fix CRAN warning (#254).