Learn R Programming

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)
#> Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE

# 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)
#> [1] "8fbe8d12acad2f3"

# where is it at several resolutions?
point_to_cell(bth, res = seq(10, 15), simple = FALSE)
#>   h3_resolution_10 h3_resolution_11 h3_resolution_12 h3_resolution_13
#> 1  8abe8d12acaffff  8bbe8d12acadfff  8cbe8d12acad3ff  8dbe8d12acad2ff
#>   h3_resolution_14 h3_resolution_15
#> 1  8ebe8d12acad2f7  8fbe8d12acad2f3

# 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
#> Geometry set for 1 feature 
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 153.0239 ymin: -27.46853 xmax: 153.0239 ymax: -27.46853
#> Geodetic CRS:  WGS 84
#> POINT (153.0239 -27.46853)

# Is that a valid H3 address?
is_valid(h3_address = '8abe8d12acaffff')
#> [1] TRUE

# is it a pentagon?
is_pentagon(h3_address = '8abe8d12acaffff')
#> [1] FALSE

# is it Class III?
is_rc3(h3_address = '8abe8d12acaffff')
#> [1] FALSE

# What is Brisbane Town Hall's base cell number?
get_base_cell(h3_address = '8abe8d12acaffff')
#> [1] 95

# 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.


Copy Link

Version

Install

install.packages('h3jsr')

Monthly Downloads

651

Version

1.3.1

License

Apache License (>= 2)

Maintainer

Lauren O'Brien

Last Published

January 21st, 2023

Functions in h3jsr (1.3.1)

get_children

get child H3 cell indices
get_ring

Get a ring of H3 cell indexes
degs_to_rads

Convert degrees to radians
get_uddest

Get destination cell from directed edge
get_res

get the resolution of an H3 cell index
get_pentagons

get the pentagon indices for an H3 resolution
get_parent

get parent H3 cell index
get_res0

Get resolution 0 indexes
get_local_cell

Get H3 cell from local i, j coordinates
get_local_ij

Get local i, j coordinates
get_udends

Get origin and destination indexes of directed edge
get_udorigin

Get origin cell index from directed edge
get_udedges

Get all directed edge indexes for a given H3 cell
get_udedge

Get a unidirectional edge index
grid_distance

Grid distance between H3 cells
grid_path

Path between H3 cells
rads_to_degs

Convert radians to degrees
res_area

Get average cell area
is_pentagon

check if H3 cell index is a pentagon
is_rc3

check if H3 cell index is in a Class III resolution
h3jsr-package

h3jsr: Access Uber's H3 library
h3_info_table

H3 index utility information table
res_cendist

Get average distance between H3 cell centers
prep_for_pt2cell

Prepare inputs for point_to_cell
prep_for_polyfill

Prepare geometry for polygon_to_cells
is_valid_vertex

check H3 cell index
is_valid

check H3 cell index
is_valid_edge

Check H3 unidirectional edge index
get_faces

get the icosahedron faces of an H3 cell index
get_gcdist

Great circle distance
res_length

Get average cell edge length
vertex_to_point

Convert H3 cell vertex index to point location
num_cells

Get total H3 cells
uncompact

Uncompact H3 cell indices
udedge_to_line

Get the geometry of an H3 edge
point_to_cell

Convert point location to H3 cell index
polygon_to_cells

Get H3 cell index within a polygon
splitlong_to_cell

Split long to H3 cell
cell_to_childpos

Cell to Child position
childpos_to_cell

Child position to cell
cell_to_line

Convert H3 cell indexes to a line
are_neighbours

check if H3 cells are neighbours
cell_to_point

Convert H3 cell index to point location
cells_to_multipolygon

Get geometry for a set of H3 cells
cell_to_polygon

Get the boundary of an H3 cell index
cell_to_children_size

Cell to children size
cell_area

Get exact cell area
get_centerchild

get central child H3 cell index
get_disk

Get nearby H3 cell indices
compact

Compact H3 cells
cell_to_splitlong

H3 cell to split long
get_disk_list

Get nearby H3 cell indexes separated by distance
get_cell_vertexes

Get all vertex indexes
get_cell_vertex

Get a vertex index
get_base_cell

get the base cell of an H3 cell index
edge_length

Get exact cell edge length