gtfsrouter icon indicating copy to clipboard operation
gtfsrouter copied to clipboard

consider child stations of "from" station in traveltimes computation

Open AlexandraKapp opened this issue 4 years ago • 1 comments

If a stop does not have any departures itself (e.g. a parent_station) but there are stops that can be transfered to that do have departures, these routes should also be followed.

  • genereally consider child stops?
  • additionally consider stops that can be transfered to?
library(gtfsrouter)

gtfs <- gtfsrouter::extract_gtfs(file.path("gtfs.zip"))
#> > Unzipping GTFS archivev Unzipped GTFS archive  
#> > Extracting GTFS feedv Extracted GTFS feed 
#> > Converting stop times to secondsv Converted stop times to seconds 
#> > Converting transfer times to secondsv Converted transfer times to seconds
gtfs$transfers <- gtfsrouter::gtfs_transfer_table(gtfs, network_times = FALSE)
#> > Finding neighbouring services for each stop
#> Loading required namespace: geodist
#> Loading required namespace: pbapply
#> v Found neighbouring services for each stop
#> > Expanding to include in-place transfers
#> v Expanded to include in-place transfers
ttable <- gtfsrouter::gtfs_timetable(gtfs, day = "tuesday")

# Prinzenstr stops
gtfs$stops[grepl("Prinzenstr./Ritterstr", gtfs$stops$stop_name)]
#>         stop_id stop_code                      stop_name stop_desc stop_lat
#> 1: 900000013104        NA Berlin, Prinzenstr./Ritterstr.        NA 52.50165
#> 2: 070101000578        NA Berlin, Prinzenstr./Ritterstr.        NA 52.50165
#> 3: 070101001379        NA Berlin, Prinzenstr./Ritterstr.        NA 52.50165
#>    stop_lon location_type parent_station wheelchair_boarding platform_code
#> 1: 13.40927             1                                  1              
#> 2: 13.40927             0   900000013104                  NA              
#> 3: 13.40927             0   900000013104                  NA              
#>                                             zone_id
#> 1: 900000013104 5555 Berlin, Prinzenstr./Ritterstr.
#> 2:                                                 
#> 3:

# there are transfers in the transfers table
gtfs$transfers[gtfs$transfers$from_stop_id == "900000013104"]
#>    from_stop_id   to_stop_id transfer_type min_transfer_time
#> 1: 900000013104 070101000578             2               120
#> 2: 900000013104 070101001379             2               120

# no result for the parent station
gtfs_traveltimes(ttable, "900000013104", from_is_id = T, start_time = 8*3600)
#> [1] duration   ntransfers stop_id    stop_name  stop_lon   stop_lat  
#> <0 rows> (or 0-length row.names)

# result for the child station
gtfs_traveltimes(ttable, "070101000578", from_is_id = T, start_time = 8*3600)
#>    duration ntransfers      stop_id                                       stop_name stop_lon stop_lat
#>1   01:30:00          5 000008012713                              Rangsdorf, Bahnhof 13.43111 52.29413
#>9   01:01:00          4 000008012666                          S Potsdam Hauptbahnhof 13.06719 52.39093
#>11  01:21:00          6 000008010279                        Potsdam, Pirschheide Bhf 13.01084 52.37391
#>13  00:30:00          3 000008010036                    S+U Lichtenberg Bhf (Berlin) 13.49823 52.51075
#>16  01:16:05          5 000008011740                            Großbeeren, Bahnhof 13.28436 52.35003
# ...

Created on 2020-12-17 by the reprex package (v0.3.0)

AlexandraKapp avatar Dec 17 '20 11:12 AlexandraKapp

Great idea, and relatively straightforward to implement. Refer also #66 and discussions there.

mpadge avatar Dec 17 '20 16:12 mpadge