Learn R Programming

h3jsr (version 1.3.1)

grid_distance: Grid distance between H3 cells

Description

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

Usage

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

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.

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.

Examples

Run this code
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])
}

Run the code above in your browser using DataLab