Routing intermodal directions between locations based on the ‘HERE Intermodal Routing’ API.
In order to calculate route geometries (LINESTRING
) between pairs of points using the ‘HERE Intermodal Routing API’ the function intermodal_route()
is used. The function takes origin and destination locations as sf
objects containing geometries of type POINT
as input. Routes can be limited to a maximum number of allowed transfers (includes mode changes and public transit transfers), by specifying the transfer
parameter.
# Request routes
intermodal_routes <- route(
origin = poi[1:3, ],
destination = poi[4:6, ]
)
The id
column corresponds to the row of the input locations (origin
and destination
) and the rank
column enumerates the alternative routes. The maximum number of alternatives can be set by the results
parameter. Each row in the returned sf
object corresponds to a route section with a transport mode in a vehicle without a transfer.
id | rank | section | departure | origin | arrival | destination | type | mode | vehicle | provider | direction | distance | duration |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2 | 1 | 1 | 2021-04-09 13:39:00 | ORIG | 2021-04-09 13:40:00 | Castagnola, Villa Favorita | pedestrian | pedestrian | NA | NA | NA | 46 | 60 |
2 | 1 | 2 | 2021-04-09 13:40:00 | Castagnola, Villa Favorita | 2021-04-09 13:54:00 | Lugano, Stazione | transit | bus | 2 | Trasporti Pubblici Luganesi | Paradiso, Carzo | 4708 | 840 |
2 | 1 | 3 | 2021-04-09 13:54:00 | Lugano, Stazione | 2021-04-09 13:57:00 | Lugano | pedestrian | pedestrian | NA | NA | NA | 150 | 180 |
2 | 1 | 4 | 2021-04-09 14:02:00 | Lugano | 2021-04-09 15:41:00 | Luzern | transit | intercityTrain | IC21 | Schweizerische Bundesbahnen SBB | Basel SBB | 167844 | 5940 |
2 | 1 | 5 | 2021-04-09 16:00:00 | Luzern | 2021-04-09 17:00:00 | Bern | transit | intercityTrain | IR IR15 | Schweizerische Bundesbahnen SBB | Genève-Aéroport | 110149 | 3600 |
2 | 1 | 6 | 2021-04-09 17:17:00 | Bern | 2021-04-09 17:28:00 | Kehrsatz Nord | transit | cityTrain | S S31 | BLS AG (bls) | Belp | 8528 | 660 |
Print the intermodal routes on an interactive leaflet map:
if (requireNamespace("mapview", quietly = TRUE)) {
mapview::mapview(intermodal_routes,
zcol = "mode",
layer.name = "Intermodal route",
map.types = c("Esri.WorldTopoMap"),
homebutton = FALSE
)
}