Create H3 indices from sfc
objects, vectors of x and y coordinates, or H3 string IDs.
Usage
h3_from_xy(x, y, resolution)
h3_from_points(x, resolution)
h3_from_strings(x)
h3_to_points(x)
h3_to_vertexes(x)
# S3 method for class 'H3'
as.character(x, ...)
flatten_h3(x)
is_h3(x)
Details
h3_from_points()
: takes ansfc_POINT
object and creates a vector ofH3
cellsh3_from_strings()
: converts a character vector of cell indexes to an H3 vectorh3_from_xy()
: converts vectors ofx
andy
coordinates to anH3
vectorh3_to_points()
: converts anH3
vector to a either ansfc_POINT
object or a list ofsfg
POINT
objects.h3_to_vertexes()
: converts anH3
vector to ansfc_MULTIPOINT
object or a list ofMULTIPOINT
objects.
Examples
h3_from_xy(-90, 120, 5)
#> <H3[1]>
#> [1] 85f29383fffffff
h3_from_strings("85f29383fffffff")
#> <H3[1]>
#> [1] 85f29383fffffff
if (requireNamespace("sf")) {
# create random points
pnts <- sf::st_cast(
sf::st_sfc(
sf::st_multipoint(matrix(runif(10, max = 90), ncol = 2)),
crs = 4326
),
"POINT"
)
# convert to H3 objects
h3s <- h3_from_points(pnts, 5)
h3_to_vertexes(h3s)
h3_to_points(h3s)
}
#> Geometry set for 5 features
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 0.7605052 ymin: 15.68115 xmax: 54.05352 ymax: 78.72561
#> Geodetic CRS: WGS 84
#> POINT (54.05352 26.14981)
#> POINT (14.19107 65.93194)
#> POINT (0.7605052 69.49418)
#> POINT (42.23951 78.72561)
#> POINT (44.75921 15.68115)
h3_ids <- c("831f91fffffffff", "831fb5fffffffff", "831f94fffffffff")
flatten_h3(
list(
NULL,
h3_from_strings(h3_ids),
h3_from_strings(h3_ids[1])
)
)
#> <H3[4]>
#> [1] 831f91fffffffff 831fb5fffffffff 831f94fffffffff 831f91fffffffff