knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(hereR) if (requireNamespace("mapview", quietly = TRUE)) { mapview::mapviewOptions( fgb = FALSE, vector.palette = grDevices::colorRampPalette( c("#000004FF", "#420A68FF", "#932667FF", "#DD513AFF", "#FCA50AFF", "#FCFFA4FF") ) ) } intermodal_routes <- hereR:::example$intermodal_route
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.
knitr::kable(head(as.data.frame(intermodal_routes)[, colnames(intermodal_routes) != "geometry"]), format = "html")
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 ) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.