Skip to content

Instantly share code, notes, and snippets.

@stupidpupil
Last active April 22, 2024 08:41
Show Gist options
  • Save stupidpupil/cb60575c5add1b28f0146ff2802424c1 to your computer and use it in GitHub Desktop.
Save stupidpupil/cb60575c5add1b28f0146ff2802424c1 to your computer and use it in GitHub Desktop.
Get r5r running for Wales-ish
# Make sure that Java 21 is installed and available
# https://adoptium.net/?variant=openjdk21
# On a Mac, try `export JAVA_HOME=$(/usr/libexec/java_home -v 21)` before running R
library(tidyverse)
options(java.parameters = "-Xmx4G")
install.packages("r5r")
library(r5r)
dir.create("walesish_r5r/data", recursive=TRUE)
setwd("walesish_r5r")
download.file(
"https://github.com/stupidpupil/wales_ish_otp_graph/releases/latest/download/r5r_network_dat.zip",
"data/r5r_network_dat.zip")
unzip("data/r5r_network_dat.zip", exdir="data")
file.rename("data/r5r_network_dat/network.dat", "data/network.dat")
r5r_core <- r5r::setup_r5("data")
places <- tibble::tibble(
id = c(
"SA6 6NL",
"SY231ER"
),
wkt = c(
"SRID=4326;POINT(-3.935252 51.684652)",
"SRID=4326;POINT(-4.071592 52.416068)"
)
)
places <- places |>
sf::st_set_geometry(sf::st_as_sfc(places$wkt))
ttm <- r5r::travel_time_matrix(r5r_core = r5r_core,
origins = places,
destinations = places,
mode = c('WALK', 'TRANSIT'),
departure_datetime = lubridate::now(),
max_trip_duration = (48*60),
verbose = TRUE
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment