diff --git a/.gitignore b/.gitignore index 0dcfcdc..5153cee 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ .V8history inst/doc update_process.txt -docs +^docs/ diff --git a/docs/404.html b/docs/404.html deleted file mode 100644 index 60beca5..0000000 --- a/docs/404.html +++ /dev/null @@ -1,96 +0,0 @@ - - -
- - - - -Version 2.0, January 2004 <http://www.apache.org/licenses/>
-“License” shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
-“Licensor” shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
-“Legal Entity” shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, “control” means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
-“You” (or “Your”) shall mean an individual or Legal Entity exercising permissions granted by this License.
-“Source” form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
-“Object” form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
-“Work” shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
-“Derivative Works” shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
-“Contribution” shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, “submitted” means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as “Not a Contribution.”
-“Contributor” shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
-Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
-Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
-You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
-You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
-Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
-This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
-Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
-In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
-While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
-END OF TERMS AND CONDITIONS
-To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets []
replaced with your own identifying information. (Don’t include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same “printed page” as the copyright notice for easier identification within third-party archives.
2021 Lauren O'Brien
- Copyright
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
intro-to-h3jsr.Rmd
-local_options <- options()
-library(sf)
-library(dplyr)
-library(ggplot2)
-library(h3jsr)
-# for R < 4, since H3 addresses are handled as strings
-options(stringsAsFactors = FALSE)
h3jsr connects Uber’s H3 geospatial library to R, via its transpiled
-JavaScript implementation,h3-js
. The library has extensive
-potential applications in network analysis, trip routing, and geospatial
-data aggregation. The wrapper functions provided are intended to
-interface well with the existing R-spatial ecosystem, particularly
-sf
.
sf::st_transform()
and a message is issued.h3jsr
, the default behaviour is to
-return data in as simple a structure as is practical, but there is
-always an option to return a more complex-object containing both input
-and output data, as appropriate for the function in question.V8
to interface with
-h3-js
. As such, a lot of the overhead for each function
-call is related to sending data to and from V8 via JSON conversion.
-Feeding large datasets in often gives faster results than one might
-expect from the toy examples below. Avoid using these functions in
-conjunction with e.g. base::lapply
or
-purrr::map
on individual geometries!Nine core functions exist - three for translating spatial data into -and out of the H3 system, and six information utilities, including an -address validity checker.
-point_to_cell()
takes in sf
-style point
-data and will return the address each point falls into. You can extract
-addresses for one resolution or many. This function will also accept a
-matrix or data frame as input, but this will only work if columns 1 and
-2 contain WGS84 longitude and latitude values, respectively.
-# This is the location of the Brisbane Town Hall:
-bth <- sf::st_sfc(sf::st_point(c(153.023503, -27.468920)), crs = 4326)
-
-# where is the Brisbane Town Hall at resolution 15?
-point_to_cell(bth, res = 15)
-#> [1] "8fbe8d12acad2f3"
By default, a character vector is returned for a single resolution,
-and a data frame where multiple resolutions are requested. If
-simple = FALSE
and the input object inherits from
-data.frame
, a data frame object is returned with a new
-attribute column for each resolution requested.
-nc <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
-nc_pts <- st_centroid(nc)
-nc_pts <- st_transform(nc_pts, crs = 4326)
-nc_pts <- dplyr::select(nc_pts, CNTY_ID, NAME)
-
-# Give me the address for the center of each NC county at every resolution
-nc_all_res <- point_to_cell(nc_pts, res = seq(0, 15), simple = FALSE)
-head(nc_all_res[, c(1:5)])
-#> CNTY_ID NAME h3_resolution_0 h3_resolution_1 h3_resolution_2
-#> 1 1825 Ashe 802bfffffffffff 812abffffffffff 8244dffffffffff
-#> 2 1827 Alleghany 802bfffffffffff 812abffffffffff 8244dffffffffff
-#> 3 1828 Surry 802bfffffffffff 812abffffffffff 822a8ffffffffff
-#> 4 1831 Currituck 802bfffffffffff 812afffffffffff 822af7fffffffff
-#> 5 1832 Northampton 802bfffffffffff 812afffffffffff 822af7fffffffff
-#> 6 1833 Hertford 802bfffffffffff 812afffffffffff 822af7fffffffff
H3 addresses can be translated back to a point at a given resolution
-with cell_to_point()
. A polygon (almost always a hexagon),
-can be retrieved with cell_to_polygon()
.
-# plot a few
-ashe_hexes <- unlist(nc_all_res[1, c(6,7,8,9,10)], use.names = FALSE)
-ashe_hexes <- cell_to_polygon(ashe_hexes, simple = FALSE)
-ggplot(nc[1,]) +
- geom_sf(fill = NA, colour = 'black') +
- geom_sf(data = ashe_hexes, aes(fill = h3_address), alpha = 0.5) +
- scale_fill_viridis_d() +
- ggtitle('H3 hexagons over County Ashe, NC', subtitle = 'Resolutions 6-10') +
- theme_minimal() +
- coord_sf()
Hopefully the above plot gives a sense of the large scale changes -between resolution levels - each level is seven times more detailed than -the last.
-H3 address validity checks are done with is_valid()
:
-is_valid(h3_address = '8abe8d12acaffff')
-#> [1] TRUE
-is_valid(h3_address = '8abe8d12aca')
-#> [1] FALSE
You can check whether an address refers to one of the pentagons that
-occur on icosahedron corners at each resolution with
-is_pentagon()
. This is relevant where subsequent area or
-distance calculations will be carried out. All of the pentagon indices
-for a given resolution can be identified using
-get_pentagons()
.
-# is the following address a pentagon?
-is_pentagon(h3_address = '8abe8d12acaffff')
-#> [1] FALSE
-
-get_pentagons(res = 8)
-#> [[1]]
-#> [1] "8808000001fffff" "881c000001fffff" "8830000001fffff" "884c000001fffff"
-#> [5] "8862000001fffff" "8874000001fffff" "887e000001fffff" "8890000001fffff"
-#> [9] "88a6000001fffff" "88c2000001fffff" "88d6000001fffff" "88ea000001fffff"
-
-ggplot() +
- geom_sf(data = cell_to_polygon(get_pentagons(8)[[1]][1]), fill = NA) +
- theme_void()
is_rc3()
checks whether an H3 address has a resolution
-with Class III orientation. This refers to the orientation of
-the hex grid relative to the next coarser resolution.
-is_rc3(h3_address = '8abe8d12acaffff')
-#> [1] FALSE
The number of the base (resolution-0) cell for any H3 address can be
-retrieved with get_base_cell()
. These run from 0 at the
-North Pole to 121 at the South.
-get_base_cell(h3_address = '8abe8d12acaffff')
-#> [1] 95
The triangular icosahedron face (or faces) that a cell belongs to can
-also be retrieved with get_faces()
. These run 1-20, North
-to South.
-get_faces(h3_address = '8abe8d12acaffff')
-#> [1] 15
Lastly, the resolution of an H3 address can be retrieved with
-get_res()
.
-get_res(h3_address = '8abe8d12acaffff')
-#> [1] 10
As the H3 grid system is hierarchical, addresses have parents and -children. A parent address is the one that contains the given address at -a coarser resolution. A child address is contained by the given address. -Parents and children can be requested at any resolution above and below -the input, respectively.
-
-# input is res 10:
-get_parent(h3_address = '8abe8d12acaffff', res = 6)
-#> [1] "86be8d12fffffff"
-# input is res 6:
-get_children(h3_address = '86be8d12fffffff', res = 7)
-#> [[1]]
-#> [1] "87be8d128ffffff" "87be8d129ffffff" "87be8d12affffff" "87be8d12bffffff"
-#> [5] "87be8d12cffffff" "87be8d12dffffff" "87be8d12effffff"
-
-ggplot() +
- geom_sf(data = cell_to_polygon('86be8d12fffffff'), fill = NA) +
- geom_sf(data = cell_to_polygon(get_children(h3_address = '86be8d12fffffff',
- res = 7)[[1]]),
- fill = 'red', alpha = 0.5 ) +
- theme_void()
The number of addresses returned for each request is
-7 ^ (parent_res - child_res)
, so jumping three levels will
-return 343 addresses for a single input, and that’s about 41 kb.
To return only the central child for a given address, use
-get_centerchild()
:
-# input is res 6:
-get_centerchild(h3_address = '86be8d12fffffff', res = 7)
-#> [1] "87be8d128ffffff"
-
-ggplot() +
- geom_sf(data = cell_to_polygon('86be8d12fffffff'), fill = NA) +
- geom_sf(data = cell_to_polygon(get_centerchild('86be8d12fffffff', 7)),
- fill = 'red') +
- geom_sf(data = cell_to_polygon(get_centerchild('86be8d12fffffff', 8)),
- fill = 'blue') +
- theme_void()
Within the same resolution, addresses within n ‘steps’ from
-a central address (a ‘patch’ of hexagons) can be retrieved with
-get_disk()
or get_disk_list()
. The latter
-function returns an output where addresses are listed separately for
-each step away from the input. The input address is included in the
-output.
-get_disk(h3_address = '86be8d12fffffff', ring_size = 2)
-#> [[1]]
-#> [1] "86be8d12fffffff" "86be8d127ffffff" "86be8d107ffffff" "86be8d10fffffff"
-#> [5] "86be8d177ffffff" "86be8d8dfffffff" "86be8d8d7ffffff" "86be8d88fffffff"
-#> [9] "86be8d89fffffff" "86be8d137ffffff" "86be8d117ffffff" "86be8d11fffffff"
-#> [13] "86be8d027ffffff" "86be8d157ffffff" "86be8d147ffffff" "86be8d167ffffff"
-#> [17] "86be8d8cfffffff" "86be8d8c7ffffff" "86be8d8f7ffffff"
-
-get_disk_list(h3_address = '86be8d12fffffff', ring_size = 2)
-#> [[1]]
-#> [[1]][[1]]
-#> [1] "86be8d12fffffff"
-#>
-#> [[1]][[2]]
-#> [1] "86be8d127ffffff" "86be8d107ffffff" "86be8d10fffffff" "86be8d177ffffff"
-#> [5] "86be8d8dfffffff" "86be8d8d7ffffff"
-#>
-#> [[1]][[3]]
-#> [1] "86be8d88fffffff" "86be8d89fffffff" "86be8d137ffffff" "86be8d117ffffff"
-#> [5] "86be8d11fffffff" "86be8d027ffffff" "86be8d157ffffff" "86be8d147ffffff"
-#> [9] "86be8d167ffffff" "86be8d8cfffffff" "86be8d8c7ffffff" "86be8d8f7ffffff"
A ring of addresses at exactly n steps is obtained with
-get_ring()
.
-get_ring(h3_address = '86be8d12fffffff', ring_size = 2)
-#> [[1]]
-#> [1] "86be8d8f7ffffff" "86be8d88fffffff" "86be8d89fffffff" "86be8d137ffffff"
-#> [5] "86be8d117ffffff" "86be8d11fffffff" "86be8d027ffffff" "86be8d157ffffff"
-#> [9] "86be8d147ffffff" "86be8d167ffffff" "86be8d8cfffffff" "86be8d8c7ffffff"
These address lists can all be spatialised with
-cell_to_multipolygon()
, which returns the polygonised
-outline of a collection of H3 addresses.
-disk <- get_disk(h3_address = '86be8d12fffffff', ring_size = 2)
-
-ring <- get_ring(h3_address = '86be8d12fffffff', ring_size = 5)
-
-patch_sf <- cells_to_multipolygon(disk, simple = FALSE)
-donut_sf <- cells_to_multipolygon(ring, simple = FALSE)
-
-ggplot() +
- geom_sf(data = patch_sf, alpha = 0.5) +
- theme_minimal() +
- geom_sf(data = donut_sf, alpha = 0.5, fill = 'red') +
- theme_void()
But it may be more interesting to use
-cell_to_polygon()
-disk_singles <- cell_to_polygon(unlist(disk, use.names = FALSE), simple = FALSE)
-ring_singles <- cell_to_polygon(unlist(ring, use.names = FALSE), simple = FALSE)
-
-ggplot(disk_singles) +
- geom_sf(aes(fill = 1:nrow(disk_singles)), show.legend = FALSE) +
- scale_fill_viridis_c() +
- theme_minimal() +
- theme_void()
-
-ggplot(ring_singles) +
- geom_sf(aes(fill = 1:nrow(ring_singles)), show.legend = FALSE) +
- scale_fill_viridis_c() +
- theme_minimal() +
- theme_void()
polygon_to_cells()
will return all the h3 addresses
-whose centers intersect a given polygon. Multipolygons are supported as
-well.
-ashe <- st_transform(nc[1, ], crs = 4326)
-ashe_7 <- polygon_to_cells(ashe, res = 7, simple = FALSE)
-ashe_7 <- cell_to_polygon(unlist(ashe_7$h3_addresses), simple = FALSE)
-
-ggplot() +
- geom_sf(data = ashe, fill = NA) +
- geom_sf(data = ashe_7, fill = NA, colour = 'red') +
- ggtitle('Resolution 7 hexagons', subtitle = 'County Ashe, NC') +
- theme_minimal() +
- coord_sf()
A representation like this can be ‘compacted’ with
-compact()
.
-ashe_comp <- compact(ashe_7$h3_address)
-ashe_comp <- cell_to_polygon(ashe_comp, simple = FALSE)
-
-ggplot() +
- geom_sf(data = ashe, fill = NA) +
- geom_sf(data = ashe_comp, fill = NA, colour = 'red') +
- ggtitle('Compacted hexes from resolution 7', subtitle = 'County Ashe, NC') +
- theme_minimal() +
- coord_sf()
Note the orientation shift at each resolution change. A compacted
-representation can be uncompacted back to any resolution with
-uncompact()
, with some loss when the chosen resolution is
-more detailed than the original polygon_to_cells()
-operation.
-ashe_comp <- compact(ashe_7$h3_address)
-ashe_uncomp <- uncompact(ashe_comp, res = 8)
-
-ashe_uncomp <- cell_to_polygon(ashe_uncomp, simple = FALSE)
-
-ggplot() +
- geom_sf(data = ashe, fill = NA) +
- geom_sf(data = ashe_uncomp, fill = NA, colour = 'red') +
- theme_minimal() +
- ggtitle('Uncompacted hexes to resolution 8', subtitle = 'County Ashe, NC') +
- coord_sf()
To check whether two H3 addresses share an edge, use
-are_neighbours()
:
-# Are the following addresses neighbours?
-are_neighbours(origin = '86be8d12fffffff', destination = '86be8d127ffffff')
-#> [1] TRUE
-
-are_neighbours(origin = '86be8d12fffffff', destination = '86be8d147ffffff')
-#> [1] FALSE
-
-ggplot() +
- geom_sf(data = cell_to_polygon(c('86be8d12fffffff')),
- fill = c('red'), alpha = 0.5) +
- geom_sf(data = cell_to_polygon(c('86be8d127ffffff')),
- fill = c('blue'), alpha = 0.5) +
- geom_sf(data = cell_to_polygon(c('86be8d147ffffff')),
- fill = c('green'), alpha = 0.5) +
- theme_void()
The H3 system can also generate addresses for hex edges. To get the
-address representing the edge between to adjacent H3 addresses, use
-get_udedge()
. Note that the resultant address looks a
-little different, and has its own validity checking function,
-is_valid_edge()
:
-# Get me the edge between these two addresses
-get_udedge(origin = '86be8d12fffffff', destination = '86be8d127ffffff')
-#> [1] "166be8d12fffffff"
-
-is_valid_edge('166be8d12fffffff')
-#> [1] TRUE
-
-# not neighbours:
-#get_udedge(origin = '86be8d12fffffff', destination = '86be8d147ffffff')
The edge address can also be used to retrieve its origin and -destination hex addresses, separately or together:
-
-get_udorigin(h3_edge = '166be8d12fffffff')
-#> [1] "86be8d12fffffff"
-
-get_uddest(h3_edge = '166be8d12fffffff')
-#> [1] "86be8d127ffffff"
-
-get_udends(h3_edge = '166be8d12fffffff')
-#> [[1]]
-#> [1] "86be8d12fffffff" "86be8d127ffffff"
To get all the edges of a given H3 address, use
-get_udedges()
. Edges can be converted to
-sfc_LINESTRING
geometries with
-udedge_to_line()
:
-get_udedges(h3_address = '86be8d12fffffff')
-#> [[1]]
-#> [1] "116be8d12fffffff" "126be8d12fffffff" "136be8d12fffffff" "146be8d12fffffff"
-#> [5] "156be8d12fffffff" "166be8d12fffffff"
-
-ggplot() +
- geom_sf(data = cell_to_polygon('86be8d12fffffff'), col = NA) +
- geom_sf(data = udedge_to_line(get_udedges(h3_address = '86be8d12fffffff')[[1]]),
- aes(col = seq(6)), size = 2, show.legend = FALSE) +
- scale_color_viridis_c() +
- theme_void()
H3 v4.0+ can return addresses for cell corner vertices, which again -have their own validity checker.
-
-vtx0 <- vertex_to_point(get_cell_vertex('86be8d12fffffff', 0), simple = FALSE)
-vtxs <- vertex_to_point(get_cell_vertexes('86be8d12fffffff')[[1]], simple = FALSE)
-poly <- cell_to_polygon('86be8d12fffffff', simple = FALSE)
-is_valid_vertex(get_cell_vertex('86be8d12fffffff', 0))
-#> [1] TRUE
-
-ggplot() +
- geom_sf(data = poly, col = NA) +
- geom_sf(data = vtxs, aes(col = seq(6)), size = 3, show.legend = FALSE) +
- geom_sf(data = vtx0, col = 'red', size = 5, pch = 1, show.legend = FALSE) +
- scale_color_viridis_c() +
- theme_void()
Functions get_local_ij()
and get_local_h3()
-can be used to map H3 addresses to a 2-axis coordinate space, relative
-to a given origin address. These functions are experimental and are
-likely to change in future.
-local <- get_local_ij(origin = '86be8d12fffffff',
- destination = '86be8d127ffffff')
-
-get_local_cell(origin = '86be8d12fffffff', i = local[, 1], j = local[, 2])
-#> [1] "86be8d127ffffff"
Within the context of the H3 grid system, functions
-grid_distance()
and grid_path()
provide some
-‘navigational’ functionality. grid_distance()
will report
-how many steps through the grid are required to travel from one address
-to another. grid_path()
will return a list of addresses
-that traverse a shortest path. Note that multiple minimum-step pathways
-will be possible for many sets of addresses, but this function should
-return the same one consistently.
-nc_pts <- sf::st_centroid(nc[c(1, 2), ])
-nc_6 <- point_to_cell(nc_pts, res = 6)
-# how far apart are these two addresses?
-grid_distance(nc_6[1], nc_6[2])
-#> [1] 6
-
-# find a path between these two addresses:
-path <- grid_path(nc_6[1], nc_6[2], simple = TRUE)
-path
-#> [[1]]
-#> [1] "862a9935fffffff" "862a9934fffffff" "862a9936fffffff" "8644db267ffffff"
-#> [5] "8644db277ffffff" "8644db257ffffff" "8644db2e7ffffff"
Note that these functions only work between grid cells at the same -resolution.
-The great-circle distance between two points (e.g. cell centers) can
-also be calculated with get_dist()
, using the Haversine
-formula.
cell_to_line()
is a custom function that has been
-provided largely to make it easy to spatialise the results of
-grid_path()
. It will take a list of h3 addresses, convert
-them to points, and then turn the set of points into an
-sfc_LINESTRING
object. The function is flexible enough to
-work across an arbitrary set of addresses (including addresses at
-multiple resolutions), but this is untested and results may be
-strange.
-state_line <- cell_to_line(path)
-
-ggplot() +
- geom_sf(data = nc[c(1,2), ], fill = NA) +
- geom_sf(data = sf::st_centroid(nc[c(1,2), ]), pch = 19, size = 2) +
- geom_sf(data = cell_to_point(nc_6), pch = 19, size = 2, col = 'red') +
- geom_sf(data = cell_to_polygon(nc_6), fill = NA) +
- geom_sf(data = state_line, fill = NA, colour = 'red') +
- theme_minimal() +
- ggtitle('Counties Ashe and Alleghany, NC', subtitle = 'Line connecting hexagons containing centroids at resolution 6') +
- coord_sf()
A set of general information utilities give information about the -characteristics of the hexagons at each resolution. This includes -average area, average edge length, average distance between hexagon -centers, and the total number of addresses. This data is stored locally -but can also be calculated from source.
-
-res_area(6, 'km2')
-#> [1] 36.12906
-
-res_length(6, 'km')
-#> [1] 3.229483
-
-res_cendist(6, 'km')
-#> [1] 5.593628
-
-num_cells(6)
-#> [1] 14117882
-
-data("h3_info_table")
-str(h3_info_table)
-#> 'data.frame': 16 obs. of 8 variables:
-#> $ h3_resolution : int 0 1 2 3 4 5 6 7 8 9 ...
-#> $ avg_area_sqm : num 4.36e+12 6.10e+11 8.68e+10 1.24e+10 1.77e+09 ...
-#> $ avg_area_sqkm : num 4357449 609788 86802 12393 1770 ...
-#> $ avg_edge_m : num 1107713 418676 158245 59811 22606 ...
-#> $ avg_edge_km : num 1107.7 418.7 158.2 59.8 22.6 ...
-#> $ avg_cendist_m : num 1918614 725168 274088 103595 39155 ...
-#> $ avg_cendist_km : num 1918.6 725.2 274.1 103.6 39.2 ...
-#> $ total_unique_indexes: num 122 842 5882 41162 288122 ...
The exact area of particular cells and the length of edges can also -be calculated:
-
-cell_area(h3_address = '8abe8d12acaffff', 'km2')
-#> [1] 0.0177539
-
-edge_length(h3_edge = '166be8d12fffffff', 'km')
-#> [1] 4.037687
Functions are available to convert H3 addresses from 64-bit -hexadecimal strings to pairs of 32-bit integers, and vice versa:
-
-x <- cell_to_splitlong(h3_address = '8abe8d12acaffff')
-
-y <- splitlong_to_cell(split_lower = x[[1]][1], split_upper = x[[1]][2])
-
-x
-#> [[1]]
-#> [1] 717946879 145483985
-y
-#> [1] "8abe8d12acaffff"
Lastly, convenience functions are available for converting between -degrees and radians. These are implemented in base R by default, as the -results are identical and obtained much faster. The H3 functions remain -accessible for testing.
-
-degs_to_rads(120)
-#> [1] 2.094395
-
-rads_to_degs(1.5)
-#> [1] 85.94367
-# reset local options
-options(local_options)
h3jsr provides access to Uber’s H3 library via its javascript transpile, using the magical power of V8
.
H3 is a hexagonal hierarchical geospatial indexing system. Details about its structure and use cases can be found here.
-Install from CRAN with
-
-install.packages('h3jsr')
Install the development version from GitHub with
-
-remotes::install_github("obrl-soil/h3jsr")
--💡 The latest version (v1.3.0) contains an API revision, so some functions have new names. See the NEWS.
-
-library(h3jsr)
-library(sf)
-#> Linking to GEOS 3.9.1, GDAL 3.4.3, PROJ 7.2.1; sf_use_s2() is TRUE
-
-# where is the Brisbane Town Hall at resolution 15?
-bth <- st_sfc(st_point(c(153.023503, -27.468920)), crs = 4326)
-point_to_cell(bth, res = 15)
-#> [1] "8fbe8d12acad2f3"
-
-# where is it at several resolutions?
-point_to_cell(bth, res = seq(10, 15), simple = FALSE)
-#> h3_resolution_10 h3_resolution_11 h3_resolution_12 h3_resolution_13
-#> 1 8abe8d12acaffff 8bbe8d12acadfff 8cbe8d12acad3ff 8dbe8d12acad2ff
-#> h3_resolution_14 h3_resolution_15
-#> 1 8ebe8d12acad2f7 8fbe8d12acad2f3
-
-# Where is the center of the hexagon over the Brisbane Town
-# Hall at resolution 10?
-brisbane_10 <- cell_to_point(h3_address = '8abe8d12acaffff')
-brisbane_10
-#> Geometry set for 1 feature
-#> Geometry type: POINT
-#> Dimension: XY
-#> Bounding box: xmin: 153.0239 ymin: -27.46853 xmax: 153.0239 ymax: -27.46853
-#> Geodetic CRS: WGS 84
-#> POINT (153.0239 -27.46853)
-
-# Is that a valid H3 address?
-is_valid(h3_address = '8abe8d12acaffff')
-#> [1] TRUE
-
-# is it a pentagon?
-is_pentagon(h3_address = '8abe8d12acaffff')
-#> [1] FALSE
-
-# is it Class III?
-is_rc3(h3_address = '8abe8d12acaffff')
-#> [1] FALSE
-
-# What is Brisbane Town Hall's base cell number?
-get_base_cell(h3_address = '8abe8d12acaffff')
-#> [1] 95
-
-# What is the hexagon over the Brisbane Town Hall at resolution 10?
-brisbane_hex_10 <- cell_to_polygon(input = '8abe8d12acaffff', simple = FALSE)
-
-# if you're feeling fancy,
-# point_to_cell(bth, res = seq(10,15)) %>%
-# unlist() %>%
-# h3_to_polygon(., simple = FALSE) %>%
-# mapview::mapview()
-
Props to Joel Gombin, who’s package concaveman
provided me with the implementation inspo.
point_to_h3()
–> point_to_cell()
-h3_to_point()
–> cell_to_point()
-h3_to_polygon()
–> cell_to_polygon()
-h3_to_line()
–> cell_to_line()
-get_kring()
–> get_disk()
-get_kring_list()
–> get_disk_list()
-polyfill()
–> polygon_to_cells()
-set_to_multipolygon()
–> cells_to_multipolygon()
-res_count()
–> num_cells()
-is_valid_vertex()
, get_cell_vertex()
, get_cell_vertexes()
, and vertex_to_point()
are available for interacting with H3 in vertex mode.cell_to_splitlong()
and splitlong_to_cell()
are available for converting between 64-bit string addresses and 32-bit integer pairs.degs_to_rads()
and rads_to_degs()
available for unit conversion.CRAN release: 2022-01-04
-V8
version requirement to ensure consistent build across platformscell_area
, edge_length
, get_dist
, and get_res0
.prep_for_pt2h3
-h3_info_table
when library not loaded explicitlyget_centerchild()
, which will return the central child of a hexagon at a given resolution.get_pentagons()
, which will return the twelve pentagon indexes at a given resolution.get_faces()
, which returns the icosahedron face(s) for a given H3 address.min_path()
with official version grid_path()
, which wraps h3Line
to find a path between two addresses.h3_to_line()
, which converts a vector of H3 addresses to sfc_LINESTRING
.nearest_neighbour()
, its fundamentally flawed.get_local_ij()
to a matrix when simple = TRUEh3_to_point()
-h3_to_point()
and polyfill()
-h3_to_point()
, h3_to_polygon()
, and polyfill()
now take a wider range of input objects.get_local_ij()
and get_local_h3()
, wrapping the experimental local coordinate system functions h3.experimentalH3ToLocalIj
and h3.experimentalLocalIjToH3
respectively.min_path()
to find a minimum-steps path between two H3 addresses of the same resolution.nearest_neighbour()
to find the nearest neighbour for a given set of points. Use with caution, read the notes.polyfill()
. Where input sf
object only has a geometry column, a column called ‘ID_H3’ containing a sequential ID field is now added before sending the geometry to the V8 session.grid_distance()
, which returns the number of ‘steps’ required to get from one H3 address to another (within the same resolution).h3_polyfill()
, plus a message when output resolution is way smaller than input extent.res_cendist()
for getting the average distance between the center of each region represented by a H3 address at a given resolution.to_point()
to return an sfc_POINT
object, or an sf
point data frame where simple = FALSE
.to_polygon()
to have a similar structure to h3_to_geo()
.point_to_h3()
to take in an sf
point object and return the same when simple = FALSE
, resulting in a new dependency on tidyr
. On the upside, one can now request addresses for multiple resolutions at multiple points, if one wishes to test the limits of one’s system.res_area()
, res_edgelen()
, and res_count()
-polyfill()
and set_to_multipolygon()
added; new dependencies on sf
and geojsonsf
have resulted.to_polygon()
now returns an object with sf
geometry.compact()
and uncompact()
added, all public core algorithms now available.get_parent()
, get_children()
, get_kring()
, get_kring_list()
, and get_ring()
added.is_valid()
, is_pentagon()
, is_rc3()
, get_base_cell()
, get_res()
, and to_polygon()
.are_neighbours.Rd
This function checks whether two H3 cells share an edge.
-Character; 15-character cell index generated by H3. A vector of -indexes can also be supplied.
Character; 15-character cell index generated by H3. A vector -of indexes can also be supplied.
Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.
cell_area.Rd
This function calculates the exact area of an H3 cell.
-cell_area(h3_address = NULL, units = c("m2", "km2", "rads2"), simple = TRUE)
compact.Rd
This function compacts a set of cells of the same resolution into a set of -cells across multiple resolutions that represents the same area.
-Character vector or list of 15-character indices
-generated by H3 at a single resolution, generally the output of
-polygon_to_cells
.
Logical; whether to return a vector of outputs or a list object -containing both inputs and outputs.
A list of H3 cells with multiple resolutions. The minimum - resolution of the output list matches the resolution of the input list.
-if (FALSE) {
-# Give me a compacted representation of County Ashe, NC
-nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
-nc1 <- nc[1, ]
-nc1 <- sf::st_cast(nc1, 'POLYGON')
-fillers <- polygon_to_cells(geometry = nc1, res = 6)
-compacted <- compact(fillers)
-}
-
edge_length.Rd
This function calculates the exact length of an H3 cell edge.
-edge_length(h3_edge = NULL, units = c("m", "km", "rads"), simple = TRUE)
get_base_cell.Rd
This function returns the number of the base (Level 1) cell for an H3 -cell idnex.
-get_centerchild.Rd
This function returns the central child of a particular H3 cell index at the -requested resolution.
-Character; 15-character index generated by H3.
Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.
Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.
get_children.Rd
This function returns the children of a particular H3 cell at the -requested resolution.
-Character; 15-character index generated by H3.
Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.
Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.
By default, a list of length(h3_address)
. Each list element contains
- a vector of H3 cell indexes.
The number of cells returned for each request is 7 ^ (parent_res -
- child_res)
, so jumping three levels will return 343 indexes per request.
- This can cause memory issues with larger requests.
# What are the children of this resolution 6 cell index at resolution 8?
-get_children(h3_address = '86be8d12fffffff', res = 8)
-#> [[1]]
-#> [1] "88be8d1281fffff" "88be8d1283fffff" "88be8d1285fffff" "88be8d1287fffff"
-#> [5] "88be8d1289fffff" "88be8d128bfffff" "88be8d128dfffff" "88be8d1291fffff"
-#> [9] "88be8d1293fffff" "88be8d1295fffff" "88be8d1297fffff" "88be8d1299fffff"
-#> [13] "88be8d129bfffff" "88be8d129dfffff" "88be8d12a1fffff" "88be8d12a3fffff"
-#> [17] "88be8d12a5fffff" "88be8d12a7fffff" "88be8d12a9fffff" "88be8d12abfffff"
-#> [21] "88be8d12adfffff" "88be8d12b1fffff" "88be8d12b3fffff" "88be8d12b5fffff"
-#> [25] "88be8d12b7fffff" "88be8d12b9fffff" "88be8d12bbfffff" "88be8d12bdfffff"
-#> [29] "88be8d12c1fffff" "88be8d12c3fffff" "88be8d12c5fffff" "88be8d12c7fffff"
-#> [33] "88be8d12c9fffff" "88be8d12cbfffff" "88be8d12cdfffff" "88be8d12d1fffff"
-#> [37] "88be8d12d3fffff" "88be8d12d5fffff" "88be8d12d7fffff" "88be8d12d9fffff"
-#> [41] "88be8d12dbfffff" "88be8d12ddfffff" "88be8d12e1fffff" "88be8d12e3fffff"
-#> [45] "88be8d12e5fffff" "88be8d12e7fffff" "88be8d12e9fffff" "88be8d12ebfffff"
-#> [49] "88be8d12edfffff"
-#>
-
get_faces.Rd
This function returns the indices of all icosahedron faces intersected by a -given H3 cell index.
-Character; 15-character index generated by H3.
Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.
get_gcdist.Rd
Get the great circle distance between WGS84 lat/long points
-get_gcdist(pt1 = NULL, pt2 = NULL, units = c("m", "km", "rads"), simple = TRUE)
`sf` object with point geometry, `sfc_POINT` object, `sfg` -point, data frame or matrix.
`sf` object with point geometry, `sfc_POINT` object, `sfg` -point, data frame or matrix.
whether to return the great circle distance in meters, -kilometers, or radians.
whether to return a numeric vector of distances or a -`data.frame` containing start and end coordinates as well as distance.
Numeric vector of point to point distances, or data frame of origin - and destination coordinates accompanied by their distances.
-get_local_ij.Rd
This function defines local i, j coordinates for an H3 destination cell -relative to an H3 origin cell.
-Character; 15-character cell index generated by H3. A vector of -indexes can also be supplied.
Character; 15-character cell index generated by H3. A -vector of indexes can also be supplied.
Logical; whether to include an unprojected sfc_POINT geometry -column in the output object.
If simple = TRUE
, a matrix where each row contains the local
- i, j coordinates for the supplied destination indexes. If not, an sf
object with origin and destination attributes, point geometry of the - destination cell centers, and an undefined coordinate reference system.
-The number of indexes supplied to origin and destination must be -equal.
The coordinate space used by this function may have deleted regions - or warping due to pentagonal distortion.
Coordinates are only comparable if they come from the same origin - index.
Failure may occur if the index is too far away from the origin or if - the index is on the other side of a pentagon.
This function is experimental, and its output is not guaranteed to be - compatible across different versions of H3.
# Get local coordinates for a nearby cell
-get_local_ij(origin = '86be8d12fffffff', destination = '86be8d127ffffff')
-#> i j
-#> 1 -87 36
-
-# Get local coordinates for a donut of nearby cells
-destinations <- get_ring(h3_address = '86be8d12fffffff', ring_size = 2)
-local_coords <- get_local_ij(origin = rep('86be8d12fffffff', length(destinations[[1]])),
- destination = destinations[[1]],
- simple = FALSE)
-
-plot(local_coords['destination'], pch = 19) # note origin is (0,0)
-
-
-
get_parent.Rd
This function returns the parent of a particular H3 cell index at the requested -resolution.
-Character; 15-character index generated by H3.
Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.
Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.
get_pentagons.Rd
This function returns the indices of all pentagons occurring at a -given H3 resolution.
-Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.
Logical; whether to return outputs as list of outputs (TRUE) or -data frame with both inputs and outputs.
By default, a list of length(h3_address)
. Each list element
- contains a vector of twelve H3 addresses. If simple = FALSE
, a data
- frame with a column of input resolutions and a list-column of pentagon
- indexes for each.
# Which indexes are pentagons at resolution 7?
-get_pentagons(res = 7)
-#> [[1]]
-#> [1] "870800000ffffff" "871c00000ffffff" "873000000ffffff" "874c00000ffffff"
-#> [5] "876200000ffffff" "877400000ffffff" "877e00000ffffff" "879000000ffffff"
-#> [9] "87a600000ffffff" "87c200000ffffff" "87d600000ffffff" "87ea00000ffffff"
-#>
-
get_res.Rd
This function returns an H3 cell index's resolution level.
-get_res0.Rd
Get all H3 cell indexes at resolution 0.
-As every index at every resolution > 0 is
-the descendant of a res 0 index, this can be used with
-get_children
to iterate over H3 indexes at
-any resolution.
res0 <- get_res0()
-cell_area(res0[1], 'km2')
-#> [1] 4106166
-
get_ring.Rd
This function returns all the H3 cell indexes at the specified step from the -address supplied.
-Character; 15-character cell index generated by H3.
Character; number of steps away from the central cell. -Defaults to 1.
Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.
By default, a list of length(h3_address)
. Each list element
- contains a character vector of H3 cells belonging to that step away from
- the input address.
In total, the number of cells returned for each input index is
- ring_size * 6
. This function will throw an error if there is a
- pentagon anywhere in the ring.
# What are the neighbours of this cell at step 2?
-get_ring(h3_address = '86be8d12fffffff', ring_size = 2)
-#> [[1]]
-#> [1] "86be8d8f7ffffff" "86be8d88fffffff" "86be8d89fffffff" "86be8d137ffffff"
-#> [5] "86be8d117ffffff" "86be8d11fffffff" "86be8d027ffffff" "86be8d157ffffff"
-#> [9] "86be8d147ffffff" "86be8d167ffffff" "86be8d8cfffffff" "86be8d8c7ffffff"
-#>
-
get_uddest.Rd
Get an H3 index representing the destination of a directed edge.
-get_udedge.Rd
Returns an H3 index representing a unidirectional edge for a given origin and -destination cell pair.
-Character; 15-character cell index generated by H3. A vector of -indexes can also be supplied.
Character; 15-character cell index generated by H3. A vector -of indexes can also be supplied.
Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.
get_udedges.Rd
Get all directed edge indexes for a given H3 cell index.
-Character; 15-character index generated by H3.
Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.
get_udends.Rd
Get H3 cell indexes representing the origin and destination of a directed -edge index.
-get_udorigin.Rd
Get an H3 cell index representing the origin of a directed edge.
-grid_distance.Rd
This function gets the grid distance between two H3 cell indices.
-Character vector or list of 15-character indices generated by -H3.
Character vector or list of 15-character indices -generated by H3.
Logical; whether to return a vector of outputs or a list object -containing both inputs and outputs.
The distance between two H3 cells, expressed as the minimum - number of hexagon 'steps' required to get from the origin to the - destination. Thus, a neighbour cell is one step away, and two cells - with one hexagon between them are two steps apart.
-Input H3 indices must be of the same resolution or results cannot be - computed. This function may fail to find the distance between two indices - if they are very far apart or on opposite sides of a pentagon.
-if (FALSE) {
-nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
-nc_pts <- sf::st_centroid(nc[c(1, 2), ])
-nc_6 <- point_to_cell(nc_pts, res = 6)
-# how far apart are these two addresses?
-grid_distance(nc_6[1], nc_6[2])
-}
-
grid_path.Rd
This function returns a path of H3 cells between a start and end cell -(inclusive).
-Character vector or list of 15-character indices generated by -H3.
Character vector or list of 15-character indices -generated by H3.
Logical; whether to return a vector of outputs or a list object -containing both inputs and outputs.
Input H3 cells must be of the same resolution or results cannot - be computed. This function may fail to find the distance between two - indexes if they are very far apart or on opposite sides of a pentagon.
The specific output of this function should not be considered stable
- across library versions. The only guarantees the library provides are that
- the line length will be h3_distance(start, end) + 1
and that every
- index in the line will be a neighbor of the preceding index.
Lines are drawn in grid space, and may not correspond exactly to - either Cartesian lines or great arcs
if (FALSE) {
-nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
-nc_pts <- sf::st_centroid(nc[c(1, 2), ])
-nc_6 <- point_to_cell(nc_pts, res = 6)
-# find a path between these two addresses:
-grid_path(nc_6[1], nc_6[2], simple = TRUE)
-
-}
-
h3_info_table.Rd
A dataset containing information about h3 cell indexes at each resolution, -calculated using H3's built-in functions.
-A data frame with 16 rows and 6 variables:
H3 resolution index number
Average area of an H3 cell index at the given - resolution, in square meters.
Average area of an - H3 cell index at the given resolution, in square kilometers.
Average edge length of an H3 cell index at the given - resolution, in meters.
Average edge length of an H3 - cell index at the given resolution, in kilometers.
Average distance between cell centers at the given - resolution, in meters.
Average distance between cellcenters at the given - resolution, in kilometers.
Total number of H3 cells at the given - resolution.
h3jsr-package.Rd
This package uses package V8 to access the -javascript bindings for Uber's H3 library
-Maintainer: Lauren O'Brien obrlsoilau@gmail.com (ORCID)
-are_neighbours()
- cells_to_multipolygon()
- cell_area()
- cell_to_line()
- cell_to_point()
- cell_to_polygon()
- cell_to_splitlong()
- compact()
- degs_to_rads()
- edge_length()
- get_base_cell()
- get_cell_vertex()
- get_cell_vertexes()
- get_centerchild()
- get_children()
- get_disk()
- get_disk_list()
- get_faces()
- get_gcdist()
- get_local_cell()
- get_local_ij()
- get_parent()
- get_pentagons()
- get_res()
- get_res0()
- get_ring()
- get_uddest()
- get_udedge()
- get_udedges()
- get_udends()
- get_udorigin()
- grid_distance()
- grid_path()
- h3jsr
h3jsr-package
- h3_info_table
- is_pentagon()
- is_rc3()
- is_valid()
- is_valid_edge()
- is_valid_vertex()
- num_cells()
- point_to_cell()
- polygon_to_cells()
- rads_to_degs()
- res_area()
- res_cendist()
- res_length()
- splitlong_to_cell()
- udedge_to_line()
- uncompact()
- vertex_to_point()
- is_pentagon.Rd
This function checks whether a H3 cell index refers to one of the pentagons -that occur at icosahedron corners.
-is_rc3.Rd
This function checks whether a H3 cell index is in a Class III resolution -(rotated versus the icosahedron and subject to shape distortion adding extra -points on icosahedron edges).
-is_valid.Rd
This function checks whether an H3 cell index is valid.
-is_valid_edge.Rd
This function checks whether an H3 unidirectional edge index is valid.
-prep_for_polyfill.Rd
Converts a variety of possible input geometries to geojson for
-h3jsr::polygon_to_cells()
.
res_area.Rd
This function returns the average area of an H3 cell at a given -resolution.
-res_area(res = NULL, units = c("m2", "km2"), fast = TRUE)
Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.
Areal unit to report in. Options are square meters or square -kilometers.
Logical; whether to retrieve values from a locally stored table or -reclaculate from source.
# Return average H3 cell area at each resolution in square meters
-res_area(res = seq(0, 15), units = 'm2')
-#> [1] 4.357449e+12 6.097884e+11 8.680178e+10 1.239343e+10 1.770348e+09
-#> [6] 2.529039e+08 3.612906e+07 5.161293e+06 7.373276e+05 1.053325e+05
-#> [11] 1.504750e+04 2.149643e+03 3.070919e+02 4.387027e+01 6.267181e+00
-#> [16] 8.953116e-01
-
-
res_cendist.Rd
This function returns the average distance between the center of H3 cells - at a given resolution.
-res_cendist(res = NULL, units = c("m", "km"), fast = TRUE)
Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.
Length unit to report in, either meters or kilometers.
Logical; whether to retrieve values from a locally stored table or -recalculate from source.
# Return average H3 cell separation distance at each resolution in kilometers
-res_cendist(res = seq(0, 15), units = 'km')
-#> [1] 1.918614e+03 7.251681e+02 2.740878e+02 1.035954e+02 3.915540e+01
-#> [6] 1.479935e+01 5.593628e+00 2.114193e+00 7.990898e-01 3.020275e-01
-#> [11] 1.141557e-01 4.314636e-02 1.630817e-02 6.165916e-03 2.335800e-03
-#> [16] 8.828488e-04
-
-
res_length.Rd
This function returns the average edge length of an H3 cell edge at a given -resolution.
-res_length(res = NULL, units = c("m", "km"), fast = TRUE)
Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.
Length unit to report in. Options are meters or kilometers.
Logical; whether to retrieve values from a locally stored table -or recalculate from source.
# Return average H3 cell edge length at each resolution in kilometers
-res_length(res = seq(0, 15), units = 'km')
-#> [1] 1.107713e+03 4.186760e+02 1.582447e+02 5.981086e+01 2.260638e+01
-#> [6] 8.544408e+00 3.229483e+00 1.220630e+00 4.613547e-01 1.743757e-01
-#> [11] 6.590781e-02 2.491056e-02 9.415526e-03 3.559893e-03 1.348575e-03
-#> [16] 5.097130e-04
-
-
udedge_to_line.Rd
This function takes an H3 unidirectional edge address and returns the -coordinates of its geometry in WGS84.
-Character; address of unidirectional edge.
Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.
# get me the shape of this edge
-udedge_to_line(h3_edge = '166be8d12fffffff')
-#> Geometry set for 1 feature
-#> Geometry type: LINESTRING
-#> Dimension: XY
-#> Bounding box: xmin: 153.039 ymin: -27.51385 xmax: 153.0433 ymax: -27.47774
-#> Geodetic CRS: WGS 84
-#> LINESTRING (153.039 -27.51385, 153.0433 -27.47774)
-
-
uncompact.Rd
This function uncompacts a compacted set of H3 cells to indices of the -target resolution.
-Character vector or list of 15-character cell indices -generated by H3.
Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.
Logical; whether to return a vector of outputs or a list object -containing both inputs and outputs.
if (FALSE) {
-# Give me a compacted representation of County Ashe, NC
-nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
-nc1 <- nc[1, ]
-nc1 <- sf::st_cast(nc1, 'POLYGON')
-fillers <- polygon_to_cells(geometry = nc1, res = 6)
-compacted <- compact(fillers)
-# uncompact to resolution 7
-uncompacted <- uncompact(compacted, res = 7)
-}
-