An open API service indexing awesome lists of open source software.

https://github.com/crazycapivara/h3forr

An R Interface to H3 via V8 and h3-js
https://github.com/crazycapivara/h3forr

h3 hexagon hexagonal-hierachical-spatial-index r r-bindings spatial spatial-index

Last synced: 3 months ago
JSON representation

An R Interface to H3 via V8 and h3-js

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 = "100%"
)
```
# h3forr

[![Travis build status](https://travis-ci.org/crazycapivara/h3forr.svg?branch=master)](https://travis-ci.org/crazycapivara/h3forr) [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![H3 Version](https://img.shields.io/badge/h3-v3.7.0-blue.svg)](https://github.com/uber/h3/releases/tag/v3.7.0)
[![R build status](https://github.com/crazycapivara/h3forr/workflows/R-CMD-check/badge.svg)](https://github.com/crazycapivara/h3forr/actions)

Provides R bindings for [H3](https://uber.github.io/h3/), a hexagonal hierarchical spatial indexing system, via [V8](https://github.com/jeroen/V8) and [h3-js](https://github.com/uber/h3-js).

See [h3-r](https://github.com/crazycapivara/h3-r) for R bindings to the H3 C library.

![](man/figures/README-road-safety.png)

## Installation

You can install h3forr from github with:

``` r
# install.packages("remotes")
remotes::install_github("crazycapivara/h3forr")
```

## Quickstart

Core functions:

```{r example}
library(h3forr)

# Convert a lat/lng point to a hexagon index at resolution 7
coords <- c(37.3615593, -122.0553238)

(h3_index <- geo_to_h3(coords, res = 7))

# Get the center of the hexagon
h3_to_geo(h3_index)

# Get the vertices of the hexagon
h3_to_geo_boundary(h3_index, format_as_geojson = FALSE)
```

Useful algorithms:

```{r algorithms}
(neighbors <- k_ring(h3_index, ring_size = 1))

h3_to_geo_boundary(neighbors) %>%
geo_boundary_to_sf()

h3_set_to_multi_polygon(neighbors)
```