Skip to content

Commit b202bd8

Browse files
committed
Add 'h3_get_base_cell'
1 parent 4c6a992 commit b202bd8

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export(geo_boundary_to_sf)
1212
export(geo_to_h3)
1313
export(geo_to_sf)
1414
export(h3_distance)
15+
export(h3_get_base_cell)
1516
export(h3_get_resolution)
1617
export(h3_is_valid)
1718
export(h3_set_to_multi_polygon)

R/RcppExports.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ h3_is_valid <- function(h3Str) {
3737
.Call(`_h3_h3_is_valid`, h3Str)
3838
}
3939

40+
#' Get the base cells of the given H3 indexes.
41+
#' @param h3Str character vector of H3 indexes
42+
#' @return numeric vector; base cell numbers between 0 and 121
43+
#' @export
44+
h3_get_base_cell <- function(h3Str) {
45+
.Call(`_h3_h3_get_base_cell`, h3Str)
46+
}
47+
4048
#' Number of unique H3 indexes at the given resolution.
4149
#' @param res numeric vector; resolution between 0 and 15
4250
#' @return numeric vector

man/h3_get_base_cell.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RcppExports.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ BEGIN_RCPP
8585
return rcpp_result_gen;
8686
END_RCPP
8787
}
88+
// h3_get_base_cell
89+
NumericVector h3_get_base_cell(CharacterVector h3Str);
90+
RcppExport SEXP _h3_h3_get_base_cell(SEXP h3StrSEXP) {
91+
BEGIN_RCPP
92+
Rcpp::RObject rcpp_result_gen;
93+
Rcpp::RNGScope rcpp_rngScope_gen;
94+
Rcpp::traits::input_parameter< CharacterVector >::type h3Str(h3StrSEXP);
95+
rcpp_result_gen = Rcpp::wrap(h3_get_base_cell(h3Str));
96+
return rcpp_result_gen;
97+
END_RCPP
98+
}
8899
// num_hexagons
89100
NumericVector num_hexagons(NumericVector res);
90101
RcppExport SEXP _h3_num_hexagons(SEXP resSEXP) {
@@ -153,6 +164,7 @@ static const R_CallMethodDef CallEntries[] = {
153164
{"_h3_rcpp_h3_to_geo_boundary", (DL_FUNC) &_h3_rcpp_h3_to_geo_boundary, 1},
154165
{"_h3_h3_get_resolution", (DL_FUNC) &_h3_h3_get_resolution, 1},
155166
{"_h3_h3_is_valid", (DL_FUNC) &_h3_h3_is_valid, 1},
167+
{"_h3_h3_get_base_cell", (DL_FUNC) &_h3_h3_get_base_cell, 1},
156168
{"_h3_num_hexagons", (DL_FUNC) &_h3_num_hexagons, 1},
157169
{"_h3_hex_area", (DL_FUNC) &_h3_hex_area, 2},
158170
{"_h3_rcpp_k_ring", (DL_FUNC) &_h3_rcpp_k_ring, 2},

src/h3_inspection.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,19 @@ LogicalVector h3_is_valid(CharacterVector h3Str) {
3434

3535
return z;
3636
}
37+
38+
//' Get the base cells of the given H3 indexes.
39+
//' @param h3Str character vector of H3 indexes
40+
//' @return numeric vector; base cell numbers between 0 and 121
41+
//' @export
42+
// [[Rcpp::export]]
43+
NumericVector h3_get_base_cell(CharacterVector h3Str) {
44+
int n = h3Str.size();
45+
NumericVector z(n);
46+
for (int i = 0; i < n; ++i) {
47+
H3Index h3 = stringToH3(h3Str[i]);
48+
z[i] = h3GetBaseCell(h3);
49+
}
50+
51+
return z;
52+
}

0 commit comments

Comments
 (0)