h3-r icon indicating copy to clipboard operation
h3-r copied to clipboard

h3 to sf helper

Open JosiahParry opened this issue 3 years ago • 2 comments

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()

image

JosiahParry avatar Jun 21 '21 21:06 JosiahParry

@JosiahParry We can use a S3 method h3_to_geo_boundary_sf.data.frame for this.

crazycapivara avatar Jun 22 '21 05:06 crazycapivara

#31

crazycapivara avatar Jun 22 '21 05:06 crazycapivara