Get aggregated frequency per hour for each bus route
Source:R/get_route_frequency_hourly.R
      get_route_frequency_hourly.RdFor each route, returns the number of departures aggregated per hour and direction.
Usage
get_route_frequency_hourly(
  gtfs,
  date = GTFShift::calendar_nextBusinessWednesday(),
  use_osm_routes = NA,
  overline = FALSE
)Arguments
- gtfs
- tidygtfs. GTFS feed. 
- date
- Date (Default - GTFShift::calendar_nextBusinessWednesday()). Reference date to consider when analyzing the GTFS file.
- use_osm_routes
- osmdata::opq (Default NA). If overpass query for transit network is defined, analysis is performed considering OSM route geometry, using - GTFShift::osm_shapes_to_routes().
- overline
- Boolean (Default FALSE). If TRUE, routes are aggregated using - stplanr::overline2(), overlapping lines and converting them into a single route network.
Value
An sf data.frame object with the following columns (the first three are only present if overline=FALSE):
- route_id, the- route_idattribute from- routes.txtfile.
- route_short_name, the- route_short_nameattribute from- routes.txtfile.
- direction_id, the- direction_idattribute from- trips.txtfile (if attribute present in GTFS feed).
- hour, the hour for which the frequency applies (24 hour format).
- frequency, the number of services for the route that depart from the first stop for the corresponding 60 minutes period.
- geometry, the route shape.
Details
This method analyses the GTFS feed for a representative day, generating for each route the number of services aggregated per hour and direction. It assumes the time of departure at the first stop as a reference for each trip geometry.
By default, it estimates the next business Wednesday, relevant for the peak hour.
The overline parameter enables the aggregation of bus routes that share common line segments, returning a sum of frequencies per road segment, using stplanr::overline2().
Optionally, using use_osm_routes parameter, it retrieves the geometries from OpenStreetMap by matching the tag gtfs:shape_id, overwriting the original GTFS shapes.txt.
This is particularly useful if the GTFS shapes do not share the same geometry. For instance, if the edges of the lines do not overlap or do not follow the same route-over-the-road – which is very common, even besides GTFS recommendation – geometries might not be aggregated correctly, causing inconsistent results.
By relying on a common road network, such as OSM, it is possible to overcome this issue and aggregate the bus routes correctly.
For a detailed example, see the vignette("analyse").
Adapted from https://github.com/Bondify/GTFS_in_R/.
Examples
if (FALSE) { # \dontrun{
gtfs = GTFShift::load_feed("gtfs.zip")
frequency_analysis = GTFShift::get_route_frequency_hourly(gtfs)
} # }