Skip to content

Commit

Permalink
Merge pull request #16 from crazycapivara/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
crazycapivara authored Mar 8, 2019
2 parents 3ac025c + 6e3fbb2 commit 720c940
Show file tree
Hide file tree
Showing 31 changed files with 832 additions and 9 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: h3
Title: R bindings for H3
Version: 3.3.0
Date: 2019-02-17
Version: 3.3.1
Date: 2019-03-08
Authors@R: person("Stefan","Kuethe", role = c("aut", "cre"), email = "[email protected]")
Maintainer: Stefan Kuethe <[email protected]>
Description: Provides R bindings for H3 <https://uber.github.io/h3/>,
Expand All @@ -26,5 +26,5 @@ Suggests:
rmarkdown,
leaflet,
dplyr
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
VignetteBuilder: knitr
13 changes: 13 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ S3method(geo_to_h3,numeric)
S3method(geo_to_h3,sf)
S3method(geo_to_sf,matrix)
export("%>%")
export(compact)
export(edge_boundary_to_sf)
export(edge_length)
export(geo_boundary_to_sf)
export(geo_to_h3)
export(geo_to_sf)
export(get_destination_h3_index_from_unidirectional_edge)
export(get_h3_unidirectional_edge)
export(get_h3_unidirectional_edge_boundary)
export(get_h3_unidirectional_edge_boundary_sf)
export(get_h3_unidirectional_edges_from_hexagon)
export(get_origin_h3_index_from_unidirectional_edge)
export(h3_distance)
export(h3_get_base_cell)
export(h3_get_resolution)
export(h3_indexes_are_neighbors)
export(h3_is_pentagon)
export(h3_is_res_class_iii)
export(h3_is_valid)
export(h3_set_to_multi_polygon)
export(h3_to_children)
Expand All @@ -22,6 +34,7 @@ export(h3_to_geo_boundary)
export(h3_to_geo_boundary_sf)
export(h3_to_geo_sf)
export(h3_to_parent)
export(h3_unidirectional_edge_is_valid)
export(hex_area)
export(k_ring)
export(k_ring_distances)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# h3 3.3.1

* Added bindings for `compact`, `edgeLength`, `h3IsPentagon` and `h3IsResClassIII`
* Added _unidirectional edge functions_

# h3 3.3.0

* Added `pkgdown` site.
Expand Down
69 changes: 69 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ rcpp_h3_to_children <- function(h3s, res) {
.Call(`_h3_rcpp_h3_to_children`, h3s, res)
}

rcpp_compact <- function(h3Str) {
.Call(`_h3_rcpp_compact`, h3Str)
}

rcpp_geo_to_h3 <- function(latlng, res) {
.Call(`_h3_rcpp_geo_to_h3`, latlng, res)
}
Expand Down Expand Up @@ -45,6 +49,23 @@ h3_get_base_cell <- function(h3Str) {
.Call(`_h3_h3_get_base_cell`, h3Str)
}

#' Check whether the given H3 indexes are pentagons.
#' @param h3Str character vector of H3 indexes
#' @return logical vector
#' @export
h3_is_pentagon <- function(h3Str) {
.Call(`_h3_h3_is_pentagon`, h3Str)
}

#' Check whether the given H3 indexes have a resolution
#' with Class III orientation.
#' @param h3Str character vector of H3 indexes
#' @return logical vector
#' @export
h3_is_res_class_iii <- function(h3Str) {
.Call(`_h3_h3_is_res_class_iii`, h3Str)
}

#' Number of unique H3 indexes at the given resolution.
#' @param res numeric vector; resolution between 0 and 15
#' @return numeric vector
Expand All @@ -62,6 +83,15 @@ hex_area <- function(res, unit) {
.Call(`_h3_hex_area`, res, unit)
}

#' Average hexagon edge length in meters or kilometers at the given resolution.
#' @param res resolution between 0 and 15
#' @param unit either \code{m} or \code{km}
#' @return numeric vector
#' @export
edge_length <- function(res, unit) {
.Call(`_h3_edge_length`, res, unit)
}

rcpp_k_ring <- function(h3s, radius) {
.Call(`_h3_rcpp_k_ring`, h3s, radius)
}
Expand All @@ -79,3 +109,42 @@ rcpp_k_ring_distances <- function(h3s, radius) {
.Call(`_h3_rcpp_k_ring_distances`, h3s, radius)
}

#' Check whether the given hexagons are neighbors.
#' @param origin character scalar; origin H3 index
#' @param destinations character vector of destination H3 indexes
#' @export
h3_indexes_are_neighbors <- function(origin, destinations) {
.Call(`_h3_h3_indexes_are_neighbors`, origin, destinations)
}

