R/h3_to_placekey.R

Defines functions h3_to_placekey

Documented in h3_to_placekey

#' Convert h3 string to placekey
#'
#' Given an h3 string identify the _where_ portion of a placekey.
#'
#' @export
h3_to_placekey <- function(h3_string) {

  h3_integer <- h3_string_to_int(h3_string)
  short_h3_int <- shorten_h3_integer(h3_integer)

  encoded_short_int <- encode_short_int(short_h3_int)

  cleaned_encoded <- clean_string(encoded_short_int)

  index_start <- seq(1, nchar(cleaned_encoded), by = TUPLE_LENGTH)
  index_stop <- index_start + TUPLE_LENGTH -1

  encoded_splits <- purrr::map2_chr(.x = index_start,
                                    .y = index_stop,
                                    .f = ~substr(cleaned_encoded, .x, .y))

  paste0("@", paste0(encoded_splits, collapse = "-"))
}
JosiahParry/placekey documentation built on March 17, 2023, 2:41 a.m.