Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

h3_to_line

Convert H3 cell indexes to a line


Description

Return line geometry for a sequence of H3 cell indexes in WGS84 coordinates.

Usage

h3_to_line(input = NULL, simple = TRUE)

## S3 method for class 'data.frame'
h3_to_line(input = NULL, simple = TRUE)

## S3 method for class 'list'
h3_to_line(input = NULL, simple = TRUE)

## S3 method for class 'character'
h3_to_line(input = NULL, simple = TRUE)

Arguments

input

Character vector of 15-character indexes generated by H3, a list of such, or a data frame where the last column is a list-column of H3 cell indexes (usually the output of h3jsr::grid_path().

simple

Logical; whether to return an 'sfc_LINESTRING' object or an 'sf' data frame containing both inputs and outputs.

Value

An 'sfc_LINESTRING' object containing a line for each vector of H3 cell indexes supplied. If simple = FALSE, an 'sf' object including the input data.

Note

This function can accept any arbitrary vector of cell indexes (including cells at multiple resolutions) but results may be unexpected. It is assumed that indexes are supplied in a pre-ordered fashion.

Examples

# What is the cell index over the Brisbane Town Hall at resolution 10?
brisbane_hex_10 <- h3_to_polygon(input = '8abe8d12acaffff')

# Give me a some nearby cells
hex_sample <- get_kring_list('8abe8d12acaffff', 4)[[1]][[4]][seq(1,18,3)]
hex_sample_polys <- h3_to_polygon(hex_sample)

# find connecting paths
paths <- grid_path(rep('8abe8d12acaffff', 6), hex_sample)

# make lines
lines <- h3_to_line(paths)

## Not run: 
plot(hex_sample_polys, reset = FALSE)
plot(brisbane_hex_10, add = TRUE)
plot(lines, col = 'red', add = TRUE)

## End(Not run)

h3jsr

Access Uber's H3 Library

v1.2.2
Apache License (>= 2)
Authors
Lauren O'Brien [aut, cre] (<https://orcid.org/0000-0002-7336-2171>)
Initial release
2021-06-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.