GithubHelp home page GithubHelp logo

cole-brokamp / h3-r Goto Github PK

View Code? Open in Web Editor NEW

This project forked from crazycapivara/h3-r

0.0 2.0 0.0 820 KB

R bindings for H3, a hierarchical hexagonal geospatial indexing system

License: Other

R 96.28% Shell 0.88% Dockerfile 2.85%

h3-r's Introduction

H3-R

R build status Project Status: Active โ€“ The project has reached a stable, usable state and is being actively developed. H3 Version

Provides R bindings for H3, a hexagonal hierarchical spatial indexing system.

Documentation

Notes

Succesfully built on

  • Linux
  • OSX
  • Windows

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.

Installation

You can install h3 from github with:

# install.packages("remotes")
remotes::install_github("crazycapivara/h3-r")

Usage

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)) 
#> [1] "87283472bffffff"

# Get the center of the hexagon
h3_to_geo_sf(h3_index)
#> Simple feature collection with 1 feature and 0 fields
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: -122.0503 ymin: 37.35172 xmax: -122.0503 ymax: 37.35172
#> CRS:            EPSG:4326
#>                     geometry
#> 1 POINT (-122.0503 37.35172)

# Get the vertices of the hexagon
h3_to_geo_boundary(h3_index)
#> [[1]]
#>           lat       lng
#> [1,] 37.34110 -122.0416
#> [2,] 37.35290 -122.0340
#> [3,] 37.36352 -122.0428
#> [4,] 37.36234 -122.0591
#> [5,] 37.35054 -122.0666
#> [6,] 37.33992 -122.0579

# Get the polygon of the hexagon
h3_to_geo_boundary_sf(h3_index)
#> Simple feature collection with 1 feature and 0 fields
#> geometry type:  POLYGON
#> dimension:      XY
#> bbox:           xmin: -122.0666 ymin: 37.33992 xmax: -122.034 ymax: 37.36352
#> CRS:            EPSG:4326
#>                         geometry
#> 1 POLYGON ((-122.0416 37.3411...

Useful algorithms:

# Get all neighbors within 1 step of the hexagon
radius <- 1
(neighbors <- k_ring(h3_index, radius))
#> [1] "87283472bffffff" "87283472affffff" "87283470cffffff" "87283470dffffff"
#> [5] "872834776ffffff" "872834729ffffff" "872834728ffffff"

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

devtools::test(reporter = "minimal")
#> Loading h3
#> Testing h3
#> ..............................................

h3-r's People

Contributors

crazycapivara avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.