#' Get the H3 edge index based on the given origin and destination hexagons.
#' @param origin character scalar; origin H3 index
#' @param destination character scalar; destination H3 index
#' @export
get_h3_unidirectional_edge <- function(origin, destination) {
.Call(`_h3_get_h3_unidirectional_edge`, origin, destination)
}

#' Check whether the given indexes are valid H3 edge indexes.
#' @param h3_edge_indexes character vector of H3 edge indexes
#' @export
h3_unidirectional_edge_is_valid <- function(h3_edge_indexes) {
.Call(`_h3_h3_unidirectional_edge_is_valid`, h3_edge_indexes)
}

rcpp_get_h3_unidirectional_edge_boundary <- function(h3EdgeStr) {
.Call(`_h3_rcpp_get_h3_unidirectional_edge_boundary`, h3EdgeStr)
}

rcpp_get_h3_unidirectional_edges_from_hexagon <- function(originStr) {
.Call(`_h3_rcpp_get_h3_unidirectional_edges_from_hexagon`, originStr)
}

rcpp_get_origin_h3_index_from_unidirectional_edge <- function(h3EdgeStr) {
.Call(`_h3_rcpp_get_origin_h3_index_from_unidirectional_edge`, h3EdgeStr)
}

rcpp_get_destination_h3_index_from_unidirectional_edge <- function(h3EdgeStr) {
.Call(`_h3_rcpp_get_destination_h3_index_from_unidirectional_edge`, h3EdgeStr)
}

16 changes: 16 additions & 0 deletions R/edge-boundary-to-sf.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Parse edge coordiantes to \code{sf} object
#' @param latlng matrix (2x2); edge coordinates
#' @export
edge_boundary_to_sf <- function(latlng) {
sf::st_linestring(latlng[, 2:1]) %>%
sf::st_sfc(crs = 4326) %>%
sf::st_sf()
}

#' Get the unidirectional edge as \code{sf} object.
#' @inheritParams get_h3_unidirectional_edge_boundary
#' @export
get_h3_unidirectional_edge_boundary_sf <- function(h3_edge_index) {
get_h3_unidirectional_edge_boundary(h3_edge_index) %>%
edge_boundary_to_sf()
}
7 changes: 7 additions & 0 deletions R/h3_hierachy.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ h3_to_parent <- function(h3_index, res) {
h3_to_children <- function(h3_index, res) {
rcpp_h3_to_children(h3_index, res)
}

#' Compact a set of hexagons of the same resolution into a set of hexagons across multiple levels.
#' @param h3_indexes character vector of H3 indexes
#' @export
compact <- function(h3_indexes) {
rcpp_compact(h3_indexes)
}
28 changes: 28 additions & 0 deletions R/h3_uniedge.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#' Get the coordinates defining the unidirectional edge.
#' @param h3_edge_index character scalar; H3 edge index
#' @export
get_h3_unidirectional_edge_boundary <- function(h3_edge_index) {
rcpp_get_h3_unidirectional_edge_boundary(h3_edge_index)
}

#' Get all of the unidirectional edges from the given H3 index.
#' @param h3_index character scalar; H3 index
#' @example inst/examples/api-reference/get-h3-unidirectional-edges-from-hexagon.R
#' @export
get_h3_unidirectional_edges_from_hexagon <- function(h3_index) {
rcpp_get_h3_unidirectional_edges_from_hexagon(h3_index)
}

#' Get the origin hexagon from the unidirectional H3 edge index.
#' @inheritParams get_h3_unidirectional_edge_boundary
#' @export
get_origin_h3_index_from_unidirectional_edge <- function(h3_edge_index) {
rcpp_get_origin_h3_index_from_unidirectional_edge(h3_edge_index)
}

#' Get the destination hexagon from the unidirectional H3 edge index.
#' @inheritParams get_h3_unidirectional_edge_boundary
#' @export
get_destination_h3_index_from_unidirectional_edge <- function(h3_edge_index) {
rcpp_get_destination_h3_index_from_unidirectional_edge(h3_edge_index)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
edges <- road_safety_greater_manchester[1, ] %>%
geo_to_h3() %>%
get_h3_unidirectional_edges_from_hexagon()

h3_unidirectional_edge_is_valid(edges)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
h3_index <- road_safety_greater_manchester[1, ] %>%
geo_to_h3()

edges <- get_h3_unidirectional_edges_from_hexagon(h3_index)
get_origin_h3_index_from_unidirectional_edge(edges[1]) == h3_index
14 changes: 14 additions & 0 deletions man/compact.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/edge_boundary_to_sf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/edge_length.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/get_destination_h3_index_from_unidirectional_edge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions man/get_h3_unidirectional_edge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/get_h3_unidirectional_edge_boundary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/get_h3_unidirectional_edge_boundary_sf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions man/get_h3_unidirectional_edges_from_hexagon.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/get_origin_h3_index_from_unidirectional_edge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions man/h3_indexes_are_neighbors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 720c940

Please sign in to comment.