h3-r
h3-r copied to clipboard
h3 to sf helper
I think it would be useful to have a helper function to convert a tibble with many h3 indexes into a single sf object.
Presently, h3_to_geo_bounardy_sf()
works well with a vector. However it is less friendly when starting with a tibble. As such I think a helper function such as the below would be useful. See below reprex to get a sense of envisioned flow.
library(h3)
library(tidyverse)
# helper function
add_boundary <- function(data, h3_index) {
cbind(data, h3_to_geo_boundary_sf(data[[quote(h3_index)]])) %>%
sf::st_as_sf()
}
k_ring_distances("842a307ffffffff", 3) %>%
add_boundary(h3_index) %>%
ggplot(aes(fill = distance)) +
geom_sf(color = "black", lwd = 0.2) +
theme_minimal()
@JosiahParry We can use a S3 method h3_to_geo_boundary_sf.data.frame
for this.
#31