
Get OSM routes geometry considering gtfs:shape_id match
Source:R/query_osm_shapes_to_routes.R
osm_shapes_to_routes.RdGet OSM routes geometry considering gtfs:shape_id match
Usage
osm_shapes_to_routes(
gtfs,
q,
ways = FALSE,
ways_tags = c("lanes", "psv", "bus", "way", "parking", "name"),
osm_file = NULL,
osm_route_type = "bus"
)Arguments
- gtfs
tidygtfs. GTFS feed.
- q
osmdata::opq. Overpass query for transit network.
- ways
boolean (Default False). If true, relation is disaggregated in ways.
character vector (Default
c("lanes", "psv", "bus", "way", "parking", "name")). List of OSM way tags to extract whenwaysparameter is set to true. Match is done usingtidyselect::contains().- osm_file
character (Optional). Location of OSM extract file with
osm.pbfformat. Refer toosmextract::oe_download()for more details. If not provided OSM Overpass API is called throughosmdata::osmdata_sf().- osm_route_type
character (Default "bus"). OSM route type. Used to query OSM network (e.g., 'bus', 'train').
Value
A sf data.frame with the following columns:
- shape_id
The
shape_idattribute fromshapes.txtfile.- osm_id
The
osm_idattribute from OSM route relation.- way_osm_id
The
osm_idattribute from OSM way (ifwaysparameter is set to true).- *
Any column that matches
ways_tagsparameter.- geometry
The geometrical data for the OSM route relation.
Shapes that do not have a match on OSM are ignored. If that occurs, a warning is displayed during the method execution, informing about the missing geometries.
Details
For each route, matches its trips' shapes with OSM route relations, considering the
OSM gtfs:shape_id attribute.
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)
# To use OSM API:
shapes_geometry_osm <- GTFShift::osm_shapes_to_routes(gtfs, q)
# To use a local OSM file:
osm_file <- oe_download("https://download.geofabrik.de/europe/portugal-latest.osm.pbf")
shapes_geometry_osm <- GTFShift::osm_shapes_to_routes(gtfs, q, osm_file = osm_file)
} # }