knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "400px" )
Provides R bindings for H3, a hexagonal hierarchical spatial indexing system.
Succesfully built on
Since v3.7.1 {h3} comes with a bundled version of the H3 C library, so that you no longer have to build it yourself before installing the R package.
Once on CRAN you can install {h3} with:
install.packages("h3")
You can install the latest version of {h3} from github with:
# install.packages("remotes") remotes::install_github("crazycapivara/h3-r")
Core functions:
library(h3) coords <- c(37.3615593, -122.0553238) resolution <- 7 # Convert a lat/lng point to a hexagon index at resolution 7 (h3_index <- geo_to_h3(coords, resolution)) # Get the center of the hexagon h3_to_geo_sf(h3_index) # Get the vertices of the hexagon h3_to_geo_boundary(h3_index) # Get the polygon of the hexagon h3_to_geo_boundary_sf(h3_index)
Useful algorithms:
# Get all neighbors within 1 step of the hexagon radius <- 1 (neighbors <- k_ring(h3_index, radius)) h3_to_geo_boundary_sf(neighbors) %>% sf::st_geometry() %>% plot(col = "blue") h3_set_to_multi_polygon(neighbors) %>% sf::st_geometry() %>% plot(col = "green")
devtools::test(reporter = "minimal")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.