## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = identical(tolower(Sys.getenv("NOT_CRAN")), "true"), out.width = "100%" ) ## ----message = FALSE---------------------------------------------------------- # options(java.parameters = "-Xmx2G") # # library(r5r) # library(sf) # library(data.table) # library(ggplot2) ## ----message = FALSE---------------------------------------------------------- # # system.file returns the directory with example data inside the r5r package # # set data path to directory containing your own data if not running this example # data_path <- system.file("extdata/poa", package = "r5r") # # r5r_network <- build_network(data_path) ## ----message = FALSE---------------------------------------------------------- # # read all points in the city # points <- fread(file.path(data_path, "poa_hexgrid.csv")) # # # subset point with the geolocation of the central bus station # central_bus_stn <- points[291,] # # # isochrone intervals # time_intervals <- seq(0, 100, 10) # # # routing inputs # mode <- c("WALK", "TRANSIT") # max_walk_time <- 30 # in minutes # max_trip_duration <- 90 # in minutes # time_window <- 60 # in minutes # departure_datetime <- as.POSIXct("13-05-2019 14:00:00", # format = "%d-%m-%Y %H:%M:%S") # # # calculate travel time matrix # iso1 <- r5r::isochrone( # r5r_network, # origins = central_bus_stn, # mode = mode, # polygon_output = TRUE, # cutoffs = time_intervals, # departure_datetime = departure_datetime, # max_walk_time = max_walk_time, # max_trip_duration = max_trip_duration, # time_window = time_window, # progress = FALSE, # zoom = 10 # ) # ## ----message = FALSE---------------------------------------------------------- # head(iso1) ## ----message = FALSE---------------------------------------------------------- # # extract OSM network # street_net <- street_network_to_sf(r5r_network) # main_roads <- subset(street_net$edges, street_class %like% 'PRIMARY|SECONDARY') # # colors <- c('#ffe0a5','#ffcb69','#ffa600','#ff7c43','#f95d6a', # '#d45087','#a05195','#665191','#2f4b7c','#003f5c') # # ggplot() + # geom_sf(data = iso1, aes(fill=factor(isochrone)), color = NA, alpha = .7) + # geom_sf(data = main_roads, color = "gray55", size=0.01, alpha = 0.2) + # geom_point(data = central_bus_stn, aes(x=lon, y=lat, color='Central bus\nstation')) + # scale_fill_manual(values = rev(colors) ) + # scale_color_manual(values=c('Central bus\nstation'='black')) + # labs(fill = "Travel time\n(in minutes)", color='') + # theme_minimal() + # theme(axis.title = element_blank()) ## ----message = FALSE---------------------------------------------------------- # # calculate travel time matrix # iso2 <- r5r::isochrone( # r5r_network, # origins = central_bus_stn, # mode = mode, # polygon_output = FALSE, # cutoffs = time_intervals, # departure_datetime = departure_datetime, # max_walk_time = max_walk_time, # max_trip_duration = max_trip_duration, # time_window = time_window, # progress = FALSE # ) # # head(iso2) # ## ----message = FALSE---------------------------------------------------------- # ggplot() + # geom_sf(data = iso2, aes(color=factor(isochrone)), alpha = .7) + # scale_color_manual(values = rev(colors) ) + # geom_point(data = central_bus_stn, aes(x=lon, y=lat), color='black') + # labs(color = "Travel time\n(in minutes)", color='sadasd') + # theme_minimal() + # theme(axis.title = element_blank()) ## ----message = FALSE---------------------------------------------------------- # r5r::stop_r5(r5r_network) # rJava::.jgc(R.gc = TRUE)