https://github.com/crazycapivara/h3-r
R bindings for H3, a hierarchical hexagonal geospatial indexing system
https://github.com/crazycapivara/h3-r
geocoding geospatial h3 hexagon r r-bindings spatial-indexing
Last synced: 5 months ago
JSON representation
R bindings for H3, a hierarchical hexagonal geospatial indexing system
- Host: GitHub
- URL: https://github.com/crazycapivara/h3-r
- Owner: crazycapivara
- License: other
- Created: 2019-01-11T17:58:47.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-08T08:04:12.000Z (about 3 years ago)
- Last Synced: 2025-04-01T03:12:24.675Z (6 months ago)
- Topics: geocoding, geospatial, h3, hexagon, r, r-bindings, spatial-indexing
- Language: R
- Homepage:
- Size: 854 KB
- Stars: 76
- Watchers: 6
- Forks: 11
- Open Issues: 9
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
README
---
output: github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "400px"
)
```
# H3-R[](https://github.com/crazycapivara/h3-r/actions)
[](https://www.repostatus.org/#active)
[](https://github.com/uber/h3/releases/tag/v3.7.1)
[](https://CRAN.R-project.org/package=h3)Provides R bindings for [H3](https://h3geo.org/), a hexagonal hierarchical spatial indexing system.
## Documentation
* [H3-R](https://crazycapivara.github.io/h3-r/)
* [H3](https://h3geo.org/docs/)## Notes
Succesfully built on
* Linux
* macOS
* WindowsSince 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.
## Installation
Once on [CRAN](https://cran.r-project.org/) you can install {h3} with:
```r
install.packages("h3")
```You can install the latest version of {h3} from github with:
```{r installation, eval = FALSE}
# install.packages("remotes")
remotes::install_github("crazycapivara/h3-r")
```## Usage
Core functions:
```{r h3-core}
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:
```{r h3-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")
```## Run tests
```{r tests}
devtools::test(reporter = "minimal")
```