I've written a first draft of the function, available in r5r\r-package\tests_rafa\isochrone.R
. As it stands, the output is a POINT sf
object with all nodes the transport network and the travel time estimate between the point of interest to each node.
If we want the output to be a group of polygons, we'll need to create convex hull polygons from those points.
The funtion currently looks like this:
functionisochrone <- function(r5r_core,
origin,
destinations = NULL,
mode = "WALK",
departure_datetime = Sys.time(),
cutoffs = c(0, 15, 30, 45, 60),
max_walk_dist = Inf,
max_trip_duration = 120L,
walk_speed = 3.6,
bike_speed = 12,
max_rides = 3,
n_threads = Inf,
verbose = TRUE){
# check inputs ------------------------------------------------------------
# check cutoffs
checkmate::assert_numeric(cutoffs, lower = 0)
# get destinations ------------------------------------------------------------
# if no 'destinations' are passed, use all network nodes as destination points
if(is.null(destinations)){
network <- street_network_to_sf(r5r_core)
destinations = network[[1]]
}
# estimate travel time matrix ------------------------------------------------------------
ttm <- travel_time_matrix(r5r_core=r5r_core,
origins = origin,
destinations = destinations,
mode = mode,
departure_datetime = departure_datetime,
max_walk_dist = max_walk_dist,
max_trip_duration = max_trip_duration,
walk_speed = 3.6,
bike_speed = 12,
max_rides = 3,
n_threads = Inf,
verbose = TRUE)
# aggregate isocrhones ------------------------------------------------------------
# include 0 in cutoffs
if(min(cutoffs) >0){cutoffs <- sort(c(0, cutoffs))}
# aggregate travel-times
ttm[, isocrhones := cut(x=travel_time, breaks=cutoffs)]
# join ttm results to destinations
setDT(destinations)[, index := as.character(index)]
destinations[ttm, on=c('index' ='toId'), isocrhones := i.isocrhones]
# back to sf
destinations_sf <- st_as_sf(destinations)
return(destinations_sf)
}
reprex
library(r5r)
library(ggplot2)
# build transport network
data_path <- system.file("extdata/poa", package = "r5r")
r5r_core <- setup_r5(data_path = data_path)
# load origin/point of interest
origin <- read.csv(file.path(data_path, "poa_hexgrid.csv"))[500,]
departure_datetime <- as.POSIXct("13-03-2019 14:00:00", format = "%d-%m-%Y %H:%M:%S")
# estimate travel time matrix
iso <- isochrone(r5r_core,
origin = origin,
mode = c("WALK", "TRANSIT"),
departure_datetime = departure_datetime,
cutoffs = c(0, 15, 30, 45, 60, 75, 90, 120),
max_walk_dist = Inf,
max_trip_duration = 120L)
ggplot() +
geom_sf(data=iso, aes(color=isocrhones)) +
geom_point(data=origin, color='red', aes(x=lon, y=lat)) +
theme_minimal()
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4