UrbanAnalyst / gtfsrouter

Routing and analysis engine for GTFS (General Transit Feed Specification) data
https://urbananalyst.github.io/gtfsrouter/
80 stars 17 forks source link

no results when calculating gtfs_traveltimes() #100

Closed viajerus closed 1 year ago

viajerus commented 1 year ago

Hello, I am trying to get the traveltimes for a station located in a very busy area (Mannheim, DE). Although I have selected a peak hour, I don't get any results at all (or error).

This is my reprex:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(gtfsrouter)

url <- "https://www.nvbw.de/fileadmin/user_upload/service/open_data/fahrplandaten_ohne_liniennetz/bwgesamt.zip"
td = tempdir()
filename = tempfile(tmpdir=td, fileext=".zip")
download.file(url, filename)

gtfs <- extract_gtfs (filename)
#> ▶ Unzipping GTFS archive
#> ✔ Unzipped GTFS archive
#> ▶ Extracting GTFS feed✔ Extracted GTFS feed 
#> ▶ Converting stop times to seconds✔ Converted stop times to seconds 
#> ▶ Converting transfer times to seconds✔ Converted transfer times to seconds

gtfs <- 
  gtfs_transfer_table(
    gtfs,
    d_limit = 200,
    min_transfer_time = 240,
    network = NULL,
    network_times = FALSE,
    quiet = FALSE
  )

from <- "de:08222:2569:0:RiW"
start_times <- 8 * 3600 + c (0, 60) * 60 # 8:00-9:00

res <- gtfs_traveltimes (gtfs, from, start_times, minimise_transfers=TRUE, from_is_id = T, max_traveltime=1200)
#> Day not specified; extracting timetable for thursday

res %>% dplyr::arrange(duration)
#> [1] start_time duration   ntransfers stop_id    stop_name  stop_lon   stop_lat  
#> <0 rows> (or 0-length row.names)

Created on 2023-03-30 with reprex v2.0.2.9000

I have also tried to build a timetable before calling gtfs_traveltimes(), but then I get the following error.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(gtfsrouter)

url <- "https://www.nvbw.de/fileadmin/user_upload/service/open_data/fahrplandaten_ohne_liniennetz/bwgesamt.zip"
td = tempdir()
filename = tempfile(tmpdir=td, fileext=".zip")
download.file(url, filename)

gtfs <- extract_gtfs (filename)
#> ▶ Unzipping GTFS archive
#> ✔ Unzipped GTFS archive
#> ▶ Extracting GTFS feed✔ Extracted GTFS feed 
#> ▶ Converting stop times to seconds✔ Converted stop times to seconds 
#> ▶ Converting transfer times to seconds✔ Converted transfer times to seconds

gtfs <- gtfs_timetable (gtfs, date = 20230215)

t <- gtfs$timetable

gtfs <- 
  gtfs_transfer_table(
    gtfs,
    d_limit = 200,
    min_transfer_time = 240,
    network = NULL,
    network_times = FALSE,
    quiet = FALSE
  )

from <- "de:08222:2569:0:RiW"
start_times <- 8 * 3600 + c (0, 60) * 60 # 8:00-9:00

res <- gtfs_traveltimes (gtfs, from, start_times, minimise_transfers=TRUE, from_is_id = T, max_traveltime=1200)
#> Error in eval(expr, envir, enclos): Not compatible with requested type: [type=character; target=double].

res %>% dplyr::arrange(duration)
#> Error in dplyr::arrange(., duration): object 'res' not found

Created on 2023-03-30 with reprex v2.0.2.9000

Am I missing something?

mpadge commented 1 year ago

Am I missing something?

In this case, yes. But that makes this issue very easy to solve. No services depart from the stop you are using:

library (gtfsrouter)
packageVersion ("gtfsrouter")
#> [1] '0.0.5.146'
url <- "https://www.nvbw.de/fileadmin/user_upload/service/open_data/fahrplandaten_ohne_liniennetz/bwgesamt.zip"
td = tempdir()
filename = tempfile(tmpdir=td, fileext=".zip")
download.file(url, filename)

gtfs <- extract_gtfs (filename)
#> ▶ Unzipping GTFS archive✔ Unzipped GTFS archive  
#> ▶ Extracting GTFS feed✔ Extracted GTFS feed 
#> ▶ Converting stop times to seconds✔ Converted stop times to seconds 
#> ▶ Converting transfer times to seconds✔ Converted transfer times to seconds
gtfs <- gtfs_timetable (gtfs, day = "Thursday")
from <- "de:08222:2569:0:RiW"
stop_number <- which (gtfs$stops$stop_id == from)
print (stop_number) 
#> [1] 24789

So that stop is in the stops table, but ...

tt <- gtfs$timetable
tt [tt$departure_station == stop_number, ]
#> Empty data.table (0 rows and 5 cols): departure_station,arrival_station,departure_time,arrival_time,trip_id

Created on 2023-03-30 with reprex v2.0.2

... no services depart from there. And so you can't get any travel times.

viajerus commented 1 year ago

Okay, interesting, maybe something isn't right with the dataset. Thank you!