Calculates route geometries (LINESTRING) between given pairs of points using the HERE 'Routing' API. Routes can be created for various transport modes, as for example 'car' or 'bicycle', incorporating current traffic information, if available. For routes using the transport mode "car" a vehicle consumption model can be specified, to obtain an estimate of the consumption.

route(
  origin,
  destination,
  datetime = Sys.time(),
  arrival = FALSE,
  results = 1,
  routing_mode = "fast",
  transport_mode = "car",
  traffic = TRUE,
  avoid_area = NULL,
  avoid_feature = NULL,
  consumption_model = NULL,
  vignettes = TRUE,
  url_only = FALSE
)

Arguments

origin

sf object, the origin locations of geometry type POINT.

destination

sf object, the destination locations of geometry type POINT.

datetime

POSIXct object, datetime for the departure (or arrival if arrival = TRUE).

arrival

boolean, calculate routes for arrival at the defined time (default = FALSE)?

results

numeric, maximum number of suggested routes (Valid range: 1 and 7).

routing_mode

character, set the routing type: "fast" or "short" (default = "fast").

transport_mode

character, set the transport mode: "car", "truck", "pedestrian", "bicycle", "scooter", "taxi", "bus" or "privateBus" (default = "car").

traffic

boolean, use real-time traffic or prediction in routing (default = TRUE)? If no traffic is selected, the datetime is set to "any" and the request is processed independently from time.

avoid_area,

sf object, area (only bounding box is taken) to avoid in routes (default = NULL).

avoid_feature

character, transport network features to avoid, e.g. "tollRoad" or "ferry" (default = NULL).

consumption_model

character, specify the consumption model of the vehicle (default = NULL an average electric car is set).

vignettes

boolean, include vignettes in the total toll cost of routes (default = TRUE).

url_only

boolean, only return the generated URLs (default = FALSE)?

Value

An sf object containing the requested routes.

Tolls are requested for routes with transport mode "car", "truck"

"taxi" or "bus". The currency defaults to the current system locale settings. A different currency can be set using set_currency and a currency code compliant to ISO 4217.

Examples

# Provide an API Key for a HERE project
set_key("<YOUR API KEY>")

# Get all from - to combinations from POIs
to <- poi[rep(seq_len(nrow(poi)), nrow(poi)), ]
from <- poi[rep(seq_len(nrow(poi)), each = nrow(poi)), ]
idx <- apply(to != from, any, MARGIN = 1)
to <- to[idx, ]
from <- from[idx, ]

# Routing
routes <- route(
  origin = from, destination = to, results = 3,
  transport_mode = "car", url_only = TRUE
)