knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-",
  warning = FALSE
)

R build status R build status R build status Coverage status CRAN Downloads

h3jsr

h3jsr provides access to Uber's H3 library via its javascript transpile, using the magical power of V8.

H3 is a hexagonal hierarchical geospatial indexing system. Details about its structure and use cases can be found here.

Installation

Install from CRAN with

install.packages('h3jsr')

Install the development version from GitHub with

remotes::install_github("obrl-soil/h3jsr")

:bulb: Version (v1.3.0) contains an API revision, so some functions have new names. See the NEWS.

Example

library(h3jsr)
library(sf)

# where is the Brisbane Town Hall at resolution 15?
bth <- st_sfc(st_point(c(153.023503, -27.468920)), crs = 4326)
point_to_cell(bth, res = 15)

# where is it at several resolutions?
point_to_cell(bth, res = seq(10, 15), simple = FALSE)

# Where is the center of the hexagon over the Brisbane Town 
# Hall at resolution 10?
brisbane_10 <- cell_to_point(h3_address = '8abe8d12acaffff')
brisbane_10

# Is that a valid H3 address?
is_valid(h3_address = '8abe8d12acaffff')

# is it a pentagon?
is_pentagon(h3_address = '8abe8d12acaffff')

# is it Class III?
is_rc3(h3_address = '8abe8d12acaffff')

# What is Brisbane Town Hall's base cell number?
get_base_cell(h3_address = '8abe8d12acaffff')

# What is the hexagon over the Brisbane Town Hall at resolution 10?
brisbane_hex_10 <- cell_to_polygon(input = '8abe8d12acaffff', simple = FALSE)

# if you're feeling fancy,
# point_to_cell(bth, res = seq(10,15)) %>%
#   unlist() %>%
#   h3_to_polygon(., simple = FALSE) %>%
#   mapview::mapview()

Props to Joel Gombin, who's package concaveman provided me with the implementation inspo.




obrl-soil/h3jsr documentation built on Jan. 27, 2024, 4:33 a.m.