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.
## POIs for intermodal routes in Berlin (service is not yet available in Switzerland)
poi_berlin <- data.frame(
name = c("HERE Berlin", "Treptow", "Potsdam", "Tiergarten"),
lng = c(13.384944, 13.461215, 13.058351, 13.336490),
lat = c(52.531056, 52.493908, 52.403587, 52.514557)
) %>%
st_as_sf(coords = c("lng", "lat")) %>%
st_set_crs(4326)
# Request routes
intermodal_routes <- route(
origin = poi_berlin[1:2, ],
destination = poi_berlin[3:4, ]
)
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 1 | 2020-06-28 14:16:07 | ORIG | 2020-06-28 14:54:08 | DEST | taxi | taxi | NA | Taxi Berlin 202020 | NA | 37822 | 2281 |
1 | 2 | 2020-06-28 14:26:00 | ORIG | 2020-06-28 14:29:00 | U Naturkundemuseum | pedestrian | pedestrian | NA | NA | NA | 234 | 180 |
1 | 2 | 2020-06-28 14:29:00 | U Naturkundemuseum | 2020-06-28 14:32:00 | S+U Friedrichstr. Bhf | transit | subway | U6 | Berliner Verkehrsbetriebe | U Alt-Mariendorf | 1308 | 180 |
1 | 2 | 2020-06-28 14:37:00 | S+U Friedrichstr. Bhf | 2020-06-28 15:06:00 | S Potsdam Hauptbahnhof | transit | regionalTrain | RE1 | DB Regio AG | Brandenburg, Hauptbahnhof | 27437 | 1740 |
1 | 2 | 2020-06-28 15:12:00 | S Potsdam Hauptbahnhof | 2020-06-28 15:19:00 | Potsdam, Nauener Tor | transit | lightRail | Tram 96 | Verkehrsbetrieb Potsdam GmbH | Potsdam, Campus Jungfernsee | 1623 | 420 |
1 | 2 | 2020-06-28 15:19:00 | Potsdam, Nauener Tor | 2020-06-28 15:20:00 | DEST | pedestrian | pedestrian | NA | NA | NA | 77 | 60 |
Print the intermodal routes on an interactive leaflet map: