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

polyfill

Get H3 cell index within a polygon


Description

This function returns all the H3 cell index within the supplied polygon geometry.

Usage

polyfill(geometry = NULL, res = NULL, simple = TRUE)

Arguments

geometry

‘sf' object of type ’POLYGON' or 'MULTIPOLYGON'.

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 an sf object containing both inputs and outputs.

Value

By default, a list of length(h3_address). Each list element contains a character vector of H3 cell indices belonging to that geometry. A result of NA indicates that no H3 cell indices of the chosen resolution are centered over the geometry.

Note

This function will be slow with a large number of polygons, and/or polygons that are large relative to the hexagon area at the chosen resolution. A message is printed to console where the total input area is (roughly) > 100000x the area of the chosen H3 resolution.

Examples

# Which level 5 H3 cell indices have centers inside County Ashe, NC?
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
nc1 <- nc[1, ]
fillers <- polyfill(geometry = nc1, res = 5)

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.