Skip to content

Instantly share code, notes, and snippets.

@stupidpupil
Last active June 11, 2022 14:40
Show Gist options
  • Save stupidpupil/676d53bb88bd8a481a966e7eef6db5e6 to your computer and use it in GitHub Desktop.
Save stupidpupil/676d53bb88bd8a481a966e7eef6db5e6 to your computer and use it in GitHub Desktop.
R5R + H3 TTM
library(tidyverse)
my_h3s <- tibble(id = unlist(h3jsr::polyfill(WalesIshOTPGraph:::bounds(), 8))) %>%
rowwise() %>% mutate(
pnt = h3jsr::h3_to_point(id),
plygn = h3jsr::h3_to_polygon(id)
)
sf::st_geometry(my_h3s) <- my_h3s$pnt
options(java.parameters = "-Xmx4G")
r5r_core <- r5r::setup_r5("output")
ttm <- r5r::travel_time_matrix(
r5r_core = r5r_core,
origins = my_h3s,
destinations = my_h3s,
mode = c('WALK', 'TRANSIT'),
departure_datetime = lubridate::now(),
max_walk_dist = 3000,
max_trip_duration = (12*60),
verbose = FALSE,
breakdown = TRUE
)
sf::st_geometry(my_h3s) <- my_h3s$plygn
my_plt <- ggplot() +
geom_sf(data = my_h3s %>% left_join(ttm %>% filter(toId == "88195ab685fffff"), by=c("id"="fromId")), aes(fill=travel_time), lwd=0) +
geom_sf(data = my_h3s %>% filter(id == "88195ab685fffff"), fill='red', lwd=0) +
scale_fill_viridis_b() + theme_minimal()
ggsave("temp.png", my_plt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment