Routing intermodal directions between locations based on the ‘HERE Intermodal Routing’ API.

Intermodal routes

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
1 1 1 2023-09-18 12:48:00 ORIG 2023-09-18 12:51:05 Littau Grenzhof / Luzernerstrasse pedestrian pedestrian NA NA NA 184 185
1 1 2 2023-09-18 12:52:05 Littau Grenzhof / Luzernerstrasse 2023-09-18 13:10:25 NA rented bicycle NA nextbike Switzerland NA 3626 1100
1 1 3 2023-09-18 13:11:25 NA 2023-09-18 13:12:00 Emmenbrücke pedestrian pedestrian NA NA NA 34 35
1 1 4 2023-09-18 13:12:00 Emmenbrücke 2023-09-18 13:53:00 Olten transit regionalTrain RE Schweizerische Bundesbahnen SBB Olten 50787 2460
1 1 5 2023-09-18 14:05:00 Olten 2023-09-18 14:32:00 Basel SBB transit intercityTrain IC61 Schweizerische Bundesbahnen SBB Basel SBB 38072 1620
1 1 6 2023-09-18 14:32:00 Basel SBB 2023-09-18 14:32:53 Basel Bahnhof SBB / Central Bahnparking pedestrian pedestrian NA NA NA 53 53

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
  )
}

API Reference