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

point_to_h3

Convert point location to H3 cell index


Description

This function takes point location data and returns a H3 cell index for each point at the chosen resolution(s).

Usage

point_to_h3(input = NULL, res = NULL, simple = TRUE)

Arguments

input

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

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 character vector where possible.

Value

  • if 'simple = TRUE' and one resolution is requested, a character vector of H3 addresses.

  • if 'simple = TRUE' and multiple resolutions are requested, a data frame of H3 addresses.

  • if 'simple = FALSE' and a matrix, sfc or sfg object is supplied, a data frame of H3 addresses.

  • if 'simple = FALSE' and a data frame or sf object with other attributes is supplied, a data frame of non-spatial attributes with new columns containing addresses for one or more H3 resolutions.

Note

While multiple resolutions can be requested for multiple points, be aware of the memory demand on large datasets.

Examples

# where is the Brisbane Town Hall at resolution 15?
bth <- sf::st_sfc(sf::st_point(c(153.023503, -27.468920)), crs = 4326)
bth_15 <- point_to_h3(bth, res = 15)

# where is it at several resolutions?
bth_many <- point_to_h3(bth, res = seq(10, 15), simple = FALSE)

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.