| sfc_to_cells | R Documentation |
Given a vector of sf geometries (class sfc) create a list of H3 vectors.
Each list element contains the vector of H3 cells that cover the geometry.
sfc_to_cells(x, resolution, containment = "intersect")
x |
for |
resolution |
an integer indicating the H3 cell resolution. Must be between 0 and 15 inclusive. |
containment |
default |
Note, use flatten_h3() to reduce the list to a single vector.
The Containment Mode determines if an H3 cell should be returned.
"centroid" returns every cell whose centroid are contained inside of a polygon. This is the fastest option but may not cover the entire polygon.
"boundary" this returns the cells which are completely contained by the polygon. Much of a polygon might not be covered using this approach.
"intersect" ensures that a polygon is entirely covered. If an H3 cell comes in contact with the polygon it will be returned. This is the default.
"contains" behaves the same as "intersect", but also handles the case where the geometry is being covered by a cell without intersecting with its boundaries. In such cases, the covering cell is returned.
An H3 vector.
if (interactive() && rlang::is_installed("sf")) {
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
geo <- sf::st_geometry(nc)
cells <- sfc_to_cells(geo, 5)
head(cells)
plot(flatten_h3(cells))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.