local_options <- options()
library(sf)
library(dplyr)
library(ggplot2)
library(h3jsr)
# for R < 4, since H3 addresses are handled as strings
options(stringsAsFactors = FALSE)

General information

h3jsr connects Uber’s H3 geospatial library to R, via its transpiled JavaScript implementation,h3-js. The library has extensive potential applications in network analysis, trip routing, and geospatial data aggregation. The wrapper functions provided are intended to interface well with the existing R-spatial ecosystem, particularly sf.

  • Documentation for the core H3 library is at H3’s github page.
  • The core library only understands WGS84 coordinates, so multiple projection support is limited. All spatial objects are returned in WGS84, and ideally should be supplied as such. It’s always safer to do your own spatial transformations and verify the results. If spatial data in a coordinate system other than WGS84 is supplied, it is transformed using sf::st_transform() and a message is issued.
  • For each function in h3jsr, the default behaviour is to return data in as simple a structure as is practical, but there is always an option to return a more complex-object containing both input and output data, as appropriate for the function in question.
  • This package uses V8 to interface with h3-js. As such, a lot of the overhead for each function call is related to sending data to and from V8 via JSON conversion. Feeding large datasets in often gives faster results than one might expect from the toy examples below. Avoid using these functions in conjunction with e.g. base::lapply or purrr::map on individual geometries!

Core Functions

Nine core functions exist - three for translating spatial data into and out of the H3 system, and six information utilities, including an address validity checker.

point_to_h3() takes in sf-style point data and will return the address each point falls into. You can extract addresses for on