Skip to content

Commit 70e33c4

Browse files
committed
allow max_cells and min_level to be set by feature
addresses r-spatial/sf#2488
1 parent b495b0d commit 70e33c4

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

R/s2-transformers.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ s2_rebuild <- function(x, options = s2_options()) {
207207
#' @export
208208
s2_buffer_cells <- function(x, distance, max_cells = 1000, min_level = -1,
209209
radius = s2_earth_radius_meters()) {
210-
recycled <- recycle_common(as_s2_geography(x), distance / radius)
211-
new_s2_geography(cpp_s2_buffer_cells(recycled[[1]], recycled[[2]], max_cells, min_level))
210+
recycled <- recycle_common(as_s2_geography(x), distance / radius, max_cells, min_level)
211+
new_s2_geography(cpp_s2_buffer_cells(recycled[[1]], recycled[[2]], recycled[[3]], recycled[[4]]))
212212
}
213213

214214
#' @rdname s2_boundary

README.Rmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ nc_s2 %>%
113113

114114
## Acknowledgment
115115

116-
This project gratefully acknowledges financial [support](https://www.r-consortium.org/) from the
116+
This project gratefully acknowledges financial [support](https://r-consortium.org/) from the
117117

118-
<a href="https://www.r-consortium.org/">
118+
<a href="https://r-consortium.org/">
119119
<img src="man/figures/rc300.png" width="300" />
120120
</a>

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ nc_s2 %>%
187187
## Acknowledgment
188188

189189
This project gratefully acknowledges financial
190-
[support](https://www.r-consortium.org/) from the
190+
[support](https://r-consortium.org/) from the
191191

192-
<a href="https://www.r-consortium.org/">
192+
<a href="https://r-consortium.org/">
193193
<img src="man/figures/rc300.png" width="300" /> </a>

src/RcppExports.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1307,15 +1307,15 @@ BEGIN_RCPP
13071307
END_RCPP
13081308
}
13091309
// cpp_s2_buffer_cells
1310-
List cpp_s2_buffer_cells(List geog, NumericVector distance, int maxCells, int minLevel);
1310+
List cpp_s2_buffer_cells(List geog, NumericVector distance, IntegerVector maxCells, IntegerVector minLevel);
13111311
RcppExport SEXP _s2_cpp_s2_buffer_cells(SEXP geogSEXP, SEXP distanceSEXP, SEXP maxCellsSEXP, SEXP minLevelSEXP) {
13121312
BEGIN_RCPP
13131313
Rcpp::RObject rcpp_result_gen;
13141314
Rcpp::RNGScope rcpp_rngScope_gen;
13151315
Rcpp::traits::input_parameter< List >::type geog(geogSEXP);
13161316
Rcpp::traits::input_parameter< NumericVector >::type distance(distanceSEXP);
1317-
Rcpp::traits::input_parameter< int >::type maxCells(maxCellsSEXP);
1318-
Rcpp::traits::input_parameter< int >::type minLevel(minLevelSEXP);
1317+
Rcpp::traits::input_parameter< IntegerVector >::type maxCells(maxCellsSEXP);
1318+
Rcpp::traits::input_parameter< IntegerVector >::type minLevel(minLevelSEXP);
13191319
rcpp_result_gen = Rcpp::wrap(cpp_s2_buffer_cells(geog, distance, maxCells, minLevel));
13201320
return rcpp_result_gen;
13211321
END_RCPP

src/s2-transformers.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,23 @@ List cpp_s2_interpolate_normalized(List geog, NumericVector distanceNormalized)
342342
}
343343

344344
// [[Rcpp::export]]
345-
List cpp_s2_buffer_cells(List geog, NumericVector distance, int maxCells, int minLevel) {
345+
List cpp_s2_buffer_cells(List geog, NumericVector distance, IntegerVector maxCells, IntegerVector minLevel) {
346346
class Op: public UnaryGeographyOperator<List, SEXP> {
347347
public:
348348
NumericVector distance;
349+
IntegerVector maxCells, minLevel;
349350
S2RegionCoverer coverer;
350351

351-
Op(NumericVector distance, int maxCells, int minLevel): distance(distance) {
352-
this->coverer.mutable_options()->set_max_cells(maxCells);
353-
if (minLevel > 0) {
354-
this->coverer.mutable_options()->set_min_level(minLevel);
355-
}
352+
Op(NumericVector distance, IntegerVector maxC, IntegerVector minL): distance(distance) {
353+
maxCells = maxC;
354+
minLevel = minL;
356355
}
357356

358357
SEXP processFeature(XPtr<RGeography> feature, R_xlen_t i) {
358+
this->coverer.mutable_options()->set_max_cells(this->maxCells[i]);
359+
if (this->minLevel[i] > 0) {
360+
this->coverer.mutable_options()->set_min_level(this->minLevel[i]);
361+
}
359362
S2ShapeIndexBufferedRegion region;
360363
region.Init(&feature->Index().ShapeIndex(), S1ChordAngle::Radians(this->distance[i]));
361364

0 commit comments

Comments
 (0)