Skip to contents

Get OSM routes that match shapes, based on geometrical match

Usage

osm_shapes_match_routes(
  gtfs,
  q,
  geometry = TRUE,
  gtfs_match = "route_short_name",
  osm_match = "ref"
)

Arguments

gtfs

tidygtfs. GTFS feed.

q

osmdata::opq. Overpass query for transit network

geometry

Boolean (Default TRUE). If TRUE, returns sf object with geometry, otherwise, a simple data.frame.

gtfs_match

String (Default route_short_name). routes.txt attribute that identifies routes. Accepted values: route_id, route_short_name, route_long_name.

osm_match

String (Default ref). OSM attribute that identifies routes by matching with gtfs_match. Accepted values: ref, name, gtfs:route_id.

Value

A data.frame (sf if geometry=TRUE) with the following columns:

  • shape_id, the shape_id attribute from shapes.txt file.

  • osm_id, the osm_id attribute from OSM route relation.

  • distance_diff, the difference, in meters, between GTFS shape and OSM route lengths.

  • points_diff, the sum of the difference, in meters, between GTFS shape and OSM route start and end points.

  • route_short_name, the route_short_name attribute from routes.txt file.

  • route_long_name, the route_long_name attribute from routes.txt file.

  • geometry, the geometrical data for the OSM route relation.

Details

For each route, matches its trips' shapes with OSM route relations.

The match is performed considering, for each shape, the closest OSM route, based on the start and end points and total length.

Examples

if (FALSE) { # \dontrun{
gtfs <- GTFShift::load_feed("gtfs.zip")

q = opq("Lisbon")  |>
  add_osm_feature(key = "route", value = c("bus", "tram")) |>
  add_osm_feature(key = "network", value = "Carris", key_exact = TRUE)

shapes_match_routes = GTFShift::osm_shapes_match_routes(gtfs, q)
} # }