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
<- route(
intermodal_routes 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 | departure | origin | arrival | destination | type | mode | vehicle | provider | direction | distance | duration |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2 | 1 | 2020-12-31 16:55:00 | ORIG | 2020-12-31 16:56:00 | Castagnola, Villa Favorita | pedestrian | pedestrian | NA | NA | NA | 46 | 60 |
2 | 1 | 2020-12-31 16:56:00 | Castagnola, Villa Favorita | 2020-12-31 17:12:00 | Lugano, Stazione | transit | bus | 2 | Trasporti Pubblici Luganesi | Paradiso, Geretta | 4709 | 960 |
2 | 1 | 2020-12-31 17:12:00 | Lugano, Stazione | 2020-12-31 17:16:00 | Lugano | pedestrian | pedestrian | NA | NA | NA | 240 | 240 |
2 | 1 | 2020-12-31 17:26:00 | Lugano | 2020-12-31 17:56:00 | Bellinzona | transit | cityTrain | S 10 | Schweizerische Bundesbahnen SBB | Bellinzona | 29562 | 1800 |
2 | 1 | 2020-12-31 18:02:00 | Bellinzona | 2020-12-31 19:13:00 | Rotkreuz | transit | intercityTrain | IC 21 | Schweizerische Bundesbahnen SBB | Basel SBB | 126914 | 4260 |
2 | 1 | 2020-12-31 19:22:00 | Rotkreuz | 2020-12-31 20:18:00 | Olten | transit | cityTrain | S 26 | Schweizerische Bundesbahnen SBB | Olten | 59944 | 3360 |
Print the intermodal routes on an interactive leaflet map:
if (requireNamespace("mapview", quietly = TRUE)) {
::mapview(intermodal_routes,
mapviewzcol = "mode",
layer.name = "Intermodal route",
map.types = c("Esri.WorldTopoMap"),
homebutton = FALSE
) }