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 @@ - - - - - - - -Page not found (404) • h3jsr - - - - - - - - - - Skip to contents - - -
-
-
- -Content not found. Please use links in the navbar. - -
-
- - - -
- - - - - - - diff --git a/docs/LICENSE.html b/docs/LICENSE.html deleted file mode 100644 index 79fb1dc..0000000 --- a/docs/LICENSE.html +++ /dev/null @@ -1,152 +0,0 @@ - -Apache License • h3jsr - Skip to contents - - -
-
-
- -
- -

Version 2.0, January 2004 <http://www.apache.org/licenses/>

-
-

Terms and Conditions for use, reproduction, and distribution

-
-

1. Definitions

-

“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.

-
-
-

3. Grant of Patent License

-

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.

-
-
-

4. Redistribution

-

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:

-
  • -(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
  • -
  • -(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
  • -
  • -(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
  • -
  • -(d) If the Work includes a “NOTICE” text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
  • -

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.

-
-
-

5. Submission of Contributions

-

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.

-
-
-

6. Trademarks

-

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.

-
-
-

7. Disclaimer of Warranty

-

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.

-
-
-

8. Limitation of Liability

-

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.

-
-
-

9. Accepting Warranty or Additional Liability

-

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

-
-
-
-

APPENDIX: How to apply the Apache License to your work

-

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.

-
Copyright 2021 Lauren O'Brien
-
-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.
-
-
- -
- - -
- - - - - - - diff --git a/docs/articles/index.html b/docs/articles/index.html deleted file mode 100644 index 5e82004..0000000 --- a/docs/articles/index.html +++ /dev/null @@ -1,77 +0,0 @@ - -Articles • h3jsr - Skip to contents - - -
-
-
- -
-

All vignettes

-

- -
Introduction to h3jsr
-
-
-
- - -
- - - - - - - diff --git a/docs/articles/intro-to-h3jsr.html b/docs/articles/intro-to-h3jsr.html deleted file mode 100644 index fdd4330..0000000 --- a/docs/articles/intro-to-h3jsr.html +++ /dev/null @@ -1,642 +0,0 @@ - - - - - - - - -Introduction to h3jsr • h3jsr - - - - - - - - - - - Skip to contents - - -
- - - - -
-
- - - -
-local_options <- options()
-library(sf)
-library(dplyr)
-library(ggplot2)
-library(h3jsr)
-# for R < 4, since H3 addresses are handled as strings
-options(stringsAsFactors = FALSE)
-
-

General information -

-

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.

-
    -
  • Documentation for the core H3 library is at H3’s github page.
  • -
  • The core library only understands WGS84 coordinates, so multiple -projection support is limited. All spatial objects are returned in -WGS84, and ideally should be supplied as such. It’s always safer to do -your own spatial transformations and verify the results. If spatial data -in a coordinate system other than WGS84 is supplied, it is transformed -using sf::st_transform() and a message is issued.
  • -
  • For each function in 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.
  • -
  • This package uses 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!
  • -
-
-
-

Core Functions -

-

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
-
-
-

Neighbour Algorithms -

-

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()
-

-
-
-

Unidirectional edges -

-

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()
-

-
-
-

Vertexes -

-

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()
-

-
-
-

Local coordinates -

-

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"
-
-
-

Distance and Direction -

-

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()
-

-
-
-

Info utilities -

-

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
-
-
-

Conversion utilities -

-

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)
-
-
-
-
- - - - -
- - - - - - - diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/c4-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/c4-1.png deleted file mode 100644 index 5de04c5..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/c4-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/cc-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/cc-1.png deleted file mode 100644 index 9715f4a..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/cc-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/compact-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/compact-1.png deleted file mode 100644 index 4c79a1c..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/compact-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/coolplot-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/coolplot-1.png deleted file mode 100644 index 7ad1665..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/coolplot-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/coolplot-2.png b/docs/articles/intro-to-h3jsr_files/figure-html/coolplot-2.png deleted file mode 100644 index d694cfa..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/coolplot-2.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/edges-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/edges-1.png deleted file mode 100644 index 71b86f9..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/edges-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/fam-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/fam-1.png deleted file mode 100644 index 9135f2c..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/fam-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/h3l-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/h3l-1.png deleted file mode 100644 index 3d8e714..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/h3l-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/ispent-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/ispent-1.png deleted file mode 100644 index 4b33800..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/ispent-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/neigbs-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/neigbs-1.png deleted file mode 100644 index b9cc274..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/neigbs-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/pf-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/pf-1.png deleted file mode 100644 index 48195a2..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/pf-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/stmp-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/stmp-1.png deleted file mode 100644 index c5c7fe9..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/stmp-1.png and /dev/null differ diff --git a/docs/articles/intro-to-h3jsr_files/figure-html/unc-1.png b/docs/articles/intro-to-h3jsr_files/figure-html/unc-1.png deleted file mode 100644 index 2cb3b47..0000000 Binary files a/docs/articles/intro-to-h3jsr_files/figure-html/unc-1.png and /dev/null differ diff --git a/docs/authors.html b/docs/authors.html deleted file mode 100644 index 8511516..0000000 --- a/docs/authors.html +++ /dev/null @@ -1,96 +0,0 @@ - -Authors and Citation • h3jsr - Skip to contents - - -
-
-
- -
-

Authors

- -
  • -

    Lauren O'Brien. Author, maintainer. -

    -
  • -
- -
-

Citation

-

- -

O'Brien L (2022). -h3jsr: Access Uber's H3 Library. -R package version 1.3.0, https://obrl-soil.github.io/h3jsr/. -

-
@Manual{,
-  title = {h3jsr: Access Uber's H3 Library},
-  author = {Lauren O'Brien},
-  year = {2022},
-  note = {R package version 1.3.0},
-  url = {https://obrl-soil.github.io/h3jsr/},
-}
-
-
- - -
- - - - - - - diff --git a/docs/extra.css b/docs/extra.css deleted file mode 100644 index 9d3f23a..0000000 --- a/docs/extra.css +++ /dev/null @@ -1,72 +0,0 @@ -/* general */ - -a { - color: #041725; - text-decoration: none; -} - -a:active { - color: #041725; - text-decoration: underline; -} - -a:hover { - color: #041725; - text-decoration: underline; -} - -/* navbar mods */ - -.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:focus, .navbar-default .navbar-nav > .active > a:hover { - color: #ededed; - background-color: #041725; -} - -.navbar-default .navbar-collapse, .navbar-default .navbar-form { - border-color: #041725; -} - -.navbar-default .navbar-link { - color: #ededed; - font-weight: bold -} - -.navbar-default .navbar-brand { - color: #ededed; -} - -.navbar-default { - background-color: #041725; - border-color: #041725; -} - -.navbar-default .navbar-nav > li > a { - color: #ededed; - font-weight: bold -} - -.fa-lg { - font-size: 1.33333333em; - line-height: .75em; - vertical-align: -15%; - color: #ededed; -} - -.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus { - background-color: #041725; - color: #ededed; -} - -/* rhs pillbox mods */ - -.nav-pills > li > a { - border-radius: 4px; - font-weight: bold -} - -.nav-pills > li.active > a, .nav-pills > li.active > a:focus, .nav-pills > li.active > a:hover { - color: #ededed; - background-color: #041725; - font-weight: bold -} - diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index 396aea1..0000000 --- a/docs/index.html +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - -Access Uber's H3 Library • h3jsr - - - - - - - - - - - Skip to contents - - -
-
-
-
- -

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.

-
-

Installation -

-

Install from CRAN with

- -

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.

-
-
-
-

Example -

-
-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.

-
-
-
- -
-
- - - -
- - - - - - - diff --git a/docs/link.svg b/docs/link.svg deleted file mode 100644 index 88ad827..0000000 --- a/docs/link.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/docs/news/index.html b/docs/news/index.html deleted file mode 100644 index 9c3588f..0000000 --- a/docs/news/index.html +++ /dev/null @@ -1,266 +0,0 @@ - -Changelog • h3jsr - Skip to contents - - -
-
-
- -
-

Version 1.3

-
-
-

Version 1.2.3 [CRAN]

CRAN release: 2022-01-04

-
  • Updated V8 version requirement to ensure consistent build across platforms
  • -
-
-

Version 1.2.2 [CRAN]

CRAN release: 2021-06-17

-
  • Updated to h3-js 3.7.2
  • -
-
-

Version 1.2.1

-
  • Updated to h3-js 3.7.1
  • -
-
-

Version 1.2.0

-
  • Updated to h3-js 3.7.0
  • -
  • Added functions cell_area, edge_length, get_dist, and get_res0.
  • -
  • Revised internal function prep_for_pt2h3 -
  • -
-
-

Version 1.1.3

-
  • Updated to h3-js 3.6.4
  • -
-
-

Version 1.1.2

-
  • Updated to h3-js 3.6.3 - polyfill algo was rolled back due to known issues
  • -
  • Move to Github Actions for CI workflow
  • -
  • Remove unneeded lwgeom dependency
  • -
  • Bugfix for accessing h3_info_table when library not loaded explicitly
  • -
-
-

Version 1.1.1

-
  • Updated to h3-js 3.6.2 - expect improvements to polyfill() behaviour
  • -
-
-

Version 1.1

-
  • Updated to h3-js 3.6.1
  • -
  • Added get_centerchild(), which will return the central child of a hexagon at a given resolution.
  • -
  • Added get_pentagons(), which will return the twelve pentagon indexes at a given resolution.
  • -
-
-

Version 1.0

-
  • Updated to h3-js 3.5.0, now using official browser bundle
  • -
  • Added get_faces(), which returns the icosahedron face(s) for a given H3 address.
  • -
-
-

Version 0.9

-
  • Updated to h3-js 3.4.2
  • -
  • Replaced custom function min_path() with official version grid_path(), which wraps h3Line to find a path between two addresses.
  • -
  • Added custom function h3_to_line(), which converts a vector of H3 addresses to sfc_LINESTRING.
  • -
-
-

Version 0.8

-
  • Updated to h3-js 3.3.0 and babel-polyfill 6.26.0
  • -
-
-

Version 0.7

-
  • Removed nearest_neighbour(), its fundamentally flawed.
  • -
  • Simplified output of get_local_ij() to a matrix when simple = TRUE
  • -
  • Improved outputs from h3_to_point() -
  • -
  • Efficiency improvements to h3_to_point() and polyfill() -
  • -
  • -h3_to_point(), h3_to_polygon(), and polyfill() now take a wider range of input objects.
  • -
-
-

Version 0.6

-
  • Update core library to v 3.2.0
  • -
  • Add get_local_ij() and get_local_h3(), wrapping the experimental local coordinate system functions h3.experimentalH3ToLocalIj and h3.experimentalLocalIjToH3 respectively.
  • -
-
-

Version 0.5.1

-
  • Added custom function min_path() to find a minimum-steps path between two H3 addresses of the same resolution.
  • -
  • Added custom function nearest_neighbour() to find the nearest neighbour for a given set of points. Use with caution, read the notes.
  • -
-
-

Version 0.5.0

-
  • change to v8 session handling (speed enhancement)
  • -
-
-

Version 0.4.5

-
  • update core library to v 3.1.1
  • -
-
-

Version 0.4.4

-
  • bugfix for 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.
  • -
-
-

Version 0.4.3

-
-
-

Version 0.4.2

-
-
-

Version 0.4.1

-
  • Warnings converted to messages
  • -
  • Multipolygon support for h3_polyfill(), plus a message when output resolution is way smaller than input extent.
  • -
-
-

Version 0.4.0

-
  • Naming things is hard, but its vignette time so, y’know, now or never. Function names are shorter now and make more sense.
  • -
  • Added another info utility res_cendist() for getting the average distance between the center of each region represented by a H3 address at a given resolution.
  • -
  • Vignette covering core functionality added.
  • -
-
-

Version 0.3.1

-
  • Reworked to_point() to return an sfc_POINT object, or an sf point data frame where simple = FALSE.
  • -
  • Improved outputs of to_polygon() to have a similar structure to h3_to_geo().
  • -
-
-

Version 0.3.0

-
  • Reworked 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.
  • -
-
-

Version 0.2.3

-
  • Added public informational utilities res_area(), res_edgelen(), and res_count() -
  • -
  • Added data table of h3 address info for fast retrieval of information using the above functions
  • -
  • Fixed resolution validation bug, level 0 is now allowed
  • -
-
-

Version 0.2.1

-
  • -polyfill() and set_to_multipolygon() added; new dependencies on sfand geojsonsf have resulted.
  • -
  • -to_polygon() now returns an object with sf geometry.
  • -
  • -compact() and uncompact() added, all public core algorithms now available.
  • -
-
-

Version 0.1.3

-
-
-

Version 0.1.2

-
-
-

Version 0.1.1

-
  • -to_point() added.
  • -
  • -point_to_h3() bugfix. A pox on devs who think y,x is ok.
  • -
  • NEWS and README added.
  • -
-
-

Version 0.1.0

-
  • -point_to_h3() - first function implemented.
  • -
-
- - -
- - - - - - - diff --git a/docs/pkgdown.js b/docs/pkgdown.js deleted file mode 100644 index 5fccd9c..0000000 --- a/docs/pkgdown.js +++ /dev/null @@ -1,156 +0,0 @@ -/* http://gregfranko.com/blog/jquery-best-practices/ */ -(function($) { - $(function() { - - $('nav.navbar').headroom(); - - Toc.init({ - $nav: $("#toc"), - $scope: $("main h2, main h3, main h4, main h5, main h6") - }); - - if ($('#toc').length) { - $('body').scrollspy({ - target: '#toc', - offset: $("nav.navbar").outerHeight() + 1 - }); - } - - // Activate popovers - $('[data-bs-toggle="popover"]').popover({ - container: 'body', - html: true, - trigger: 'focus', - placement: "top", - sanitize: false, - }); - - $('[data-bs-toggle="tooltip"]').tooltip(); - - /* Clipboard --------------------------*/ - - function changeTooltipMessage(element, msg) { - var tooltipOriginalTitle=element.getAttribute('data-original-title'); - element.setAttribute('data-original-title', msg); - $(element).tooltip('show'); - element.setAttribute('data-original-title', tooltipOriginalTitle); - } - - if(ClipboardJS.isSupported()) { - $(document).ready(function() { - var copyButton = ""; - - $("div.sourceCode").addClass("hasCopyButton"); - - // Insert copy buttons: - $(copyButton).prependTo(".hasCopyButton"); - - // Initialize tooltips: - $('.btn-copy-ex').tooltip({container: 'body'}); - - // Initialize clipboard: - var clipboard = new ClipboardJS('[data-clipboard-copy]', { - text: function(trigger) { - return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); - } - }); - - clipboard.on('success', function(e) { - changeTooltipMessage(e.trigger, 'Copied!'); - e.clearSelection(); - }); - - clipboard.on('error', function() { - changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); - }); - - }); - } - - /* Search marking --------------------------*/ - var url = new URL(window.location.href); - var toMark = url.searchParams.get("q"); - var mark = new Mark("main#main"); - if (toMark) { - mark.mark(toMark, { - accuracy: { - value: "complementary", - limiters: [",", ".", ":", "/"], - } - }); - } - - /* Search --------------------------*/ - /* Adapted from https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/inst/resources/bs4_book/bs4_book.js#L25 */ - // Initialise search index on focus - var fuse; - $("#search-input").focus(async function(e) { - if (fuse) { - return; - } - - $(e.target).addClass("loading"); - var response = await fetch($("#search-input").data("search-index")); - var data = await response.json(); - - var options = { - keys: ["what", "text", "code"], - ignoreLocation: true, - threshold: 0.1, - includeMatches: true, - includeScore: true, - }; - fuse = new Fuse(data, options); - - $(e.target).removeClass("loading"); - }); - - // Use algolia autocomplete - var options = { - autoselect: true, - debug: true, - hint: false, - minLength: 2, - }; - var q; -async function searchFuse(query, callback) { - await fuse; - - var items; - if (!fuse) { - items = []; - } else { - q = query; - var results = fuse.search(query, { limit: 20 }); - items = results - .filter((x) => x.score <= 0.75) - .map((x) => x.item); - if (items.length === 0) { - items = [{dir:"Sorry 😿",previous_headings:"",title:"No results found.",what:"No results found.",path:window.location.href}]; - } - } - callback(items); -} - $("#search-input").autocomplete(options, [ - { - name: "content", - source: searchFuse, - templates: { - suggestion: (s) => { - if (s.title == s.what) { - return `${s.dir} >
${s.title}
`; - } else if (s.previous_headings == "") { - return `${s.dir} >
${s.title}
> ${s.what}`; - } else { - return `${s.dir} >
${s.title}
> ${s.previous_headings} > ${s.what}`; - } - }, - }, - }, - ]).on('autocomplete:selected', function(event, s) { - window.location.href = s.path + "?q=" + q + "#" + s.id; - }); - }); -})(window.jQuery || window.$) - - diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml deleted file mode 100644 index e73e8e9..0000000 --- a/docs/pkgdown.yml +++ /dev/null @@ -1,10 +0,0 @@ -pandoc: '2.18' -pkgdown: 2.0.6 -pkgdown_sha: ~ -articles: - intro-to-h3jsr: intro-to-h3jsr.html -last_built: 2022-09-26T08:31Z -urls: - reference: https://obrl-soil.github.io/h3jsr/reference - article: https://obrl-soil.github.io/h3jsr/articles - diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png deleted file mode 100644 index 17a3580..0000000 Binary files a/docs/reference/Rplot001.png and /dev/null differ diff --git a/docs/reference/are_neighbours.html b/docs/reference/are_neighbours.html deleted file mode 100644 index 083df26..0000000 --- a/docs/reference/are_neighbours.html +++ /dev/null @@ -1,122 +0,0 @@ - -check if H3 cells are neighbours — are_neighbours • h3jsr - Skip to contents - - -
-
-
- -
-

This function checks whether two H3 cells share an edge.

-
- -
-

Usage

-
are_neighbours(origin = NULL, destination = NULL, simple = TRUE)
-
- -
-

Arguments

-
origin
-

Character; 15-character cell index generated by H3. A vector of -indexes can also be supplied.

- - -
destination
-

Character; 15-character cell index generated by H3. A vector -of indexes can also be supplied.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

Logical; TRUE if neighbours.

-
-
-

Note

- -
  • The number of indexes supplied to origin and destination must be -equal.

  • -
  • This function will always return false if the indexes are of different -resolutions.

  • -
- -
-

Examples

-
# Are the following cells neighbours?
-are_neighbours(origin = '86be8d12fffffff', destination = '86be8d127ffffff')
-#> [1] TRUE
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/cell_area.html b/docs/reference/cell_area.html deleted file mode 100644 index 0a21334..0000000 --- a/docs/reference/cell_area.html +++ /dev/null @@ -1,111 +0,0 @@ - -Get exact cell area — cell_area • h3jsr - Skip to contents - - -
-
-
- -
-

This function calculates the exact area of an H3 cell.

-
- -
-

Usage

-
cell_area(h3_address = NULL, units = c("m2", "km2", "rads2"), simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
units
-

Length unit to report in. Options are square meters, square -kilometers, or steradians.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, a numeric vector of length(h3_address).

-
- -
-

Examples

-
cell_area(h3_address = '8abe8d12acaffff', 'm2')
-#> [1] 17753.9
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/compact.html b/docs/reference/compact.html deleted file mode 100644 index 44bcf31..0000000 --- a/docs/reference/compact.html +++ /dev/null @@ -1,118 +0,0 @@ - -Compact H3 cells — compact • h3jsr - Skip to contents - - -
-
-
- -
-

This function compacts a set of cells of the same resolution into a set of -cells across multiple resolutions that represents the same area.

-
- -
-

Usage

-
compact(h3_addresses = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_addresses
-

Character vector or list of 15-character indices -generated by H3 at a single resolution, generally the output of -polygon_to_cells.

- - -
simple
-

Logical; whether to return a vector of outputs or a list object -containing both inputs and outputs.

- -
-
-

Value

- - -

A list of H3 cells with multiple resolutions. The minimum - resolution of the output list matches the resolution of the input list.

-
- -
-

Examples

-
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)
-}
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/edge_length.html b/docs/reference/edge_length.html deleted file mode 100644 index 5fcc217..0000000 --- a/docs/reference/edge_length.html +++ /dev/null @@ -1,111 +0,0 @@ - -Get exact cell edge length — edge_length • h3jsr - Skip to contents - - -
-
-
- -
-

This function calculates the exact length of an H3 cell edge.

-
- -
-

Usage

-
edge_length(h3_edge = NULL, units = c("m", "km", "rads"), simple = TRUE)
-
- -
-

Arguments

-
h3_edge
-

Character; address of unidirectional edge.

- - -
units
-

Length unit to report in. Options are meters, kilometers, or -radians.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, a numeric vector of length(h3_address).

-
- -
-

Examples

-
edge_length(h3_edge = '166be8d12fffffff', 'm')
-#> [1] 4037.687
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_base_cell.html b/docs/reference/get_base_cell.html deleted file mode 100644 index c1f5198..0000000 --- a/docs/reference/get_base_cell.html +++ /dev/null @@ -1,111 +0,0 @@ - -get the base cell of an H3 cell index — get_base_cell • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns the number of the base (Level 1) cell for an H3 -cell idnex.

-
- -
-

Usage

-
get_base_cell(h3_address = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, an integer vector of length(h3_address), ranging from - 0 to 121.

-
- -
-

Examples

-
# What is Brisbane Town Hall's base cell number?
-get_base_cell(h3_address = '8abe8d12acaffff')
-#> [1] 95
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_centerchild.html b/docs/reference/get_centerchild.html deleted file mode 100644 index 5fb43e0..0000000 --- a/docs/reference/get_centerchild.html +++ /dev/null @@ -1,116 +0,0 @@ - -get central child H3 cell index — get_centerchild • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns the central child of a particular H3 cell index at the -requested resolution.

-
- -
-

Usage

-
get_centerchild(h3_address = NULL, res = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
res
-

Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, a list of length(h3_address). Each list element contains - a vector of H3 cells.

-
- -
-

Examples

-
# What is the central child of this resolution 6 index at resolution 8?
-get_centerchild(h3_address = '86be8d12fffffff', res = 8)
-#> [1] "88be8d1281fffff"
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_children.html b/docs/reference/get_children.html deleted file mode 100644 index 2f4f790..0000000 --- a/docs/reference/get_children.html +++ /dev/null @@ -1,136 +0,0 @@ - -get child H3 cell indices — get_children • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns the children of a particular H3 cell at the -requested resolution.

-
- -
-

Usage

-
get_children(h3_address = NULL, res = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
res
-

Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, a list of length(h3_address). Each list element contains - a vector of H3 cell indexes.

-
-
-

Note

-

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.

-
- -
-

Examples

-
# 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"
-#> 
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_faces.html b/docs/reference/get_faces.html deleted file mode 100644 index 2459d84..0000000 --- a/docs/reference/get_faces.html +++ /dev/null @@ -1,112 +0,0 @@ - -get the icosahedron faces of an H3 cell index — get_faces • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns the indices of all icosahedron faces intersected by a -given H3 cell index.

-
- -
-

Usage

-
get_faces(h3_address = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, an integer vector of length(h3_address), ranging - from 1 to 20. If simple = FALSE, a data.frame with a column of H3 - cell indexes and a list-column of faces.

-
- -
-

Examples

-
# Which faces does this h3 cell index intersect?
-get_faces(h3_address = '8abe8d12acaffff')
-#> [1] 15
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_gcdist.html b/docs/reference/get_gcdist.html deleted file mode 100644 index 1857de1..0000000 --- a/docs/reference/get_gcdist.html +++ /dev/null @@ -1,130 +0,0 @@ - -Great circle distance — get_gcdist • h3jsr - Skip to contents - - -
-
-
- -
-

Get the great circle distance between WGS84 lat/long points

-
- -
-

Usage

-
get_gcdist(pt1 = NULL, pt2 = NULL, units = c("m", "km", "rads"), simple = TRUE)
-
- -
-

Arguments

-
pt1
-

`sf` object with point geometry, `sfc_POINT` object, `sfg` -point, data frame or matrix.

- - -
pt2
-

`sf` object with point geometry, `sfc_POINT` object, `sfg` -point, data frame or matrix.

- - -
units
-

whether to return the great circle distance in meters, -kilometers, or radians.

- - -
simple
-

whether to return a numeric vector of distances or a -`data.frame` containing start and end coordinates as well as distance.

- -
-
-

Value

- - -

Numeric vector of point to point distances, or data frame of origin - and destination coordinates accompanied by their distances.

-
-
-

Note

-

This functionality also exists in R packages sp, sf, -geosphere and fields. H3's version appears to return slightly -shorter distances than most other implementations, but is included here -for completeness.

-
- -
-

Examples

-
# distance between Brisbane and Melbourne
-bne <- c(153.028, -27.468)
-mlb <- c(144.963, -37.814)
-get_gcdist(bne, mlb, 'km')
-#> Assuming positions 1 and 2 contain x, y coordinates in EPSG:4326
-#> Assuming positions 1 and 2 contain x, y coordinates in EPSG:4326
-#> [1] 1331.349
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_local_ij-1.png b/docs/reference/get_local_ij-1.png deleted file mode 100644 index 86fbe50..0000000 Binary files a/docs/reference/get_local_ij-1.png and /dev/null differ diff --git a/docs/reference/get_local_ij.html b/docs/reference/get_local_ij.html deleted file mode 100644 index f2a975e..0000000 --- a/docs/reference/get_local_ij.html +++ /dev/null @@ -1,146 +0,0 @@ - -Get local i, j coordinates — get_local_ij • h3jsr - Skip to contents - - -
-
-
- -
-

This function defines local i, j coordinates for an H3 destination cell -relative to an H3 origin cell.

-
- -
-

Usage

-
get_local_ij(origin = NULL, destination = NULL, simple = TRUE)
-
- -
-

Arguments

-
origin
-

Character; 15-character cell index generated by H3. A vector of -indexes can also be supplied.

- - -
destination
-

Character; 15-character cell index generated by H3. A -vector of indexes can also be supplied.

- - -
simple
-

Logical; whether to include an unprojected sfc_POINT geometry -column in the output object.

- -
-
-

Value

- - -

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.

-
-
-

Note

- -
  • 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.

  • -
- -
-

Examples

-
# 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)
-
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_parent.html b/docs/reference/get_parent.html deleted file mode 100644 index 9ad2520..0000000 --- a/docs/reference/get_parent.html +++ /dev/null @@ -1,115 +0,0 @@ - -get parent H3 cell index — get_parent • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns the parent of a particular H3 cell index at the requested -resolution.

-
- -
-

Usage

-
get_parent(h3_address = NULL, res = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
res
-

Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, a logical vector of length(h3_address).

-
- -
-

Examples

-
# What is the parent of this cell at resolution 6?
-get_parent(h3_address = '8abe8d12acaffff', res = 6)
-#> [1] "86be8d12fffffff"
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_pentagons.html b/docs/reference/get_pentagons.html deleted file mode 100644 index e6fdbfc..0000000 --- a/docs/reference/get_pentagons.html +++ /dev/null @@ -1,118 +0,0 @@ - -get the pentagon indices for an H3 resolution — get_pentagons • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns the indices of all pentagons occurring at a -given H3 resolution.

-
- -
-

Usage

-
get_pentagons(res = NULL, simple = TRUE)
-
- -
-

Arguments

-
res
-

Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.

- - -
simple
-

Logical; whether to return outputs as list of outputs (TRUE) or -data frame with both inputs and outputs.

- -
-
-

Value

- - -

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.

-
- -
-

Examples

-
# 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"
-#> 
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_res.html b/docs/reference/get_res.html deleted file mode 100644 index cec844e..0000000 --- a/docs/reference/get_res.html +++ /dev/null @@ -1,108 +0,0 @@ - -get the resolution of an H3 cell index — get_res • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns an H3 cell index's resolution level.

-
- -
-

Usage

-
get_res(h3_address = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, an integer vector of length(h3_address), ranging - from 1 to 15.

-
- -
-

Examples

-
# What is the resolution of this H3 cell index?
-get_res(h3_address = '8abe8d12acaffff')
-#> [1] 10
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_res0.html b/docs/reference/get_res0.html deleted file mode 100644 index 629c6c9..0000000 --- a/docs/reference/get_res0.html +++ /dev/null @@ -1,103 +0,0 @@ - -Get resolution 0 indexes — get_res0 • h3jsr - Skip to contents - - -
-
-
- -
-

Get all H3 cell indexes at resolution 0.

-
- -
-

Usage

-
get_res0()
-
- -
-

Value

- - -

length 122 character vector of top-level H3 cell indices.

-
-
-

Note

-

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.

-
- -
-

Examples

-
res0 <- get_res0()
-cell_area(res0[1], 'km2')
-#> [1] 4106166
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_ring.html b/docs/reference/get_ring.html deleted file mode 100644 index 981a7ad..0000000 --- a/docs/reference/get_ring.html +++ /dev/null @@ -1,127 +0,0 @@ - -Get a ring of H3 cell indexes — get_ring • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns all the H3 cell indexes at the specified step from the -address supplied.

-
- -
-

Usage

-
get_ring(h3_address = NULL, ring_size = 1, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character cell index generated by H3.

- - -
ring_size
-

Character; number of steps away from the central cell. -Defaults to 1.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

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.

-
-
-

Note

-

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.

-
- -
-

Examples

-
# 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"
-#> 
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_uddest.html b/docs/reference/get_uddest.html deleted file mode 100644 index 1c520c3..0000000 --- a/docs/reference/get_uddest.html +++ /dev/null @@ -1,108 +0,0 @@ - -Get destination cell from directed edge — get_uddest • h3jsr - Skip to contents - - -
-
-
- -
-

Get an H3 index representing the destination of a directed edge.

-
- -
-

Usage

-
get_uddest(h3_edge = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_edge
-

Character; address of unidirectional edge.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, character vector of h3 cell indexes.

-
- -
-

Examples

-
# Get the destination cell index of this directed edge index
-get_uddest(h3_edge = '166be8d12fffffff')
-#> [1] "86be8d127ffffff"
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_udedge.html b/docs/reference/get_udedge.html deleted file mode 100644 index 221c4b1..0000000 --- a/docs/reference/get_udedge.html +++ /dev/null @@ -1,122 +0,0 @@ - -Get a unidirectional edge index — get_udedge • h3jsr - Skip to contents - - -
-
-
- -
-

Returns an H3 index representing a unidirectional edge for a given origin and -destination cell pair.

-
- -
-

Usage

-
get_udedge(origin = NULL, destination = NULL, simple = TRUE)
-
- -
-

Arguments

-
origin
-

Character; 15-character cell index generated by H3. A vector of -indexes can also be supplied.

- - -
destination
-

Character; 15-character cell index generated by H3. A vector -of indexes can also be supplied.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, character vector of unidirectional edge indexes.

-
-
-

Note

-

The number of cell indexes supplied to origin and destination must be - equal.

-
- -
-

Examples

-
# Return the unidirectional edge representing the transition between these two cells:
-get_udedge(origin = '86be8d12fffffff', destination = '86be8d127ffffff')
-#> [1] "166be8d12fffffff"
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_udedges.html b/docs/reference/get_udedges.html deleted file mode 100644 index 5e65367..0000000 --- a/docs/reference/get_udedges.html +++ /dev/null @@ -1,112 +0,0 @@ - -Get all directed edge indexes for a given H3 cell — get_udedges • h3jsr - Skip to contents - - -
-
-
- -
-

Get all directed edge indexes for a given H3 cell index.

-
- -
-

Usage

-
get_udedges(h3_address = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, list of length(h3_address). Each list contains a - character vector of H3 edge indexes.

-
- -
-

Examples

-
# Get all the edge indexes for this cell
-get_udedges(h3_address = '86be8d12fffffff')
-#> [[1]]
-#> [1] "116be8d12fffffff" "126be8d12fffffff" "136be8d12fffffff" "146be8d12fffffff"
-#> [5] "156be8d12fffffff" "166be8d12fffffff"
-#> 
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_udends.html b/docs/reference/get_udends.html deleted file mode 100644 index e863fdb..0000000 --- a/docs/reference/get_udends.html +++ /dev/null @@ -1,113 +0,0 @@ - -Get origin and destination indexes of directed edge — get_udends • h3jsr - Skip to contents - - -
-
-
- -
-

Get H3 cell indexes representing the origin and destination of a directed -edge index.

-
- -
-

Usage

-
get_udends(h3_edge = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_edge
-

Character; address of unidirectional edge.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, character matrix of h3 cell indexes.

-
- -
-

Examples

-
# Get the origin and destination of this directed edge
-get_udends(h3_edge = '166be8d12fffffff')
-#> [[1]]
-#> [1] "86be8d12fffffff" "86be8d127ffffff"
-#> 
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/get_udorigin.html b/docs/reference/get_udorigin.html deleted file mode 100644 index 0ea5a73..0000000 --- a/docs/reference/get_udorigin.html +++ /dev/null @@ -1,108 +0,0 @@ - -Get origin cell index from directed edge — get_udorigin • h3jsr - Skip to contents - - -
-
-
- -
-

Get an H3 cell index representing the origin of a directed edge.

-
- -
-

Usage

-
get_udorigin(h3_edge = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_edge
-

Character; address of unidirectional edge.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, character vector of H3 indexes.

-
- -
-

Examples

-
# Get the origin cell of this directed edge
-get_udorigin(h3_edge = '166be8d12fffffff')
-#> [1] "86be8d12fffffff"
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/grid_distance.html b/docs/reference/grid_distance.html deleted file mode 100644 index 6847219..0000000 --- a/docs/reference/grid_distance.html +++ /dev/null @@ -1,126 +0,0 @@ - -Grid distance between H3 cells — grid_distance • h3jsr - Skip to contents - - -
-
-
- -
-

This function gets the grid distance between two H3 cell indices.

-
- -
-

Usage

-
grid_distance(origin = NULL, destination = NULL, simple = TRUE)
-
- -
-

Arguments

-
origin
-

Character vector or list of 15-character indices generated by -H3.

- - -
destination
-

Character vector or list of 15-character indices -generated by H3.

- - -
simple
-

Logical; whether to return a vector of outputs or a list object -containing both inputs and outputs.

- -
-
-

Value

- - -

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.

-
-
-

Note

-

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.

-
- -
-

Examples

-
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])
-}
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/grid_path.html b/docs/reference/grid_path.html deleted file mode 100644 index 2411247..0000000 --- a/docs/reference/grid_path.html +++ /dev/null @@ -1,134 +0,0 @@ - -Path between H3 cells — grid_path • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns a path of H3 cells between a start and end cell -(inclusive).

-
- -
-

Usage

-
grid_path(origin = NULL, destination = NULL, simple = TRUE)
-
- -
-

Arguments

-
origin
-

Character vector or list of 15-character indices generated by -H3.

- - -
destination
-

Character vector or list of 15-character indices -generated by H3.

- - -
simple
-

Logical; whether to return a vector of outputs or a list object -containing both inputs and outputs.

- -
-
-

Value

- - -

A vector of h3 cells of form c(origin, c(path), destination).

-
-
-

Note

- -
  • 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

  • -
- -
-

Examples

-
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)
-
-}
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/h3_info_table.html b/docs/reference/h3_info_table.html deleted file mode 100644 index 1a6e812..0000000 --- a/docs/reference/h3_info_table.html +++ /dev/null @@ -1,125 +0,0 @@ - -H3 index utility information table — h3_info_table • h3jsr - Skip to contents - - -
-
-
- -
-

A dataset containing information about h3 cell indexes at each resolution, -calculated using H3's built-in functions.

-
- -
-

Usage

-
h3_info_table
-
- -
-

Format

-

A data frame with 16 rows and 6 variables:

h3_resolution
-

H3 resolution index number

- -
avg_area_sqm
-

Average area of an H3 cell index at the given - resolution, in square meters.

- -
avg_area_sqkm
-

Average area of an - H3 cell index at the given resolution, in square kilometers.

- -
avg_edge_m
-

Average edge length of an H3 cell index at the given - resolution, in meters.

- -
avg_edge_km
-

Average edge length of an H3 - cell index at the given resolution, in kilometers.

- -
avg_cendist_m
-

Average distance between cell centers at the given - resolution, in meters.

- -
avg_cendist_km
-

Average distance between cellcenters at the given - resolution, in kilometers.

- -
total_unique_indexes
-

Total number of H3 cells at the given - resolution.

- -
- - -
- - -
- - - - - - - diff --git a/docs/reference/h3jsr-package.html b/docs/reference/h3jsr-package.html deleted file mode 100644 index 4bbc1e3..0000000 --- a/docs/reference/h3jsr-package.html +++ /dev/null @@ -1,91 +0,0 @@ - -h3jsr: Access Uber's H3 library — h3jsr-package • h3jsr - Skip to contents - - -
-
-
- -
-

This package uses package V8 to access the -javascript bindings for Uber's H3 library

-
- - -
-

See also

- -
-
-

Author

-

Maintainer: Lauren O'Brien obrlsoilau@gmail.com (ORCID)

-
- -
- - -
- - - - - - - diff --git a/docs/reference/index.html b/docs/reference/index.html deleted file mode 100644 index f7aa3a5..0000000 --- a/docs/reference/index.html +++ /dev/null @@ -1,337 +0,0 @@ - -Function reference • h3jsr - Skip to contents - - -
-
-
- -
-

All functions

- - - - -
- - - - -
- - are_neighbours() -
-
check if H3 cells are neighbours
-
- - cells_to_multipolygon() -
-
Get geometry for a set of H3 cells
-
- - cell_area() -
-
Get exact cell area
-
- - cell_to_line() -
-
Convert H3 cell indexes to a line
-
- - cell_to_point() -
-
Convert H3 cell index to point location
-
- - cell_to_polygon() -
-
Get the boundary of an H3 cell index
-
- - cell_to_splitlong() -
-
H3 cell to split long
-
- - compact() -
-
Compact H3 cells
-
- - degs_to_rads() -
-
Convert degrees to radians
-
- - edge_length() -
-
Get exact cell edge length
-
- - get_base_cell() -
-
get the base cell of an H3 cell index
-
- - get_cell_vertex() -
-
Get a vertex index
-
- - get_cell_vertexes() -
-
Get all vertex indexes
-
- - get_centerchild() -
-
get central child H3 cell index
-
- - get_children() -
-
get child H3 cell indices
-
- - get_disk() -
-
Get nearby H3 cell indices
-
- - get_disk_list() -
-
Get nearby H3 cell indexes separated by distance
-
- - get_faces() -
-
get the icosahedron faces of an H3 cell index
-
- - get_gcdist() -
-
Great circle distance
-
- - get_local_cell() -
-
Get H3 cell from local i, j coordinates
-
- - get_local_ij() -
-
Get local i, j coordinates
-
- - get_parent() -
-
get parent H3 cell index
-
- - get_pentagons() -
-
get the pentagon indices for an H3 resolution
-
- - get_res() -
-
get the resolution of an H3 cell index
-
- - get_res0() -
-
Get resolution 0 indexes
-
- - get_ring() -
-
Get a ring of H3 cell indexes
-
- - get_uddest() -
-
Get destination cell from directed edge
-
- - get_udedge() -
-
Get a unidirectional edge index
-
- - get_udedges() -
-
Get all directed edge indexes for a given H3 cell
-
- - get_udends() -
-
Get origin and destination indexes of directed edge
-
- - get_udorigin() -
-
Get origin cell index from directed edge
-
- - grid_distance() -
-
Grid distance between H3 cells
-
- - grid_path() -
-
Path between H3 cells
-
- - h3jsr h3jsr-package -
-
h3jsr: Access Uber's H3 library
-
- - h3_info_table -
-
H3 index utility information table
-
- - is_pentagon() -
-
check if H3 cell index is a pentagon
-
- - is_rc3() -
-
check if H3 cell index is in a Class III resolution
-
- - is_valid() -
-
check H3 cell index
-
- - is_valid_edge() -
-
Check H3 unidirectional edge index
-
- - is_valid_vertex() -
-
check H3 cell index
-
- - num_cells() -
-
Get total H3 cells
-
- - point_to_cell() -
-
Convert point location to H3 cell index
-
- - polygon_to_cells() -
-
Get H3 cell index within a polygon
-
- - rads_to_degs() -
-
Convert radians to degrees
-
- - res_area() -
-
Get average cell area
-
- - res_cendist() -
-
Get average distance between H3 cell centers
-
- - res_length() -
-
Get average cell edge length
-
- - splitlong_to_cell() -
-
Split long to H3 cell
-
- - udedge_to_line() -
-
Get the geometry of an H3 edge
-
- - uncompact() -
-
Uncompact H3 cell indices
-
- - vertex_to_point() -
-
Convert H3 cell vertex index to point location
-
-
- - -
- - - - - - - diff --git a/docs/reference/is_pentagon.html b/docs/reference/is_pentagon.html deleted file mode 100644 index 822f893..0000000 --- a/docs/reference/is_pentagon.html +++ /dev/null @@ -1,110 +0,0 @@ - -check if H3 cell index is a pentagon — is_pentagon • h3jsr - Skip to contents - - -
-
-
- -
-

This function checks whether a H3 cell index refers to one of the pentagons -that occur at icosahedron corners.

-
- -
-

Usage

-
is_pentagon(h3_address = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, a logical vector of length(h3_address).

-
- -
-

Examples

-
# is the following cell index a pentagon?
-is_pentagon(h3_address = '8abe8d12acaffff')
-#> [1] FALSE
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/is_rc3.html b/docs/reference/is_rc3.html deleted file mode 100644 index d764be7..0000000 --- a/docs/reference/is_rc3.html +++ /dev/null @@ -1,113 +0,0 @@ - -check if H3 cell index is in a Class III resolution — is_rc3 • h3jsr - Skip to contents - - -
-
-
- -
-

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).

-
- -
-

Usage

-
is_rc3(h3_address = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, a logical vector of length(h3_address).

-
- -
-

Examples

-
# is the following cell index Class III?
-is_rc3(h3_address = '8abe8d12acaffff')
-#> [1] FALSE
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/is_valid.html b/docs/reference/is_valid.html deleted file mode 100644 index 31482b6..0000000 --- a/docs/reference/is_valid.html +++ /dev/null @@ -1,107 +0,0 @@ - -check H3 cell index — is_valid • h3jsr - Skip to contents - - -
-
-
- -
-

This function checks whether an H3 cell index is valid.

-
- -
-

Usage

-
is_valid(h3_address = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_address
-

Character; 15-character index generated by H3.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, a logical vector of length(h3_address).

-
- -
-

Examples

-
# is the following cell index valid?
-is_valid(h3_address = '8abe8d12acaffff')
-#> [1] TRUE
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/is_valid_edge.html b/docs/reference/is_valid_edge.html deleted file mode 100644 index 6b9b163..0000000 --- a/docs/reference/is_valid_edge.html +++ /dev/null @@ -1,108 +0,0 @@ - -Check H3 unidirectional edge index — is_valid_edge • h3jsr - Skip to contents - - -
-
-
- -
-

This function checks whether an H3 unidirectional edge index is valid.

-
- -
-

Usage

-
is_valid_edge(h3_edge = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_edge
-

Character; address of unidirectional edge.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, a logical vector of length(h3_edge).

-
- -
-

Examples

-
# is the following unidirectional edge index valid?
-is_valid_edge(h3_edge = '166be8d12fffffff')
-#> [1] TRUE
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/prep_for_polyfill.html b/docs/reference/prep_for_polyfill.html deleted file mode 100644 index 921c480..0000000 --- a/docs/reference/prep_for_polyfill.html +++ /dev/null @@ -1,107 +0,0 @@ - -Prepare geometry for polygon_to_cells — prep_for_polyfill • h3jsr - Skip to contents - - -
-
-
- -
-

Converts a variety of possible input geometries to geojson for -h3jsr::polygon_to_cells().

-
- -
-

Usage

-
prep_for_polyfill(polys = NULL)
-
-# S3 method for sf
-prep_for_polyfill(polys = NULL)
-
-# S3 method for sfc
-prep_for_polyfill(polys = NULL)
-
-# S3 method for sfg
-prep_for_polyfill(polys = NULL)
-
- -
-

Arguments

-
polys
-

sf, sfc or sfg POLYGON/MULTIPOLYGON object.

- -
-
-

Value

- - -

`geojson` representation of supplied geometry.

-
- -
- - -
- - - - - - - diff --git a/docs/reference/res_area.html b/docs/reference/res_area.html deleted file mode 100644 index d1a1a82..0000000 --- a/docs/reference/res_area.html +++ /dev/null @@ -1,120 +0,0 @@ - -Get average cell area — res_area • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns the average area of an H3 cell at a given -resolution.

-
- -
-

Usage

-
res_area(res = NULL, units = c("m2", "km2"), fast = TRUE)
-
- -
-

Arguments

-
res
-

Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.

- - -
units
-

Areal unit to report in. Options are square meters or square -kilometers.

- - -
fast
-

Logical; whether to retrieve values from a locally stored table or -reclaculate from source.

- -
-
-

Value

- - -

Numeric; average H3 cell area.

-
- -
-

Examples

-
# 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
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/res_cendist.html b/docs/reference/res_cendist.html deleted file mode 100644 index fe8cae0..0000000 --- a/docs/reference/res_cendist.html +++ /dev/null @@ -1,123 +0,0 @@ - -Get average distance between H3 cell centers — res_cendist • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns the average distance between the center of H3 cells - at a given resolution.

-
- -
-

Usage

-
res_cendist(res = NULL, units = c("m", "km"), fast = TRUE)
-
- -
-

Arguments

-
res
-

Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.

- - -
units
-

Length unit to report in, either meters or kilometers.

- - -
fast
-

Logical; whether to retrieve values from a locally stored table or -recalculate from source.

- -
-
-

Value

- - -

Numeric; H3 cell center separation distance.

-
-
-

Note

-

This isn't in the core library but may be useful.

-
- -
-

Examples

-
# 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
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/res_length.html b/docs/reference/res_length.html deleted file mode 100644 index 77c4713..0000000 --- a/docs/reference/res_length.html +++ /dev/null @@ -1,123 +0,0 @@ - -Get average cell edge length — res_length • h3jsr - Skip to contents - - -
-
-
- -
-

This function returns the average edge length of an H3 cell edge at a given -resolution.

-
- -
-

Usage

-
res_length(res = NULL, units = c("m", "km"), fast = TRUE)
-
- -
-

Arguments

-
res
-

Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.

- - -
units
-

Length unit to report in. Options are meters or kilometers.

- - -
fast
-

Logical; whether to retrieve values from a locally stored table -or recalculate from source.

- -
-
-

Value

- - -

Numeric; H3 cell edge length

-
-
-

Note

-

This value is also the hexagon circumradius.

-
- -
-

Examples

-
# 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
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/udedge_to_line.html b/docs/reference/udedge_to_line.html deleted file mode 100644 index c58f540..0000000 --- a/docs/reference/udedge_to_line.html +++ /dev/null @@ -1,116 +0,0 @@ - -Get the geometry of an H3 edge — udedge_to_line • h3jsr - Skip to contents - - -
-
-
- -
-

This function takes an H3 unidirectional edge address and returns the -coordinates of its geometry in WGS84.

-
- -
-

Usage

-
udedge_to_line(h3_edge = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_edge
-

Character; address of unidirectional edge.

- - -
simple
-

Logical; whether to return a vector of outputs or a data frame -containing both inputs and outputs.

- -
-
-

Value

- - -

By default, an object of type `sfc_LINESTRING`.

-
- -
-

Examples

-
# 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)
-
-
-
-
- - -
- - - - - - - diff --git a/docs/reference/uncompact.html b/docs/reference/uncompact.html deleted file mode 100644 index 43d0cb8..0000000 --- a/docs/reference/uncompact.html +++ /dev/null @@ -1,123 +0,0 @@ - -Uncompact H3 cell indices — uncompact • h3jsr - Skip to contents - - -
-
-
- -
-

This function uncompacts a compacted set of H3 cells to indices of the -target resolution.

-
- -
-

Usage

-
uncompact(h3_addresses = NULL, res = NULL, simple = TRUE)
-
- -
-

Arguments

-
h3_addresses
-

Character vector or list of 15-character cell indices -generated by H3.

- - -
res
-

Integer; Desired H3 resolution. See -https://h3geo.org/docs/core-library/restable/ for allowable values and related dimensions.

- - -
simple
-

Logical; whether to return a vector of outputs or a list object -containing both inputs and outputs.

- -
-
-

Value

- - -

A list of H3 cell indices of the chosen resolution.

-
- -
-

Examples

-
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)
-}
-
-
-
- - -
- - - - - - - diff --git a/docs/sitemap.xml b/docs/sitemap.xml deleted file mode 100644 index 6622e39..0000000 --- a/docs/sitemap.xml +++ /dev/null @@ -1,186 +0,0 @@ - - - - https://obrl-soil.github.io/h3jsr/404.html - - - https://obrl-soil.github.io/h3jsr/articles/index.html - - - https://obrl-soil.github.io/h3jsr/articles/intro-to-h3jsr.html - - - https://obrl-soil.github.io/h3jsr/authors.html - - - https://obrl-soil.github.io/h3jsr/index.html - - - https://obrl-soil.github.io/h3jsr/LICENSE.html - - - https://obrl-soil.github.io/h3jsr/news/index.html - - - https://obrl-soil.github.io/h3jsr/reference/are_neighbours.html - - - https://obrl-soil.github.io/h3jsr/reference/cells_to_multipolygon.html - - - https://obrl-soil.github.io/h3jsr/reference/cell_area.html - - - https://obrl-soil.github.io/h3jsr/reference/cell_to_line.html - - - https://obrl-soil.github.io/h3jsr/reference/cell_to_point.html - - - https://obrl-soil.github.io/h3jsr/reference/cell_to_polygon.html - - - https://obrl-soil.github.io/h3jsr/reference/cell_to_splitlong.html - - - https://obrl-soil.github.io/h3jsr/reference/compact.html - - - https://obrl-soil.github.io/h3jsr/reference/degs_to_rads.html - - - https://obrl-soil.github.io/h3jsr/reference/edge_length.html - - - https://obrl-soil.github.io/h3jsr/reference/get_base_cell.html - - - https://obrl-soil.github.io/h3jsr/reference/get_cell_vertex.html - - - https://obrl-soil.github.io/h3jsr/reference/get_cell_vertexes.html - - - https://obrl-soil.github.io/h3jsr/reference/get_centerchild.html - - - https://obrl-soil.github.io/h3jsr/reference/get_children.html - - - https://obrl-soil.github.io/h3jsr/reference/get_disk.html - - - https://obrl-soil.github.io/h3jsr/reference/get_disk_list.html - - - https://obrl-soil.github.io/h3jsr/reference/get_faces.html - - - https://obrl-soil.github.io/h3jsr/reference/get_gcdist.html - - - https://obrl-soil.github.io/h3jsr/reference/get_local_cell.html - - - https://obrl-soil.github.io/h3jsr/reference/get_local_ij.html - - - https://obrl-soil.github.io/h3jsr/reference/get_parent.html - - - https://obrl-soil.github.io/h3jsr/reference/get_pentagons.html - - - https://obrl-soil.github.io/h3jsr/reference/get_res.html - - - https://obrl-soil.github.io/h3jsr/reference/get_res0.html - - - https://obrl-soil.github.io/h3jsr/reference/get_ring.html - - - https://obrl-soil.github.io/h3jsr/reference/get_uddest.html - - - https://obrl-soil.github.io/h3jsr/reference/get_udedge.html - - - https://obrl-soil.github.io/h3jsr/reference/get_udedges.html - - - https://obrl-soil.github.io/h3jsr/reference/get_udends.html - - - https://obrl-soil.github.io/h3jsr/reference/get_udorigin.html - - - https://obrl-soil.github.io/h3jsr/reference/grid_distance.html - - - https://obrl-soil.github.io/h3jsr/reference/grid_path.html - - - https://obrl-soil.github.io/h3jsr/reference/h3jsr-package.html - - - https://obrl-soil.github.io/h3jsr/reference/h3_info_table.html - - - https://obrl-soil.github.io/h3jsr/reference/index.html - - - https://obrl-soil.github.io/h3jsr/reference/is_pentagon.html - - - https://obrl-soil.github.io/h3jsr/reference/is_rc3.html - - - https://obrl-soil.github.io/h3jsr/reference/is_valid.html - - - https://obrl-soil.github.io/h3jsr/reference/is_valid_edge.html - - - https://obrl-soil.github.io/h3jsr/reference/is_valid_vertex.html - - - https://obrl-soil.github.io/h3jsr/reference/num_cells.html - - - https://obrl-soil.github.io/h3jsr/reference/point_to_cell.html - - - https://obrl-soil.github.io/h3jsr/reference/polygon_to_cells.html - - - https://obrl-soil.github.io/h3jsr/reference/prep_for_polyfill.html - - - https://obrl-soil.github.io/h3jsr/reference/prep_for_pt2cell.html - - - https://obrl-soil.github.io/h3jsr/reference/rads_to_degs.html - - - https://obrl-soil.github.io/h3jsr/reference/res_area.html - - - https://obrl-soil.github.io/h3jsr/reference/res_cendist.html - - - https://obrl-soil.github.io/h3jsr/reference/res_length.html - - - https://obrl-soil.github.io/h3jsr/reference/splitlong_to_cell.html - - - https://obrl-soil.github.io/h3jsr/reference/udedge_to_line.html - - - https://obrl-soil.github.io/h3jsr/reference/uncompact.html - - - https://obrl-soil.github.io/h3jsr/reference/vertex_to_point.html - - diff --git a/tests/testthat/test_algorithms.R b/tests/testthat/test_algorithms.R index b9b25f1..3d7004d 100644 --- a/tests/testthat/test_algorithms.R +++ b/tests/testthat/test_algorithms.R @@ -1,235 +1,195 @@ context('H3 Algorithms') -test_that( - 'get_parent returns correctly', - c( - expect_error(get_parent(h3_address = 'whereami', res = 1)), - expect_error(get_parent(h3_address = '8abe8d12acaffff', res = 20)), - val1 <- get_parent(h3_address = '8abe8d12acaffff', res = 6), - val2 <- get_parent(h3_address = '8abe8d12acaffff', res = 6, - simple = FALSE), - expect_equal(val1, '86be8d12fffffff'), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_is(val2$h3_res, 'integer'), - expect_equal(val2$h3_parent, '86be8d12fffffff') - ) -) - -test_that( - 'get_children returns correctly', - c( - expect_error(get_children(h3_address = 'whereami', res = 12)), - expect_error(get_children(h3_address = '8abe8d12acaffff', res = 20)), - val1 <- get_children(h3_address = '86be8d12fffffff', res = 8), - val2 <- get_children(h3_address = '86be8d12fffffff', res = 8, - simple = FALSE), - expect_equal(length(val1[[1]]), 49L), - expect_equal(val1[[1]][1], '88be8d1281fffff'), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_is(val2$h3_res, 'integer'), - expect_equal(length(val2$h3_children[[1]]), 49L), - expect_equal(val2$h3_children[[1]][1], '88be8d1281fffff') - - ) -) - -test_that( - 'get_centerchild returns correctly', - c( - expect_error(get_centerchild(h3_address = 'whereami', res = 12)), - expect_error(get_centerchild(h3_address = '8abe8d12acaffff', res = 20)), - val1 <- get_centerchild(h3_address = '86be8d12fffffff', res = 8), - val2 <- get_centerchild(h3_address = '86be8d12fffffff', res = 8, - simple = FALSE), - expect_equal(length(val1[[1]]), 1L), - expect_equal(val1[[1]][1], '88be8d1281fffff'), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_is(val2$h3_res, 'integer'), - expect_equal(length(val2$h3_centerchild[[1]]), 1L), - expect_equal(val2$h3_centerchild[[1]][1], '88be8d1281fffff') - - ) -) - -test_that( - 'get_disk returns correctly', - c( - expect_error(get_disk(h3_address = 'whereami', ring_size = 2)), - val1 <- get_disk(h3_address = '86be8d12fffffff', ring_size = 2), - val2 <- get_disk(h3_address = '86be8d12fffffff', ring_size = 2, - simple = FALSE), - expect_is(val1, 'list'), - expect_equal(length(val1[[1]]), 19L), - expect_equal(val1[[1]][1], '86be8d12fffffff'), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_is(val2$ring_size, 'integer'), - expect_equal(length(val2$h3_disk[[1]]), 19L), - expect_equal(val2$h3_disk[[1]][1], '86be8d12fffffff') - - ) -) - -test_that( - 'get_disk_list returns correctly', - c( - expect_error(get_disk_list(h3_address = 'whereami', ring_size = 2)), - val1 <- get_disk_list(h3_address = '86be8d12fffffff', ring_size = 2), - val2 <- get_disk_list(h3_address = '86be8d12fffffff', ring_size = 2, - simple = FALSE), - expect_is(val1[[1]], 'list'), - expect_equal(length(val1[[1]]), 3L), - expect_equal(val1[[1]][[1]], '86be8d12fffffff'), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_is(val2$ring_size, 'integer'), - expect_equal(length(val2$h3_disks[[1]]), 3L), - expect_equal(val2$h3_disks[[1]][[1]], '86be8d12fffffff') - - ) -) - -test_that( - 'get_ring returns correctly', - c( - expect_error(get_ring(h3_address = 'whereami', ring_size = 2)), - val1 <- get_ring(h3_address = '86be8d12fffffff', ring_size = 2), - val2 <- get_ring(h3_address = '86be8d12fffffff', ring_size = 2, - simple = FALSE), - expect_equal(length(val1[[1]]), 12L), - expect_equal(val1[[1]][1], '86be8d8f7ffffff'), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_is(val2$ring_size, 'integer'), - expect_equal(length(val2$h3_ring[[1]]), 12L), - expect_equal(val2$h3_ring[[1]][1], '86be8d8f7ffffff') - - ) -) - -test_that( - 'polygon_to_cells returns correctly', - c( - expect_error(polygon_to_cells(geometry = 'a shape', res = 4)), - nc <- sf::st_read(system.file("shape/nc.shp", package="sf")), - nc1 <- nc[1, ], - expect_error(polygon_to_cells(geometry = nc1, res = 20)), - expect_message(polygon_to_cells(geometry = sf::st_transform(nc1, 4326), res = 10)), - expect_message(polygon_to_cells(geometry = nc, res = 1)), - val1 <- polygon_to_cells(geometry = nc1, res = 4), - val2 <- polygon_to_cells(geometry = nc1, res = 4, simple = FALSE), - expect_equal(val1[[1]], '842a993ffffffff'), - expect_is(val2, 'data.frame'), - expect_is(val2, 'sf'), - expect_is(val2$h3_addresses[[1]], 'character'), - val3 <- polygon_to_cells(geometry = nc1, res = 1), - expect_equal(val3[[1]], NA_character_) - ) -) - -test_that( - 'cells_to_multipolygon returns correctly', - c(library(sf), - bth <- sf::st_sfc(sf::st_point(c(153.023503, -27.468920)), crs = 4326), - expect_error(cells_to_multipolygon(h3_addresses = 'whereami')), - val <- point_to_cell(bth, res = 10), - val <- get_disk(h3_address = val, ring_size = 2), - val1 <- cells_to_multipolygon(unlist(val)), - val2 <- cells_to_multipolygon(unlist(val), simple = FALSE), - val3 <- cells_to_multipolygon(val[[1]][1]), - expect_equal(val1, cells_to_multipolygon(val)), - expect_is(val1, 'sfc'), - expect_is(val2, 'sf'), - expect_is(val3, 'sfc'), - expect_is(val2$h3_addresses[[1]], 'character') - # bad geom bit needs handling another way, another time - ) -) - -test_that( - 'compact returns correctly', - c( - 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), - expect_error(compact(c('whereami', 'whoami'))), - val1 <- compact(fillers), - val2 <- compact(fillers, simple = FALSE), - val3 <- compact(fillers[[1]][1]), - expect_is(val1, 'character'), - expect_equal(length(val1), 15L), - expect_is(val2, 'list'), - expect_equal(length(val2), 2L), - expect_equal(length(val2[[1]]), 33L), - expect_is(val2[[1]], 'character'), - expect_equal(length(val2[[2]]), 15L), - expect_is(val2[[2]], 'character'), - expect_equal(val3, fillers[[1]][1]) - ) -) - -test_that( - 'uncompact returns correctly', - c( - 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), - comp <- compact(fillers), - expect_error(uncompact(c('whereami', 'whoami'), res = 13)), - expect_error(uncompact(fillers, res = 25)), - val1 <- uncompact(fillers, res = 7), - val2 <- uncompact(fillers, res = 7, simple = FALSE), - val3 <- uncompact(fillers[[1]][1], res = 7, simple = FALSE), - expect_is(val1, 'character'), - expect_equal(length(val1), 231L), - expect_equal(length(val2[[1]]), 33L), - expect_is(val2[[1]], 'character'), - expect_equal(length(val2[[2]]), 231L), - expect_is(val2[[2]], 'character'), - expect_equal(length(val3[[2]]), 7L), - expect_is(val3[[2]], 'character') - ) -) - -test_that( - 'grid_distance returns correctly', - c( - expect_error(grid_distance('whereami', 'whoami')), - expect_error(grid_distance('whereami')), - expect_error(grid_distance('86be8d12fffffff', - c('86be8d127ffffff', '86be8d107ffffff'))), - val1 <- grid_distance('86be8d12fffffff', '86be8d127ffffff'), - val2 <- grid_distance(c('86be8d12fffffff', '86be8d107ffffff', '86be8d127ffffff'), +test_that('get_parent returns correctly', { + expect_error(get_parent(h3_address = 'whereami', res = 1)) + expect_error(get_parent(h3_address = '8abe8d12acaffff', res = 20)) + val1 <- get_parent(h3_address = '8abe8d12acaffff', res = 6) + val2 <- get_parent(h3_address = '8abe8d12acaffff', res = 6, + simple = FALSE) + expect_equal(val1, '86be8d12fffffff') + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_is(val2$h3_res, 'integer') + expect_equal(val2$h3_parent, '86be8d12fffffff') +}) + +test_that('get_children returns correctly', { + expect_error(get_children(h3_address = 'whereami', res = 12)) + expect_error(get_children(h3_address = '8abe8d12acaffff', res = 20)) + val1 <- get_children(h3_address = '86be8d12fffffff', res = 8) + val2 <- get_children(h3_address = '86be8d12fffffff', res = 8, + simple = FALSE) + expect_equal(length(val1[[1]]), 49L) + expect_equal(val1[[1]][1], '88be8d1281fffff') + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_is(val2$h3_res, 'integer') + expect_equal(length(val2$h3_children[[1]]), 49L) + expect_equal(val2$h3_children[[1]][1], '88be8d1281fffff') +}) + +test_that('get_centerchild returns correctly', { + expect_error(get_centerchild(h3_address = 'whereami', res = 12)) + expect_error(get_centerchild(h3_address = '8abe8d12acaffff', res = 20)) + val1 <- get_centerchild(h3_address = '86be8d12fffffff', res = 8) + val2 <- get_centerchild(h3_address = '86be8d12fffffff', res = 8, + simple = FALSE) + expect_equal(length(val1[[1]]), 1L) + expect_equal(val1[[1]][1], '88be8d1281fffff') + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_is(val2$h3_res, 'integer') + expect_equal(length(val2$h3_centerchild[[1]]), 1L) + expect_equal(val2$h3_centerchild[[1]][1], '88be8d1281fffff') +}) + +test_that('get_disk returns correctly', { + expect_error(get_disk(h3_address = 'whereami', ring_size = 2)) + val1 <- get_disk(h3_address = '86be8d12fffffff', ring_size = 2) + val2 <- get_disk(h3_address = '86be8d12fffffff', ring_size = 2, + simple = FALSE) + expect_is(val1, 'list') + expect_equal(length(val1[[1]]), 19L) + expect_equal(val1[[1]][1], '86be8d12fffffff') + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_is(val2$ring_size, 'integer') + expect_equal(length(val2$h3_disk[[1]]), 19L) + expect_equal(val2$h3_disk[[1]][1], '86be8d12fffffff') +}) + +test_that('get_disk_list returns correctly', { + expect_error(get_disk_list(h3_address = 'whereami', ring_size = 2)) + val1 <- get_disk_list(h3_address = '86be8d12fffffff', ring_size = 2) + val2 <- get_disk_list(h3_address = '86be8d12fffffff', ring_size = 2, + simple = FALSE) + expect_is(val1[[1]], 'list') + expect_equal(length(val1[[1]]), 3L) + expect_equal(val1[[1]][[1]], '86be8d12fffffff') + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_is(val2$ring_size, 'integer') + expect_equal(length(val2$h3_disks[[1]]), 3L) + expect_equal(val2$h3_disks[[1]][[1]], '86be8d12fffffff') +}) + +test_that('get_ring returns correctly', { + expect_error(get_ring(h3_address = 'whereami', ring_size = 2)) + val1 <- get_ring(h3_address = '86be8d12fffffff', ring_size = 2) + val2 <- get_ring(h3_address = '86be8d12fffffff', ring_size = 2, + simple = FALSE) + expect_equal(length(val1[[1]]), 12L) + expect_equal(val1[[1]][1], '86be8d8f7ffffff') + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_is(val2$ring_size, 'integer') + expect_equal(length(val2$h3_ring[[1]]), 12L) + expect_equal(val2$h3_ring[[1]][1], '86be8d8f7ffffff') +}) + +test_that('polygon_to_cells returns correctly', { + expect_error(polygon_to_cells(geometry = 'a shape', res = 4)) + nc <- sf::st_read(system.file("shape/nc.shp", package="sf")) + nc1 <- nc[1, ] + expect_error(polygon_to_cells(geometry = nc1, res = 20)) + expect_message(polygon_to_cells(geometry = sf::st_transform(nc1, 4326), res = 10)) + expect_message(polygon_to_cells(geometry = nc, res = 1)) + val1 <- polygon_to_cells(geometry = nc1, res = 4) + val2 <- polygon_to_cells(geometry = nc1, res = 4, simple = FALSE) + expect_equal(val1[[1]], '842a993ffffffff') + expect_is(val2, 'data.frame') + expect_is(val2, 'sf') + expect_is(val2$h3_addresses[[1]], 'character') + val3 <- polygon_to_cells(geometry = nc1, res = 1) + expect_equal(val3[[1]], NA_character_) +}) + +test_that('cells_to_multipolygon returns correctly', { + library(sf) + bth <- sf::st_sfc(sf::st_point(c(153.023503, -27.468920)), crs = 4326) + expect_error(cells_to_multipolygon(h3_addresses = 'whereami')) + val <- point_to_cell(bth, res = 10) + val <- get_disk(h3_address = val, ring_size = 2) + val1 <- cells_to_multipolygon(unlist(val)) + val2 <- cells_to_multipolygon(unlist(val), simple = FALSE) + val3 <- cells_to_multipolygon(val[[1]][1]) + expect_equal(val1, cells_to_multipolygon(val)) + expect_is(val1, 'sfc') + expect_is(val2, 'sf') + expect_is(val3, 'sfc') + expect_is(val2$h3_addresses[[1]], 'character') + # bad geom bit needs handling another way, another time +}) + +test_that('compact returns correctly', { + 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) + expect_error(compact(c('whereami', 'whoami'))) + val1 <- compact(fillers) + val2 <- compact(fillers, simple = FALSE) + val3 <- compact(fillers[[1]][1]) + expect_is(val1, 'character') + expect_equal(length(val1), 15L) + expect_is(val2, 'list') + expect_equal(length(val2), 2L) + expect_equal(length(val2[[1]]), 33L) + expect_is(val2[[1]], 'character') + expect_equal(length(val2[[2]]), 15L) + expect_is(val2[[2]], 'character') + expect_equal(val3, fillers[[1]][1]) +}) + +test_that('uncompact returns correctly', { + 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) + comp <- compact(fillers) + expect_error(uncompact(c('whereami', 'whoami'), res = 13)) + expect_error(uncompact(fillers, res = 25)) + val1 <- uncompact(fillers, res = 7) + val2 <- uncompact(fillers, res = 7, simple = FALSE) + val3 <- uncompact(fillers[[1]][1], res = 7, simple = FALSE) + expect_is(val1, 'character') + expect_equal(length(val1), 231L) + expect_equal(length(val2[[1]]), 33L) + expect_is(val2[[1]], 'character') + expect_equal(length(val2[[2]]), 231L) + expect_is(val2[[2]], 'character') + expect_equal(length(val3[[2]]), 7L) + expect_is(val3[[2]], 'character') +}) + +test_that('grid_distance returns correctly', { + expect_error(grid_distance('whereami', 'whoami')) + expect_error(grid_distance('whereami')) + expect_error(grid_distance('86be8d12fffffff', + c('86be8d127ffffff', '86be8d107ffffff'))) + val1 <- grid_distance('86be8d12fffffff', '86be8d127ffffff') + val2 <- grid_distance(c('86be8d12fffffff', '86be8d107ffffff', '86be8d127ffffff'), c('86be8d127ffffff', '86be8d10fffffff', '86be8d10fffffff'), - simple = FALSE), - expect_equal(val1, 1L), - expect_is(val2, 'data.frame'), - expect_equal(names(val2), c('origin', 'destination', 'grid_distance')), - expect_equal(dim(val2)[1], 3), - expect_equal(val2$grid_distance, c(1L, 1L, 2L)) - ) -) - -test_that( - 'grid_path returns correctly', - c( - expect_error(grid_path('whereami', 'whoami')), - expect_error(grid_path('whereami')), - expect_error(grid_path('86be8d12fffffff', - c('86be8d127ffffff', '86be8d107ffffff'))), - val1 <- grid_path('86be8d12fffffff', '86be8d127ffffff'), - val2 <- grid_path(c('86be8d12fffffff', '86be8d107ffffff', '86be8d127ffffff'), - c('86be8d127ffffff', '86be8d10fffffff', '86be8d10fffffff'), - simple = FALSE), - expect_equal(val1[[1]], c('86be8d12fffffff', '86be8d127ffffff')), - expect_is(val2, 'data.frame'), - expect_equal(names(val2), c('origin', 'destination', 'grid_path')), - expect_equal(dim(val2)[1], 3), - expect_is(val2$grid_path, 'list') - ) -) + simple = FALSE) + expect_equal(val1, 1L) + expect_is(val2, 'data.frame') + expect_equal(names(val2), c('origin', 'destination', 'grid_distance')) + expect_equal(dim(val2)[1], 3) + expect_equal(val2$grid_distance, c(1L, 1L, 2L)) +}) + +test_that('grid_path returns correctly', { + expect_error(grid_path('whereami', 'whoami')) + expect_error(grid_path('whereami')) + expect_error(grid_path('86be8d12fffffff', + c('86be8d127ffffff', '86be8d107ffffff'))) + val1 <- grid_path('86be8d12fffffff', '86be8d127ffffff') + val2 <- grid_path(c('86be8d12fffffff', '86be8d107ffffff', '86be8d127ffffff'), + c('86be8d127ffffff', '86be8d10fffffff', '86be8d10fffffff'), + simple = FALSE) + expect_equal(val1[[1]], c('86be8d12fffffff', '86be8d127ffffff')) + expect_is(val2, 'data.frame') + expect_equal(names(val2), c('origin', 'destination', 'grid_path')) + expect_equal(dim(val2)[1], 3) + expect_is(val2$grid_path, 'list') +}) diff --git a/tests/testthat/test_core_api.R b/tests/testthat/test_core_api.R index 5148e30..0553eef 100644 --- a/tests/testthat/test_core_api.R +++ b/tests/testthat/test_core_api.R @@ -1,342 +1,292 @@ context('Core H3 API') -test_that( - 'is_valid returns correctly', - c( - val1 <- is_valid(h3_address = '8abe8d12acaffff'), - val2 <- is_valid(h3_address = c('whereami', '8abe8d12acaffff')), - val3 <- is_valid(h3_address = c('whereami', '8abe8d12acaffff'), - simple = FALSE), - expect_equal(val1, TRUE), - expect_equal(val2, c(FALSE, TRUE)), - expect_is(val3, 'data.frame'), - expect_is(val3$h3_address, 'character'), - expect_equal(val3$h3_valid, c(FALSE, TRUE)) - ) -) +test_that('is_valid returns correctly', { + val1 <- is_valid(h3_address = '8abe8d12acaffff') + val2 <- is_valid(h3_address = c('whereami', '8abe8d12acaffff')) + val3 <- is_valid(h3_address = c('whereami', '8abe8d12acaffff'), + simple = FALSE) + expect_equal(val1, TRUE) + expect_equal(val2, c(FALSE, TRUE)) + expect_is(val3, 'data.frame') + expect_is(val3$h3_address, 'character') + expect_equal(val3$h3_valid, c(FALSE, TRUE)) +}) -test_that( - 'is_pentagon returns correctly', - c( - expect_error(is_pentagon(h3_address = 'whereami')), - val1 <- is_pentagon(h3_address = '8abe8d12acaffff'), - val2 <- is_pentagon(h3_address = '8abe8d12acaffff', simple = FALSE), - expect_equal(val1, FALSE), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_equal(val2$h3_pentagon, FALSE) - # note to self find the addy of a pentagon - ) -) +test_that('is_pentagon returns correctly', { + expect_error(is_pentagon(h3_address = 'whereami')) + val1 <- is_pentagon(h3_address = '8abe8d12acaffff') + val2 <- is_pentagon(h3_address = '8abe8d12acaffff', simple = FALSE) + expect_equal(val1, FALSE) + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_equal(val2$h3_pentagon, FALSE) + # note to self find the addy of a pentagon +}) # is_rc3 -test_that( - 'is_rc3 returns correctly', - c( - expect_error(is_rc3(h3_address = 'whereami')), - val1 <- is_rc3(h3_address = '8abe8d12acaffff'), - val2 <- is_rc3(h3_address = '8abe8d12acaffff', simple = FALSE), - expect_equal(val1, FALSE), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_equal(val2$h3_rc3, FALSE) - ) -) +test_that('is_rc3 returns correctly', { + expect_error(is_rc3(h3_address = 'whereami')) + val1 <- is_rc3(h3_address = '8abe8d12acaffff') + val2 <- is_rc3(h3_address = '8abe8d12acaffff', simple = FALSE) + expect_equal(val1, FALSE) + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_equal(val2$h3_rc3, FALSE) +}) -test_that( - 'get_base_cell returns correctly', - c( - expect_error(get_base_cell(h3_address = 'whereami')), - val1 <- get_base_cell(h3_address = '8abe8d12acaffff'), - val2 <- get_base_cell(h3_address = '8abe8d12acaffff', simple = FALSE), - expect_equal(val1, 95L), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_equal(val2$h3_base_cell, 95L) - ) -) +test_that('get_base_cell returns correctly', { + expect_error(get_base_cell(h3_address = 'whereami')) + val1 <- get_base_cell(h3_address = '8abe8d12acaffff') + val2 <- get_base_cell(h3_address = '8abe8d12acaffff', simple = FALSE) + expect_equal(val1, 95L) + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_equal(val2$h3_base_cell, 95L) +}) -test_that( - 'get_faces returns correctly', - c( - expect_error(get_faces(h3_address = 'whereami')), - val1 <- get_faces(h3_address = '8abe8d12acaffff'), - val2 <- get_faces(h3_address = '8abe8d12acaffff', simple = FALSE), - expect_equal(val1, 15L), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_faces, 'list'), - expect_equal(val2$h3_faces[[1]], 15L) - ) -) +test_that('get_faces returns correctly', { + expect_error(get_faces(h3_address = 'whereami')) + val1 <- get_faces(h3_address = '8abe8d12acaffff') + val2 <- get_faces(h3_address = '8abe8d12acaffff', simple = FALSE) + expect_equal(val1, 15L) + expect_is(val2, 'data.frame') + expect_is(val2$h3_faces, 'list') + expect_equal(val2$h3_faces[[1]], 15L) +}) -test_that( - 'get_pentagons returns correctly', - c( - expect_error(get_pentagons(res = Inf)), - val1 <- get_pentagons(res = 8), - val2 <- get_pentagons(res = c(8, 9), simple = FALSE), - expect_is(val1, 'list'), - expect_is(val2, 'data.frame'), - expect_length(val1, 1L), - expect_length(val1[[1]], 12L), - expect_true("8808000001fffff" %in% val1[[1]]), - expect_is(val2$h3_pentagons, 'list'), - expect_length(val2$h3_pentagons, 2L), - expect_length(val2$h3_pentagons[[1]], 12L) - ) -) +test_that('get_pentagons returns correctly', { + expect_error(get_pentagons(res = Inf)) + val1 <- get_pentagons(res = 8) + val2 <- get_pentagons(res = c(8, 9), simple = FALSE) + expect_is(val1, 'list') + expect_is(val2, 'data.frame') + expect_length(val1, 1L) + expect_length(val1[[1]], 12L) + expect_true("8808000001fffff" %in% val1[[1]]) + expect_is(val2$h3_pentagons, 'list') + expect_length(val2$h3_pentagons, 2L) + expect_length(val2$h3_pentagons[[1]], 12L) +}) -test_that( - 'get_res returns correctly', - c( - expect_error(get_res(h3_address = 'whereami')), - val1 <- get_res(h3_address = '8abe8d12acaffff'), - val2 <- get_res(h3_address = '8abe8d12acaffff', simple = FALSE), - expect_equal(val1, 10L), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_equal(val2$h3_res, 10L) - ) -) +test_that('get_res returns correctly', { + expect_error(get_res(h3_address = 'whereami')) + val1 <- get_res(h3_address = '8abe8d12acaffff') + val2 <- get_res(h3_address = '8abe8d12acaffff', simple = FALSE) + expect_equal(val1, 10L) + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_equal(val2$h3_res, 10L) +}) -test_that('prep_for_pt2cell works consistently across methods', - c(# matrix method - bth_mat <- matrix(c(153.023503, -27.468920), ncol = 2), - bth_mat_m <- matrix(c(bth_mat, bth_mat, bth_mat), - ncol = 2, byrow = TRUE), - val1 <- h3jsr:::prep_for_pt2cell(bth_mat), - val2 <- h3jsr:::prep_for_pt2cell(bth_mat_m), - expect_is(val1, 'matrix'), - expect_is(val2, 'matrix'), - expect_message(h3jsr:::prep_for_pt2cell(bth_mat)), - # df method - bth_df <- as.data.frame(bth_mat), - bth_df_m <- as.data.frame(bth_mat_m), - val3 <- h3jsr:::prep_for_pt2cell(bth_df), - val4 <- h3jsr:::prep_for_pt2cell(bth_df_m), - expect_equal(val1, val3), - expect_equal(val2, val4), - expect_message(h3jsr:::prep_for_pt2cell(bth_df)), - # sfg method - bth_sfg <- sf::st_point(bth_mat), - val5 <- h3jsr:::prep_for_pt2cell(bth_sfg), - expect_equivalent(val1, val5), # dimnames, meh - expect_message(h3jsr:::prep_for_pt2cell(bth_sfg)), - # sfc method - bth_sfc <- sf::st_sfc(bth_sfg, crs = 4326), - bth_sfc_m <- - sf::st_as_sfc(list(bth_sfg, bth_sfg, bth_sfg), crs = 4326), - val6 <- h3jsr:::prep_for_pt2cell(bth_sfc), - val7 <- h3jsr:::prep_for_pt2cell(bth_sfc_m), - expect_equal(val5, val6), - expect_equivalent(val2, val7), # dimnames - bth_sfc2 <- sf::st_sfc(bth_sfg, crs = 4283), - expect_message(h3jsr:::prep_for_pt2cell(bth_sfc2)), - # sf method - bth_sf <- sf::st_sf('geometry' = bth_sfc), - bth_sf_m <- sf::st_sf('geometry' = bth_sfc_m), - val8 <- h3jsr:::prep_for_pt2cell(bth_sf), - val9 <- h3jsr:::prep_for_pt2cell(bth_sf_m), - expect_equal(val6, val8), - expect_equal(val7, val9), - bth_sf2 <- sf::st_sf('geometry' = bth_sfc2), - expect_message(h3jsr:::prep_for_pt2cell(bth_sf2)), - # simple vector - bth_vec <- c(153.023503, -27.468920), - val10 <- h3jsr:::prep_for_pt2cell(bth_vec), - expect_equal(val1, val10) - )) +test_that('prep_for_pt2cell works consistently across methods', { + # matrix method + bth_mat <- matrix(c(153.023503, -27.468920), ncol = 2) + bth_mat_m <- matrix(c(bth_mat, bth_mat, bth_mat), + ncol = 2, byrow = TRUE) + val1 <- h3jsr:::prep_for_pt2cell(bth_mat) + val2 <- h3jsr:::prep_for_pt2cell(bth_mat_m) + expect_is(val1, 'matrix') + expect_is(val2, 'matrix') + expect_message(h3jsr:::prep_for_pt2cell(bth_mat)) + # df method + bth_df <- as.data.frame(bth_mat) + bth_df_m <- as.data.frame(bth_mat_m) + val3 <- h3jsr:::prep_for_pt2cell(bth_df) + val4 <- h3jsr:::prep_for_pt2cell(bth_df_m) + expect_equal(val1, val3) + expect_equal(val2, val4) + expect_message(h3jsr:::prep_for_pt2cell(bth_df)) + # sfg method + bth_sfg <- sf::st_point(bth_mat) + val5 <- h3jsr:::prep_for_pt2cell(bth_sfg) + expect_equivalent(val1, val5) # dimnames, meh + expect_message(h3jsr:::prep_for_pt2cell(bth_sfg)) + # sfc method + bth_sfc <- sf::st_sfc(bth_sfg, crs = 4326) + bth_sfc_m <- + sf::st_as_sfc(list(bth_sfg, bth_sfg, bth_sfg), crs = 4326) + val6 <- h3jsr:::prep_for_pt2cell(bth_sfc) + val7 <- h3jsr:::prep_for_pt2cell(bth_sfc_m) + expect_equal(val5, val6) + expect_equivalent(val2, val7) # dimnames + bth_sfc2 <- sf::st_sfc(bth_sfg, crs = 4283) + expect_message(h3jsr:::prep_for_pt2cell(bth_sfc2)) + # sf method + bth_sf <- sf::st_sf('geometry' = bth_sfc) + bth_sf_m <- sf::st_sf('geometry' = bth_sfc_m) + val8 <- h3jsr:::prep_for_pt2cell(bth_sf) + val9 <- h3jsr:::prep_for_pt2cell(bth_sf_m) + expect_equal(val6, val8) + expect_equal(val7, val9) + bth_sf2 <- sf::st_sf('geometry' = bth_sfc2) + expect_message(h3jsr:::prep_for_pt2cell(bth_sf2)) + # simple vector + bth_vec <- c(153.023503, -27.468920) + val10 <- h3jsr:::prep_for_pt2cell(bth_vec) + expect_equal(val1, val10) +}) -test_that('point_to_cell with various options', - c(bpts <- list(c(153.02350, -27.46892), - c(153.02456, -27.47071), - c(153.02245, -27.47078)), - bpts <- lapply(bpts, sf::st_point), - bpts_sfc <- sf::st_sfc(bpts, crs = 4326), - bpts_sf <- sf::st_sf('geometry' = bpts_sfc), - # several points 1 res - expect_error(point_to_cell(bpts_sfc, res = 25)), - val1 <- point_to_cell(bpts_sfc, res = 11), - val2 <- point_to_cell(bpts_sfc, res = 11, simple = FALSE), - expect_equal(val1[1], '8bbe8d12acadfff'), - expect_length(val1, 3), - expect_is(val2, 'data.frame'), - expect_equal(nrow(val2), 3), - # several points several res - val3 <- point_to_cell(bpts_sfc, res = c(11,12)), - val4 <- point_to_cell(bpts_sfc, res = c(11,12), simple = FALSE), - expect_identical(val3, val4), - expect_identical(val2$h3_resolution_11, val3$h3_resolution_11, - val4$h3_resolution_11), - # sf object with other attribs - bpts_sf2 <- sf::st_sf('ID' = seq(length(bpts_sfc)), - 'geometry' = bpts_sfc), - val5 <- point_to_cell(bpts_sf2, res = c(11,12), simple = FALSE), - expect_is(val5, 'data.frame'), - expect_equal(nrow(val5), 3), - expect_equal(names(val5), c('ID', 'h3_resolution_11', 'h3_resolution_12')), - expect_equal(val5[[1]], c(1,2,3)), - # df with other attribs - bpts_df2 <- - as.data.frame(cbind(matrix(unlist(bpts_sfc), - ncol = 2, byrow = T), 'ID' = seq(3))), - val6 <- point_to_cell(bpts_df2, res = c(11, 12), simple = FALSE), - expect_equal(val5, val6) - ) - ) +test_that('point_to_cell with various options', { + bpts <- list(c(153.02350, -27.46892), + c(153.02456, -27.47071), + c(153.02245, -27.47078)) + bpts <- lapply(bpts, sf::st_point) + bpts_sfc <- sf::st_sfc(bpts, crs = 4326) + bpts_sf <- sf::st_sf('geometry' = bpts_sfc) + # several points 1 res + expect_error(point_to_cell(bpts_sfc, res = 25)) + val1 <- point_to_cell(bpts_sfc, res = 11) + val2 <- point_to_cell(bpts_sfc, res = 11, simple = FALSE) + expect_equal(val1[1], '8bbe8d12acadfff') + expect_length(val1, 3) + expect_is(val2, 'data.frame') + expect_equal(nrow(val2), 3) + # several points several res + val3 <- point_to_cell(bpts_sfc, res = c(11,12)) + val4 <- point_to_cell(bpts_sfc, res = c(11,12), simple = FALSE) + expect_identical(val3, val4) + expect_identical(val2$h3_resolution_11, val3$h3_resolution_11, + val4$h3_resolution_11) + # sf object with other attribs + bpts_sf2 <- sf::st_sf('ID' = seq(length(bpts_sfc)), + 'geometry' = bpts_sfc) + val5 <- point_to_cell(bpts_sf2, res = c(11,12), simple = FALSE) + expect_is(val5, 'data.frame') + expect_equal(nrow(val5), 3) + expect_equal(names(val5), c('ID', 'h3_resolution_11', 'h3_resolution_12')) + expect_equal(val5[[1]], c(1,2,3)) + # df with other attribs + bpts_df2 <- + as.data.frame(cbind(matrix(unlist(bpts_sfc), + ncol = 2, byrow = T), 'ID' = seq(3))) + val6 <- point_to_cell(bpts_df2, res = c(11, 12), simple = FALSE) + expect_equal(val5, val6) +}) - -test_that('cell_to_point returns an appropriate dataset', - c( - expect_error(cell_to_point(h3_address = 'whereami')), - val1 <- cell_to_point('8abe8d12acaffff'), - val2 <- cell_to_point('8abe8d12acaffff', simple = FALSE), - expect_is(val1, 'sfc_POINT'), - expect_equal(val1, val2$geometry), - # lock in in case underlying fn gets fixed - expect_equal(val1[[1]][1], 153.0239032), - expect_equal(val1[[1]][2], -27.46852938), - expect_is(val2, 'sf'), - expect_equal(names(val2), c('h3_address', 'geometry')) - )) +test_that('cell_to_point returns an appropriate dataset', { + expect_error(cell_to_point(h3_address = 'whereami')) + val1 <- cell_to_point('8abe8d12acaffff') + val2 <- cell_to_point('8abe8d12acaffff', simple = FALSE) + expect_is(val1, 'sfc_POINT') + expect_equal(val1, val2$geometry) + # lock in in case underlying fn gets fixed + expect_equal(val1[[1]][1], 153.0239032) + expect_equal(val1[[1]][2], -27.46852938) + expect_is(val2, 'sf') + expect_equal(names(val2), c('h3_address', 'geometry')) +}) # cell_to_polygon -test_that('cell_to_polygon returns an appropriate dataset', - c( - expect_error(cell_to_polygon(input = 'whereami')), - val1 <- cell_to_polygon('8abe8d12acaffff'), - val2 <- cell_to_polygon('8abe8d12acaffff', simple = FALSE), - # xy checks - expect_equal(val1[[1]][[1]][1,1], 153.0245835), - expect_equal(val1[[1]][[1]][1,2], -27.46896347), - expect_is(val1, 'sfc_POLYGON'), - expect_is(val2, 'sf'), - expect_equal(as.character(sf::st_geometry_type(val2)), 'POLYGON'), - expect_identical(val1, val2$geometry), - expect_equal(names(val2), c('h3_address', 'geometry')), - expect_equal(sf::st_crs(val1)$epsg, 4326), - # data frame inputs - df <- data.frame('h3_resolution_7' = c('8abe8d12acaffff', - '8abe8d12acaffff', - '8abe8d12acaffff'), - 'ID' = seq(3)), - val3 <- cell_to_polygon(df), - expect_is(val3, 'sfc_POLYGON'), - expect_equal(as.character(sf::st_geometry_type(val3[[1]])), 'POLYGON'), - val4 <- cell_to_polygon(df, simple = FALSE), - expect_is(val4, 'sf'), - expect_equal(val3, val4$geometry), - expect_error(cell_to_polygon(df[ , c(2,1)], simple = FALSE)) - ) -) +test_that('cell_to_polygon returns an appropriate dataset', { + expect_error(cell_to_polygon(input = 'whereami')) + val1 <- cell_to_polygon('8abe8d12acaffff') + val2 <- cell_to_polygon('8abe8d12acaffff', simple = FALSE) + # xy checks + expect_equal(val1[[1]][[1]][1,1], 153.0245835) + expect_equal(val1[[1]][[1]][1,2], -27.46896347) + expect_is(val1, 'sfc_POLYGON') + expect_is(val2, 'sf') + expect_equal(as.character(sf::st_geometry_type(val2)), 'POLYGON') + expect_identical(val1, val2$geometry) + expect_equal(names(val2), c('h3_address', 'geometry')) + expect_equal(sf::st_crs(val1)$epsg, 4326) + # data frame inputs + df <- data.frame('h3_resolution_7' = c('8abe8d12acaffff', + '8abe8d12acaffff', + '8abe8d12acaffff'), + 'ID' = seq(3)) + val3 <- cell_to_polygon(df) + expect_is(val3, 'sfc_POLYGON') + expect_equal(as.character(sf::st_geometry_type(val3[[1]])), 'POLYGON') + val4 <- cell_to_polygon(df, simple = FALSE) + expect_is(val4, 'sf') + expect_equal(val3, val4$geometry) + expect_error(cell_to_polygon(df[ , c(2,1)], simple = FALSE)) +}) -test_that( - 'get_res0 returns correctly', - c( - res0 <- get_res0(), - expect_is(res0, 'character'), - expect_equal(length(res0), 122), - expect_equal(res0[1], '8001fffffffffff') - ) -) +test_that('get_res0 returns correctly', { + res0 <- get_res0() + expect_is(res0, 'character') + expect_equal(length(res0), 122) + expect_equal(res0[1], '8001fffffffffff') +}) # cell_to_splitlong -test_that( - 'cell_to_splitlong returns correctly', - c( - val1 <- cell_to_splitlong('8abe8d12acaffff'), - val2 <- cell_to_splitlong('8abe8d12acaffff', simple = FALSE), - val3 <- cell_to_splitlong(c('86be8d12fffffff', '86be8d107ffffff', '86be8d127ffffff')), - val4 <- cell_to_splitlong(c('86be8d12fffffff', '86be8d107ffffff', '86be8d127ffffff'), simple = FALSE), - expect_is(val1, 'list'), - expect_is(val2, 'data.frame'), - expect_is(val3, 'list'), - expect_is(val4, 'data.frame'), - expect_length(val1, 1), - expect_length(val1[[1]], 2), - expect_equal(val1[[1]][1], 717946879), - expect_equal(val1[[1]][2], 145483985), - expect_equal(nrow(val2), 1), - expect_equal(val1[[1]][1], val2$split_lower), - expect_length(val3, 3), - expect_length(val3[[2]], 2), - expect_equal(val3[[1]][1], 805306367), - expect_equal(val3[[3]][1], 671088639), - expect_equal(nrow(val4), 3), - expect_equal(val3[[1]][1], val4$split_lower[1]), - expect_equal(val3[[3]][1], val4$split_lower[3]) - ) -) +test_that('cell_to_splitlong returns correctly', { + val1 <- cell_to_splitlong('8abe8d12acaffff') + val2 <- cell_to_splitlong('8abe8d12acaffff', simple = FALSE) + val3 <- cell_to_splitlong(c('86be8d12fffffff', '86be8d107ffffff', '86be8d127ffffff')) + val4 <- cell_to_splitlong(c('86be8d12fffffff', '86be8d107ffffff', '86be8d127ffffff'), simple = FALSE) + expect_is(val1, 'list') + expect_is(val2, 'data.frame') + expect_is(val3, 'list') + expect_is(val4, 'data.frame') + expect_length(val1, 1) + expect_length(val1[[1]], 2) + expect_equal(val1[[1]][1], 717946879) + expect_equal(val1[[1]][2], 145483985) + expect_equal(nrow(val2), 1) + expect_equal(val1[[1]][1], val2$split_lower) + expect_length(val3, 3) + expect_length(val3[[2]], 2) + expect_equal(val3[[1]][1], 805306367) + expect_equal(val3[[3]][1], 671088639) + expect_equal(nrow(val4), 3) + expect_equal(val3[[1]][1], val4$split_lower[1]) + expect_equal(val3[[3]][1], val4$split_lower[3]) +}) # splitlong_to_cell -test_that( - 'splitlong_to_cell returns correctly', - c( - val1 <- cell_to_splitlong('8abe8d12acaffff'), - val2 <- splitlong_to_cell(val1[[1]][1], val1[[1]][2]), - expect_error(splitlong_to_cell('8abe8d12acaffff')), - expect_equal(val2, '8abe8d12acaffff') - ) -) +test_that('splitlong_to_cell returns correctly', { + val1 <- cell_to_splitlong('8abe8d12acaffff') + val2 <- splitlong_to_cell(val1[[1]][1], val1[[1]][2]) + expect_error(splitlong_to_cell('8abe8d12acaffff')) + expect_equal(val2, '8abe8d12acaffff') +}) # degs to rads -test_that( - 'degs_to_rads returns correctly and consistently', - c( - val1 <- degs_to_rads(120), - val2 <- degs_to_rads(120, 'h3'), - expect_equal(val1, val2), - expect_equal(val1, 2.094395102393195262636), - expect_error(degs_to_rads(120, 'C++')) - ) -) +test_that('degs_to_rads returns correctly and consistently', { + val1 <- degs_to_rads(120) + val2 <- degs_to_rads(120, 'h3') + expect_equal(val1, val2) + expect_equal(val1, 2.094395102393195262636) + expect_error(degs_to_rads(120, 'C++')) +}) -test_that( - 'rads_to_degs returns correctly and consistently', - c( - val1 <- rads_to_degs(2.09), - val2 <- rads_to_degs(2.09, 'h3'), - expect_equal(val1, val2), - expect_equal(val1, 119.7481791823420564924), - expect_error(rads_to_degs(2.09, 'C++')) - ) -) +test_that('rads_to_degs returns correctly and consistently', { + val1 <- rads_to_degs(2.09) + val2 <- rads_to_degs(2.09, 'h3') + expect_equal(val1, val2) + expect_equal(val1, 119.7481791823420564924) + expect_error(rads_to_degs(2.09, 'C++')) +}) -test_that( - 'cell_to_childpos returns correctly', - c( - val1 <- cell_to_childpos('872830b82ffffff', c(3,4,5,6)), - val2 <- cell_to_childpos('872830b82ffffff', c(3,4,5,6), simple = FALSE), - expect_equal(val1, val2$child_pos), - expect_equal(val1, c(2011, 296, 2, 2)), - expect_error(cell_to_childpos('872830b82ffffff', 8)), - expect_error(cell_to_childpos('lol', 8)), - expect_error(cell_to_childpos('872830b82ffffff', 25)) - ) -) +test_that('cell_to_childpos returns correctly', { + val1 <- cell_to_childpos('872830b82ffffff', c(3,4,5,6)) + val2 <- cell_to_childpos('872830b82ffffff', c(3,4,5,6), simple = FALSE) + expect_equal(val1, val2$child_pos) + expect_equal(val1, c(2011, 296, 2, 2)) + expect_error(cell_to_childpos('872830b82ffffff', 8)) + expect_error(cell_to_childpos('lol', 8)) + expect_error(cell_to_childpos('872830b82ffffff', 25)) +}) -test_that( - 'childpos_to_cell returns correctly', - c( - val1 <- childpos_to_cell(0, '872830b82ffffff', 9), - val2 <- childpos_to_cell(0, '872830b82ffffff', 9, simple = FALSE), - expect_equal(val1, val2$child_cell), - expect_equal(val1, '892830b8203ffff'), - expect_error(childpos_to_cell(0, '872830b82ffffff', 6)), - expect_error(childpos_to_cell(0, 'lol', 9)), - expect_error(childpos_to_cell(0, '872830b82ffffff', 25)) - ) -) +test_that('childpos_to_cell returns correctly', { + val1 <- childpos_to_cell(0, '872830b82ffffff', 9) + val2 <- childpos_to_cell(0, '872830b82ffffff', 9, simple = FALSE) + expect_equal(val1, val2$child_cell) + expect_equal(val1, '892830b8203ffff') + expect_error(childpos_to_cell(0, '872830b82ffffff', 6)) + expect_error(childpos_to_cell(0, 'lol', 9)) + expect_error(childpos_to_cell(0, '872830b82ffffff', 25)) +}) -test_that( - 'cell_to_children_size returns correctly', - c( - val1 <- cell_to_children_size('872830b82ffffff', c(8,9,10,11)), - val2 <- cell_to_children_size('872830b82ffffff', c(8,9,10,11), simple = FALSE), - expect_equal(val1, val2$child_size), - expect_equal(val1, c(7, 49, 343, 2401)), - expect_error(cell_to_children_size('872830b82ffffff', 6)), - expect_error(cell_to_children_size('lol', 9)), - expect_error(cell_to_children_size('872830b82ffffff', 25)) - ) -) +test_that('cell_to_children_size returns correctly', { + val1 <- cell_to_children_size('872830b82ffffff', c(8,9,10,11)) + val2 <- cell_to_children_size('872830b82ffffff', c(8,9,10,11), simple = FALSE) + expect_equal(val1, val2$child_size) + expect_equal(val1, c(7, 49, 343, 2401)) + expect_error(cell_to_children_size('872830b82ffffff', 6)) + expect_error(cell_to_children_size('lol', 9)) + expect_error(cell_to_children_size('872830b82ffffff', 25)) +}) diff --git a/tests/testthat/test_custom_functions.R b/tests/testthat/test_custom_functions.R index 7293c3e..4fdcbcb 100644 --- a/tests/testthat/test_custom_functions.R +++ b/tests/testthat/test_custom_functions.R @@ -1,54 +1,48 @@ context('H3 custom functions') -test_that( - 'cell_to_line returns correctly - vector', - c(path <- c("8abe8d12adaffff", "8abe8d10536ffff", "8abe8d10526ffff", - "8abe8d12a52ffff", "8abe8d12aceffff", "8abe8d12ac2ffff"), - val1 <- cell_to_line(path), - val2 <- cell_to_line(path, simple = FALSE), - expect_is(val1, 'sfc_LINESTRING'), - expect_length(val1, 1), - expect_is(val2, 'sf'), - expect_equal(ncol(val2), 2), - expect_type(val2$input, 'list'), - expect_is(val2$geometry, 'sfc_LINESTRING') - ) -) +test_that('cell_to_line returns correctly - vector', { + path <- c("8abe8d12adaffff", "8abe8d10536ffff", "8abe8d10526ffff", + "8abe8d12a52ffff", "8abe8d12aceffff", "8abe8d12ac2ffff") + val1 <- cell_to_line(path) + val2 <- cell_to_line(path, simple = FALSE) + expect_is(val1, 'sfc_LINESTRING') + expect_length(val1, 1) + expect_is(val2, 'sf') + expect_equal(ncol(val2), 2) + expect_type(val2$input, 'list') + expect_is(val2$geometry, 'sfc_LINESTRING') +}) -test_that( - 'cell_to_line returns correctly - list of vectors', - c(path <- c("8abe8d12adaffff", "8abe8d10536ffff", "8abe8d10526ffff", - "8abe8d12a52ffff", "8abe8d12aceffff", "8abe8d12ac2ffff"), - paths <- list(path, path, path), - val1 <- cell_to_line(paths), - val2 <- cell_to_line(paths, simple = FALSE), - expect_is(val1, 'sfc_LINESTRING'), - expect_length(val1, 3), - expect_is(val2, 'sf'), - expect_equal(ncol(val2), 2), - expect_equal(nrow(val2), 3), - expect_type(val2$input, 'list'), - expect_is(val2$geometry, 'sfc_LINESTRING') - ) -) +test_that('cell_to_line returns correctly - list of vectors', { + path <- c("8abe8d12adaffff", "8abe8d10536ffff", "8abe8d10526ffff", + "8abe8d12a52ffff", "8abe8d12aceffff", "8abe8d12ac2ffff") + paths <- list(path, path, path) + val1 <- cell_to_line(paths) + val2 <- cell_to_line(paths, simple = FALSE) + expect_is(val1, 'sfc_LINESTRING') + expect_length(val1, 3) + expect_is(val2, 'sf') + expect_equal(ncol(val2), 2) + expect_equal(nrow(val2), 3) + expect_type(val2$input, 'list') + expect_is(val2$geometry, 'sfc_LINESTRING') +}) -test_that( - 'cell_to_line returns correctly - data.frame with list-column', - c(library(sf), - brisbane_hex_10 <- cell_to_polygon(input = '8abe8d12acaffff'), - hex_sample <- get_disk_list('8abe8d12acaffff', 4)[[1]][[4]][seq(1,18,3)], - hex_sample_polys <- cell_to_polygon(hex_sample), - paths <- grid_path(rep('8abe8d12acaffff', 6), hex_sample), - paths_df <- data.frame('ID' = seq(6), 'paths' = I(paths)), - val1 <- cell_to_line(paths_df), - val2 <- cell_to_line(paths_df, simple = FALSE), - expect_is(val1, 'sfc_LINESTRING'), - expect_length(val1, 6), - expect_is(val2, 'sf'), - expect_equal(ncol(val2), 3), - expect_equal(nrow(val2), 6), - ins <- sf::st_set_geometry(val2, NULL), # wierd behav when lib() missing - expect_identical(ins, paths_df), - expect_is(val2$geometry, 'sfc_LINESTRING') - ) -) +test_that('cell_to_line returns correctly - data.frame with list-column', { + library(sf) + brisbane_hex_10 <- cell_to_polygon(input = '8abe8d12acaffff') + hex_sample <- get_disk_list('8abe8d12acaffff', 4)[[1]][[4]][seq(1,18,3)] + hex_sample_polys <- cell_to_polygon(hex_sample) + paths <- grid_path(rep('8abe8d12acaffff', 6), hex_sample) + paths_df <- data.frame('ID' = seq(6), 'paths' = I(paths)) + val1 <- cell_to_line(paths_df) + val2 <- cell_to_line(paths_df, simple = FALSE) + expect_is(val1, 'sfc_LINESTRING') + expect_length(val1, 6) + expect_is(val2, 'sf') + expect_equal(ncol(val2), 3) + expect_equal(nrow(val2), 6) + ins <- sf::st_set_geometry(val2, NULL) # wierd behav when lib() missing + expect_identical(ins, paths_df) + expect_is(val2$geometry, 'sfc_LINESTRING') +}) diff --git a/tests/testthat/test_helpers.R b/tests/testthat/test_helpers.R index 7347772..22516e8 100644 --- a/tests/testthat/test_helpers.R +++ b/tests/testthat/test_helpers.R @@ -1,77 +1,72 @@ context('prep_for_x methods') +test_that('prep_for_pt2cell.sf works', { + library(sf) + nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) + nc1 <- nc[1, ] + expect_error(h3jsr:::prep_for_pt2cell(nc1)) + no_crs_point <- sf::st_sf('geometry' = sf::st_sfc(sf::st_point(c(153,-27)))) + expect_message(h3jsr:::prep_for_pt2cell(no_crs_point)) + v1 <- h3jsr:::prep_for_pt2cell(no_crs_point) + expect_is(v1, 'matrix') +}) -test_that('prep_for_pt2cell.sf works', - c(library(sf), - nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE), - nc1 <- nc[1, ], - expect_error(h3jsr:::prep_for_pt2cell(nc1)), - no_crs_point <- sf::st_sf('geometry' = sf::st_sfc(sf::st_point(c(153,-27)))), - expect_message(h3jsr:::prep_for_pt2cell(no_crs_point)), - v1 <- h3jsr:::prep_for_pt2cell(no_crs_point), - expect_is(v1, 'matrix') - )) +test_that('prep_for_pt2cell.sfc works', { + library(sf) + nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) + nc1 <- sf::st_geometry(nc[1, ]) + expect_error(h3jsr:::prep_for_pt2cell(nc1)) + no_crs_point <- sf::st_sfc(sf::st_point(c(153,-27))) + expect_message(h3jsr:::prep_for_pt2cell(no_crs_point)) + v1 <- h3jsr:::prep_for_pt2cell(no_crs_point) + expect_is(v1, 'matrix') +}) -test_that('prep_for_pt2cell.sfc works', - c(library(sf), - nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE), - nc1 <- sf::st_geometry(nc[1, ]), - expect_error(h3jsr:::prep_for_pt2cell(nc1)), - no_crs_point <- sf::st_sfc(sf::st_point(c(153,-27))), - expect_message(h3jsr:::prep_for_pt2cell(no_crs_point)), - v1 <- h3jsr:::prep_for_pt2cell(no_crs_point), - expect_is(v1, 'matrix') - )) +test_that('prep_for_pt2cell.sfg works', { + library(sf) + nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) + nc1 <- sf::st_geometry(nc[1, ])[[1]] + expect_error(h3jsr:::prep_for_pt2cell(nc1)) +}) -test_that('prep_for_pt2cell.sfg works', - c(library(sf), - nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE), - nc1 <- sf::st_geometry(nc[1, ])[[1]], - expect_error(h3jsr:::prep_for_pt2cell(nc1)) - )) +test_that('prep_for_polyfill.sf works', { + library(sf) + no_crs_poly <- + sf::st_sf('geometry' = sf::st_sfc( + sf::st_polygon(list(matrix(c(150, -30, + 151, -30, + 151, -35, + 150, -35, + 150, -30), ncol = 2, byrow = T))))) + expect_message(h3jsr:::prep_for_polyfill(no_crs_poly)) + v1 <- h3jsr:::prep_for_polyfill(no_crs_poly) + expect_is(v1, 'geojson') +}) -test_that('prep_for_polyfill.sf works', - c(library(sf), - no_crs_poly <- - sf::st_sf('geometry' = sf::st_sfc( - sf::st_polygon(list(matrix(c(150, -30, - 151, -30, - 151, -35, - 150, -35, - 150, -30), ncol = 2, byrow = T))))), - expect_message(h3jsr:::prep_for_polyfill(no_crs_poly)), - v1 <- h3jsr:::prep_for_polyfill(no_crs_poly), - expect_is(v1, 'geojson') - )) +test_that('prep_for_polyfill.sf works', { + library(sf) + no_crs_poly <- + sf::st_sfc( + sf::st_polygon(list(matrix(c(150, -30, + 151, -30, + 151, -35, + 150, -35, + 150, -30), ncol = 2, byrow = T)))) + expect_message(h3jsr:::prep_for_polyfill(no_crs_poly)) + v1 <- h3jsr:::prep_for_polyfill(no_crs_poly) + expect_is(v1, 'geojson') +}) -test_that('prep_for_polyfill.sf works', - c(library(sf), - no_crs_poly <- - sf::st_sfc( - sf::st_polygon(list(matrix(c(150, -30, - 151, -30, - 151, -35, - 150, -35, - 150, -30), ncol = 2, byrow = T)))), - expect_message(h3jsr:::prep_for_polyfill(no_crs_poly)), - v1 <- h3jsr:::prep_for_polyfill(no_crs_poly), - expect_is(v1, 'geojson') - )) - - -test_that( - 'prepped geojson returns correctly', - c( - nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE), - nc1 <- nc[1, ], - val1 <- h3jsr:::prep_for_polyfill(nc1), - val2 <- h3jsr:::prep_for_polyfill(sf::st_geometry(nc1)), - nc1_84 <- sf::st_transform(nc1, 4326), - val3 <- - h3jsr:::prep_for_polyfill(sf::st_geometry(nc1_84)[[1]]), - expect_is(val1, 'geojson'), - expect_equal(val1, val2), - expect_equal(val1, val3) - ) -) +test_that('prepped geojson returns correctly', { + nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) + nc1 <- nc[1, ] + val1 <- h3jsr:::prep_for_polyfill(nc1) + val2 <- h3jsr:::prep_for_polyfill(sf::st_geometry(nc1)) + nc1_84 <- sf::st_transform(nc1, 4326) + val3 <- + h3jsr:::prep_for_polyfill(sf::st_geometry(nc1_84)[[1]]) + expect_is(val1, 'geojson') + expect_equal(val1, val2) + expect_equal(val1, val3) +}) diff --git a/tests/testthat/test_info_utils.R b/tests/testthat/test_info_utils.R index c91b1ab..b46ec51 100644 --- a/tests/testthat/test_info_utils.R +++ b/tests/testthat/test_info_utils.R @@ -1,113 +1,91 @@ context('info utils') -test_that( - 'res_area returns correctly', - c( - expect_error(res_area(8, 'cubic furlongs')), - expect_error(res_area(25, 'm2')), - expect_equal(res_area(14, 'm2'), 6.26718113532432230528), - expect_equal(res_area(7, 'km2'), 5.161293359717190831759), - expect_equal(res_area(14, 'm2', fast = FALSE)$area, 6.26718113532432230528), - expect_equal(res_area(7, 'km2', fast = FALSE)$area, 5.161293359717190831759) - ) -) +test_that('res_area returns correctly', { + expect_error(res_area(8, 'cubic furlongs')) + expect_error(res_area(25, 'm2')) + expect_equal(res_area(14, 'm2'), 6.26718113532432230528) + expect_equal(res_area(7, 'km2'), 5.161293359717190831759) + expect_equal(res_area(14, 'm2', fast = FALSE)$area, 6.26718113532432230528) + expect_equal(res_area(7, 'km2', fast = FALSE)$area, 5.161293359717190831759) +}) -test_that( - 'res_edgelen returns correctly', - c( - expect_error(res_length(8, 'cubic furlongs')), - expect_error(res_length(25, 'm')), - expect_equal(res_length(14, 'm'), 1.348574562000000032214), - expect_equal(res_length(7, 'km'), 1.220629758999999925351), - expect_equal(res_length(14, 'm', fast = FALSE)$edgelen, 1.348574562000000032214), - expect_equal(res_length(7, 'km', fast = FALSE)$edgelen, 1.220629758999999925351) - ) -) +test_that('res_edgelen returns correctly', { + expect_error(res_length(8, 'cubic furlongs')) + expect_error(res_length(25, 'm')) + expect_equal(res_length(14, 'm'), 1.348574562000000032214) + expect_equal(res_length(7, 'km'), 1.220629758999999925351) + expect_equal(res_length(14, 'm', fast = FALSE)$edgelen, 1.348574562000000032214) + expect_equal(res_length(7, 'km', fast = FALSE)$edgelen, 1.220629758999999925351) +}) -test_that( - 'res_cendist returns correctly', - c( - expect_error(res_cendist(8, 'cubic furlongs')), - expect_error(res_cendist(25, 'm')), - expect_equal(res_cendist(14, 'm'), 2.335799659178945386628), - expect_equal(res_cendist(7, 'km'), 2.114192759818553923878), - expect_equal(res_cendist(14, 'm', fast = FALSE)$cendist, 2.335799659178945386628), - expect_equal(res_cendist(7, 'km', fast = FALSE)$cendist, 2.114192759818553923878) - ) -) +test_that('res_cendist returns correctly', { + expect_error(res_cendist(8, 'cubic furlongs')) + expect_error(res_cendist(25, 'm')) + expect_equal(res_cendist(14, 'm'), 2.335799659178945386628) + expect_equal(res_cendist(7, 'km'), 2.114192759818553923878) + expect_equal(res_cendist(14, 'm', fast = FALSE)$cendist, 2.335799659178945386628) + expect_equal(res_cendist(7, 'km', fast = FALSE)$cendist, 2.114192759818553923878) +}) -test_that( - 'num_cells returns correctly', - c( - expect_error(num_cells(25)), - expect_equal(num_cells(14), 81386768741882), - expect_equal(num_cells(3), 41162), - expect_equal(num_cells(14, fast = FALSE)$total_unique_indexes, - 81386768741882), - expect_equal(num_cells(3, fast = FALSE)$total_unique_indexes, 41162) - ) -) +test_that('num_cells returns correctly', { + expect_error(num_cells(25)) + expect_equal(num_cells(14), 81386768741882) + expect_equal(num_cells(3), 41162) + expect_equal(num_cells(14, fast = FALSE)$total_unique_indexes, + 81386768741882) + expect_equal(num_cells(3, fast = FALSE)$total_unique_indexes, 41162) +}) -test_that( - 'get_gcdist performs as expected', - c( - nc <- st_read(system.file("shape/nc.shp", package="sf")), - pt1 <- sf::st_centroid(nc[1:10, ]), - pt2 <- sf::st_centroid(nc[91:100, ]), - val1 <- get_gcdist(pt1[1,], pt2[1,]), - val2 <- get_gcdist(pt1, pt2), - val_2a <- get_gcdist(pt1, pt2, 'km'), - expect_equal(val_2a * 1000, val2), - val3 <- get_gcdist(pt1[1,], pt2[1,], simple = FALSE), - val4 <- get_gcdist(pt1, pt2, simple = FALSE), - expect_equal(val3, val4[1,]), - expect_is(val3, 'data.frame'), - expect_error(get_gcdist(pt1, pt2, 'furlongs')), - expect_error(get_gcdist(pt1[1,], pt2)), - val5 <- get_gcdist(pt1[1, ], pt1[1, ]), - expect_equal(val5, 0) - ) +test_that('get_gcdist performs as expected', { + nc <- st_read(system.file("shape/nc.shp", package="sf")) + pt1 <- sf::st_centroid(nc[1:10, ]) + pt2 <- sf::st_centroid(nc[91:100, ]) + val1 <- get_gcdist(pt1[1,], pt2[1,]) + val2 <- get_gcdist(pt1, pt2) + val_2a <- get_gcdist(pt1, pt2, 'km') + expect_equal(val_2a * 1000, val2) + val3 <- get_gcdist(pt1[1,], pt2[1,], simple = FALSE) + val4 <- get_gcdist(pt1, pt2, simple = FALSE) + expect_equal(val3, val4[1,]) + expect_is(val3, 'data.frame') + expect_error(get_gcdist(pt1, pt2, 'furlongs')) + expect_error(get_gcdist(pt1[1,], pt2)) + val5 <- get_gcdist(pt1[1, ], pt1[1, ]) + expect_equal(val5, 0) +}) -) +test_that('cell_area performs as expected', { + val1 <- cell_area(h3_address = '8abe8d12acaffff') + val2 <- cell_area(h3_address = '8abe8d12acaffff', simple = FALSE) + val3 <- cell_area(h3_address = '8abe8d12acaffff', units = 'km2') + val4 <- cell_area(h3_address = '8abe8d12acaffff', simple = FALSE, units = 'km2') + expect_equal(val1, 17753.904855348257) + expect_equal(val3 * 1000000, val1) + expect_equal(val2[1, 2], 17753.904855348257) + expect_equal(val4[1, 2] * 1000000, val2[1, 2]) + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_equal(val2$area, 17753.904855348257) + expect_equal(names(val2), c('h3_address', 'area_m2')) + expect_equal(names(val4), c('h3_address', 'area_km2')) +}) -test_that( - 'cell_area performs as expected', - c( - val1 <- cell_area(h3_address = '8abe8d12acaffff'), - val2 <- cell_area(h3_address = '8abe8d12acaffff', simple = FALSE), - val3 <- cell_area(h3_address = '8abe8d12acaffff', units = 'km2'), - val4 <- cell_area(h3_address = '8abe8d12acaffff', simple = FALSE, units = 'km2'), - expect_equal(val1, 17753.904855348257), - expect_equal(val3 * 1000000, val1), - expect_equal(val2[1, 2], 17753.904855348257), - expect_equal(val4[1, 2] * 1000000, val2[1, 2]), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_equal(val2$area, 17753.904855348257), - expect_equal(names(val2), c('h3_address', 'area_m2')), - expect_equal(names(val4), c('h3_address', 'area_km2')) - ) -) - -test_that( - 'edge_length performs as expected', - c( - val1 <- edge_length(h3_edge = '166be8d12fffffff'), - val2 <- edge_length(h3_edge = '166be8d12fffffff', simple = FALSE), - val3 <- edge_length(h3_edge = '166be8d12fffffff', units = 'km'), - val4 <- edge_length(h3_edge = '166be8d12fffffff', simple = FALSE, units = 'km'), - val5 <- edge_length(h3_edge = '166be8d12fffffff', units = 'rads'), - val6 <- edge_length(h3_edge = '166be8d12fffffff', simple = FALSE, units = 'rads'), - expect_equal(val1, 4037.6871751936487), - expect_equal(val1 / 1000, val3), - expect_equal(val5 * 6371.007180918475, val3), # note hardcoded mean earth radius used here - expect_equal(val2[1, 2], 4037.6871751936487), - expect_equal(val4[1, 2] * 1000, val2[1, 2]), - expect_is(val2, 'data.frame'), - expect_is(val2$h3_address, 'character'), - expect_equal(val2$length_m, 4037.6871751936487), - expect_equal(names(val2), c('h3_address', 'length_m')), - expect_equal(names(val4), c('h3_address', 'length_km')), - expect_equal(names(val6), c('h3_address', 'length_rads')) - ) -) +test_that('edge_length performs as expected', { + val1 <- edge_length(h3_edge = '166be8d12fffffff') + val2 <- edge_length(h3_edge = '166be8d12fffffff', simple = FALSE) + val3 <- edge_length(h3_edge = '166be8d12fffffff', units = 'km') + val4 <- edge_length(h3_edge = '166be8d12fffffff', simple = FALSE, units = 'km') + val5 <- edge_length(h3_edge = '166be8d12fffffff', units = 'rads') + val6 <- edge_length(h3_edge = '166be8d12fffffff', simple = FALSE, units = 'rads') + expect_equal(val1, 4037.6871751936487) + expect_equal(val1 / 1000, val3) + expect_equal(val5 * 6371.007180918475, val3) # note hardcoded mean earth radius used here + expect_equal(val2[1, 2], 4037.6871751936487) + expect_equal(val4[1, 2] * 1000, val2[1, 2]) + expect_is(val2, 'data.frame') + expect_is(val2$h3_address, 'character') + expect_equal(val2$length_m, 4037.6871751936487) + expect_equal(names(val2), c('h3_address', 'length_m')) + expect_equal(names(val4), c('h3_address', 'length_km')) + expect_equal(names(val6), c('h3_address', 'length_rads')) +}) diff --git a/tests/testthat/test_local_coords.R b/tests/testthat/test_local_coords.R index be1287d..6869452 100644 --- a/tests/testthat/test_local_coords.R +++ b/tests/testthat/test_local_coords.R @@ -1,38 +1,32 @@ context('local coordinates') -test_that( - 'get_local_ij returns correctly', - c( - expect_error(get_local_ij('whereami', 'whoami')), - expect_error(get_local_ij('86be8d12fffffff')), - expect_error(get_local_ij('86be8d12fffffff', - c('86be8d127ffffff', '86be8d107ffffff'))), - val1 <- get_local_ij('86be8d12fffffff', '86be8d127ffffff'), - val2 <- get_local_ij('86be8d12fffffff', '86be8d127ffffff', simple = FALSE), - expect_is(val1, 'matrix'), - expect_equal(dim(val1), c(1, 2)), - expect_equal(names(val2), c('origin', 'destination', 'geometry')), - expect_equal(val1[1], -87L), # note: probs unstable - expect_equal(val1[2], 36L), # note: probs unstable - expect_is(val2$geometry, 'sfc_POINT'), - expect_true(is.na(sf::st_crs(val2))) - ) -) +test_that('get_local_ij returns correctly', { + expect_error(get_local_ij('whereami', 'whoami')) + expect_error(get_local_ij('86be8d12fffffff')) + expect_error(get_local_ij('86be8d12fffffff', + c('86be8d127ffffff', '86be8d107ffffff'))) + val1 <- get_local_ij('86be8d12fffffff', '86be8d127ffffff') + val2 <- get_local_ij('86be8d12fffffff', '86be8d127ffffff', simple = FALSE) + expect_is(val1, 'matrix') + expect_equal(dim(val1), c(1, 2)) + expect_equal(names(val2), c('origin', 'destination', 'geometry')) + expect_equal(val1[1], -87L) # note: probs unstable + expect_equal(val1[2], 36L) # note: probs unstable + expect_is(val2$geometry, 'sfc_POINT') + expect_true(is.na(sf::st_crs(val2))) +}) -test_that( - 'get_local_cell returns correctly', - c( - expect_error(get_local_cell('whereami', -87L, 36L)), - expect_error(get_local_cell('86be8d12fffffff')), - val1 <- get_local_cell('86be8d12fffffff', -87L, 36L), - val2 <- get_local_cell('86be8d12fffffff', -87L, 36L, simple = FALSE), - expect_is(val1, 'character'), - expect_is(val2, 'data.frame'), - expect_length(val1, 1L), - expect_true(h3jsr::is_valid(val1)), - expect_equal(names(val2), c('origin', 'i', 'j', 'destination')), - expect_equal(dim(val2)[1], 1), - expect_equal(dim(val2)[2], 4), - expect_equal(val2$destination, '86be8d127ffffff') - ) - ) +test_that('get_local_cell returns correctly', { + expect_error(get_local_cell('whereami', -87L, 36L)) + expect_error(get_local_cell('86be8d12fffffff')) + val1 <- get_local_cell('86be8d12fffffff', -87L, 36L) + val2 <- get_local_cell('86be8d12fffffff', -87L, 36L, simple = FALSE) + expect_is(val1, 'character') + expect_is(val2, 'data.frame') + expect_length(val1, 1L) + expect_true(h3jsr::is_valid(val1)) + expect_equal(names(val2), c('origin', 'i', 'j', 'destination')) + expect_equal(dim(val2)[1], 1) + expect_equal(dim(val2)[2], 4) + expect_equal(val2$destination, '86be8d127ffffff') +}) diff --git a/tests/testthat/test_unidirectional_edges.R b/tests/testthat/test_unidirectional_edges.R index fc5ffa0..f58d759 100644 --- a/tests/testthat/test_unidirectional_edges.R +++ b/tests/testthat/test_unidirectional_edges.R @@ -1,124 +1,100 @@ context('unidirectional edges') -test_that( - 'are_neighbours returns correctly', - c( - expect_error(are_neighbours('whereami', 'whoami')), - expect_error(are_neighbours('86be8d12fffffff')), - expect_error(are_neighbours('86be8d12fffffff', - c('86be8d127ffffff', '86be8d107ffffff'))), - val1 <- are_neighbours('86be8d12fffffff', '86be8d127ffffff'), - val2 <- are_neighbours(c('86be8d12fffffff', '86be8d107ffffff', '86be8d127ffffff'), - c('86be8d127ffffff', '86be8d10fffffff', '86be8d10fffffff'), - simple = FALSE), - expect_equal(val1, TRUE), - expect_is(val2, 'data.frame'), - expect_equal(names(val2), c('origin', 'destination', 'h3_neighbours')), - expect_equal(dim(val2)[1], 3), - expect_equal(val2$h3_neighbours, c(TRUE, TRUE, FALSE)) - ) -) +test_that('are_neighbours returns correctly', { + expect_error(are_neighbours('whereami', 'whoami')) + expect_error(are_neighbours('86be8d12fffffff')) + expect_error(are_neighbours('86be8d12fffffff', + c('86be8d127ffffff', '86be8d107ffffff'))) + val1 <- are_neighbours('86be8d12fffffff', '86be8d127ffffff') + val2 <- are_neighbours(c('86be8d12fffffff', '86be8d107ffffff', '86be8d127ffffff'), + c('86be8d127ffffff', '86be8d10fffffff', '86be8d10fffffff'), + simple = FALSE) + expect_equal(val1, TRUE) + expect_is(val2, 'data.frame') + expect_equal(names(val2), c('origin', 'destination', 'h3_neighbours')) + expect_equal(dim(val2)[1], 3) + expect_equal(val2$h3_neighbours, c(TRUE, TRUE, FALSE)) +}) -test_that( - 'get_udedge returns correctly', - c( - expect_error(get_udedge('whereami', 'whoami')), - expect_error(get_udedge('86be8d12fffffff')), - expect_error(get_udedge('86be8d12fffffff', - c('86be8d127ffffff', '86be8d107ffffff'))), - val1 <- get_udedge('86be8d12fffffff', '86be8d127ffffff'), - val2 <- get_udedge(c('86be8d12fffffff', '86be8d107ffffff'), - c('86be8d127ffffff', '86be8d10fffffff'), - simple = FALSE), - expect_equal(val1, '166be8d12fffffff'), - expect_is(val2, 'data.frame'), - expect_equal(names(val2), c('origin', 'destination', 'h3_edge')), - expect_equal(dim(val2)[1], 2), - expect_equal(val2$h3_edge, c('166be8d12fffffff', '116be8d107ffffff')) - ) -) +test_that('get_udedge returns correctly', { + expect_error(get_udedge('whereami', 'whoami')) + expect_error(get_udedge('86be8d12fffffff')) + expect_error(get_udedge('86be8d12fffffff', + c('86be8d127ffffff', '86be8d107ffffff'))) + val1 <- get_udedge('86be8d12fffffff', '86be8d127ffffff') + val2 <- get_udedge(c('86be8d12fffffff', '86be8d107ffffff'), + c('86be8d127ffffff', '86be8d10fffffff'), + simple = FALSE) + expect_equal(val1, '166be8d12fffffff') + expect_is(val2, 'data.frame') + expect_equal(names(val2), c('origin', 'destination', 'h3_edge')) + expect_equal(dim(val2)[1], 2) + expect_equal(val2$h3_edge, c('166be8d12fffffff', '116be8d107ffffff')) +}) -test_that( - 'is_valid_edge returns correctly', - c( - val1 <- is_valid_edge(h3_edge = '166be8d12fffffff'), - val2 <- is_valid_edge(h3_edge = c('whereami', '166be8d12fffffff')), - val3 <- is_valid_edge(h3_edge = c('whereami', '166be8d12fffffff'), - simple = FALSE), - expect_equal(val1, TRUE), - expect_equal(val2, c(FALSE, TRUE)), - expect_is(val3, 'data.frame'), - expect_is(val3$h3_edge, 'character'), - expect_equal(val3$h3_edge_valid, c(FALSE, TRUE)) - ) -) +test_that('is_valid_edge returns correctly', { + val1 <- is_valid_edge(h3_edge = '166be8d12fffffff') + val2 <- is_valid_edge(h3_edge = c('whereami', '166be8d12fffffff')) + val3 <- is_valid_edge(h3_edge = c('whereami', '166be8d12fffffff'), + simple = FALSE) + expect_equal(val1, TRUE) + expect_equal(val2, c(FALSE, TRUE)) + expect_is(val3, 'data.frame') + expect_is(val3$h3_edge, 'character') + expect_equal(val3$h3_edge_valid, c(FALSE, TRUE)) +}) -test_that( - 'get_udorigin returns correctly', - c( - expect_error(get_udorigin('edgy')), - val1 <- get_udorigin('166be8d12fffffff'), - val2 <- get_udorigin('166be8d12fffffff', simple = FALSE), - expect_equal(val1, '86be8d12fffffff'), - expect_is(val2, 'data.frame'), - expect_equal(names(val2), c('h3_edge', 'h3_origin')), - expect_equal(val2$h3_origin, '86be8d12fffffff') - ) -) +test_that('get_udorigin returns correctly', { + expect_error(get_udorigin('edgy')) + val1 <- get_udorigin('166be8d12fffffff') + val2 <- get_udorigin('166be8d12fffffff', simple = FALSE) + expect_equal(val1, '86be8d12fffffff') + expect_is(val2, 'data.frame') + expect_equal(names(val2), c('h3_edge', 'h3_origin')) + expect_equal(val2$h3_origin, '86be8d12fffffff') +}) -test_that( - 'get_uddest returns correctly', - c( - expect_error(get_uddest('edgy')), - val1 <- get_uddest('166be8d12fffffff'), - val2 <- get_uddest('166be8d12fffffff', simple = FALSE), - expect_equal(val1, '86be8d127ffffff'), - expect_is(val2, 'data.frame'), - expect_equal(names(val2), c('h3_edge', 'h3_destination')), - expect_equal(val2$h3_destination, '86be8d127ffffff') - ) -) +test_that('get_uddest returns correctly', { + expect_error(get_uddest('edgy')) + val1 <- get_uddest('166be8d12fffffff') + val2 <- get_uddest('166be8d12fffffff', simple = FALSE) + expect_equal(val1, '86be8d127ffffff') + expect_is(val2, 'data.frame') + expect_equal(names(val2), c('h3_edge', 'h3_destination')) + expect_equal(val2$h3_destination, '86be8d127ffffff') +}) -test_that( - 'get_udends returns correctly', - c( - expect_error(get_udends('edgy')), - val1 <- get_udends('166be8d12fffffff'), - val2 <- get_udends('166be8d12fffffff', simple = FALSE), - expect_is(val1, 'list'), - expect_equal(val1[[1]][1], '86be8d12fffffff'), - expect_is(val2, 'data.frame'), - expect_equal(names(val2), c('h3_edge', 'h3_ends')), - expect_is(val2$h3_ends, 'list' ), - expect_equal(val2$h3_ends[[1]][1], '86be8d12fffffff') - ) -) +test_that('get_udends returns correctly', { + expect_error(get_udends('edgy')) + val1 <- get_udends('166be8d12fffffff') + val2 <- get_udends('166be8d12fffffff', simple = FALSE) + expect_is(val1, 'list') + expect_equal(val1[[1]][1], '86be8d12fffffff') + expect_is(val2, 'data.frame') + expect_equal(names(val2), c('h3_edge', 'h3_ends')) + expect_is(val2$h3_ends, 'list') + expect_equal(val2$h3_ends[[1]][1], '86be8d12fffffff') +}) -test_that( - 'get_udedges returns correctly', - c( - expect_error(get_udedges('whereami')), - val1 <- get_udedges(h3_address = '86be8d12fffffff'), - val2 <- get_udedges(h3_address = '86be8d12fffffff', simple = FALSE), - expect_equal(val1[[1]][1], '116be8d12fffffff'), - expect_is(val2, 'data.frame'), - expect_equal(names(val2), c('h3_address', 'h3_edges')), - expect_is(val2$h3_edges, 'list'), - expect_equal(val2$h3_edges[[1]][1], '116be8d12fffffff') - ) -) +test_that('get_udedges returns correctly', { + expect_error(get_udedges('whereami')) + val1 <- get_udedges(h3_address = '86be8d12fffffff') + val2 <- get_udedges(h3_address = '86be8d12fffffff', simple = FALSE) + expect_equal(val1[[1]][1], '116be8d12fffffff') + expect_is(val2, 'data.frame') + expect_equal(names(val2), c('h3_address', 'h3_edges')) + expect_is(val2$h3_edges, 'list') + expect_equal(val2$h3_edges[[1]][1], '116be8d12fffffff') +}) -test_that( - 'udedge_to_line returns correctly', - c( - expect_error(udedge_to_line('edgy')), - val1 <- udedge_to_line(h3_edge = '166be8d12fffffff'), - val2 <- udedge_to_line(h3_edge = '166be8d12fffffff', simple = FALSE), - expect_is(val1, 'sfc_LINESTRING'), - expect_is(val2, 'sf'), - expect_equal(sf::st_crs(val1)$epsg, 4326), - expect_equal(names(val2), c('h3_edge', 'geometry')), - expect_is(val2$geometry, 'sfc_LINESTRING'), - expect_equal(val2$h3_edge, '166be8d12fffffff') - ) -) +test_that('udedge_to_line returns correctly', { + expect_error(udedge_to_line('edgy')) + val1 <- udedge_to_line(h3_edge = '166be8d12fffffff') + val2 <- udedge_to_line(h3_edge = '166be8d12fffffff', simple = FALSE) + expect_is(val1, 'sfc_LINESTRING') + expect_is(val2, 'sf') + expect_equal(sf::st_crs(val1)$epsg, 4326) + expect_equal(names(val2), c('h3_edge', 'geometry')) + expect_is(val2$geometry, 'sfc_LINESTRING') + expect_equal(val2$h3_edge, '166be8d12fffffff') +}) diff --git a/tests/testthat/test_vertex_functions.R b/tests/testthat/test_vertex_functions.R index 65f942f..46cf3ee 100644 --- a/tests/testthat/test_vertex_functions.R +++ b/tests/testthat/test_vertex_functions.R @@ -1,53 +1,41 @@ context('vertex functions') -test_that( - 'is_valid_vertex returns correctly', - c( - expect_false(is_valid_vertex('86be8d12fffffff')), - expect_true(is_valid_vertex(h3_vertex = '25abe8d12ac87fff')) - ) -) +test_that('is_valid_vertex returns correctly', { + expect_false(is_valid_vertex('86be8d12fffffff')) + expect_true(is_valid_vertex(h3_vertex = '25abe8d12ac87fff')) +}) -test_that( - 'get_cell_vertex returns correctly', - c( - val1 <- get_cell_vertex('86be8d12fffffff', 0), - expect_error(get_cell_vertex('whatever')), - expect_error(get_cell_vertex('86be8d12fffffff', NA)), - expect_error(get_cell_vertex('86be8d12fffffff', seq(0, 5))), - expect_equal(val1, '246be8d127ffffff') - ) -) +test_that('get_cell_vertex returns correctly', { + val1 <- get_cell_vertex('86be8d12fffffff', 0) + expect_error(get_cell_vertex('whatever')) + expect_error(get_cell_vertex('86be8d12fffffff', NA)) + expect_error(get_cell_vertex('86be8d12fffffff', seq(0, 5))) + expect_equal(val1, '246be8d127ffffff') +}) -test_that( - 'get_cell_vertexes returns correctly', - c( - val1 <- get_cell_vertexes('86be8d12fffffff'), - val2 <- get_cell_vertexes('86be8d12fffffff', simple = FALSE), - expect_error(get_cell_vertexes('256be8d107ffffff')), - expect_length(val1, 1), - expect_length(val1[[1]], 6), # nb haven't checked on pentagon here - expect_equal(val1[[1]][1], '246be8d127ffffff') - ) -) +test_that('get_cell_vertexes returns correctly', { + val1 <- get_cell_vertexes('86be8d12fffffff') + val2 <- get_cell_vertexes('86be8d12fffffff', simple = FALSE) + expect_error(get_cell_vertexes('256be8d107ffffff')) + expect_length(val1, 1) + expect_length(val1[[1]], 6) # nb haven't checked on pentagon here + expect_equal(val1[[1]][1], '246be8d127ffffff') +}) -test_that( - 'vertex_to_point returns correctly', - c( - library(sf), - val1 <- vertex_to_point('256be8d107ffffff'), - val2 <- vertex_to_point('256be8d107ffffff', simple = FALSE), - val3 <- vertex_to_point(get_cell_vertexes('86be8d12fffffff')[[1]]), - val4 <- vertex_to_point(get_cell_vertexes('86be8d12fffffff')[[1]], simple = FALSE), - val5 <- cell_to_polygon('86be8d12fffffff', simple = FALSE), - val6 <- all(sapply(sf::st_intersects(val4, val5), function(i) {i == 1})), - expect_error(vertex_to_point('86be8d12fffffff')), - expect_length(val1, 1), - expect_is(val1, 'sfc_POINT'), - expect_is(val2, 'sf'), - expect_is(val3, 'sfc_POINT'), - expect_is(val4, 'sf'), - expect_true(val6), # all points intersect their parent hex - expect_equal(val1[[1]][1], 153.0433070159652118036) - ) -) +test_that('vertex_to_point returns correctly', { + library(sf) + val1 <- vertex_to_point('256be8d107ffffff') + val2 <- vertex_to_point('256be8d107ffffff', simple = FALSE) + val3 <- vertex_to_point(get_cell_vertexes('86be8d12fffffff')[[1]]) + val4 <- vertex_to_point(get_cell_vertexes('86be8d12fffffff')[[1]], simple = FALSE) + val5 <- cell_to_polygon('86be8d12fffffff', simple = FALSE) + val6 <- all(sapply(sf::st_intersects(val4, val5), function(i) {i == 1})) + expect_error(vertex_to_point('86be8d12fffffff')) + expect_length(val1, 1) + expect_is(val1, 'sfc_POINT') + expect_is(val2, 'sf') + expect_is(val3, 'sfc_POINT') + expect_is(val4, 'sf') + expect_true(val6) # all points intersect their parent hex + expect_equal(val1[[1]][1], 153.0433070159652118036) +})