Routing directions between locations, travel distance or time origin-destination matrices and isolines for points of interest (POIs) based on the ‘HERE Routing’ API.
In order to calculate route geometries (LINESTRING
) between pairs of points using the ‘HERE Routing API’ the function route()
is used. The function takes origin and destination locations as sf
objects containing geometries of type POINT
as input. Routes can be created for various transport modes, as for example car or public transport. Optionally the current or predicted traffic information is considered. For routes using the transport mode "car"
a vehicle type can be specified, to obtain an estimate of the energy consumption on the routes.
origin <- poi[1:2, ]
destination <- poi[3:4, ]
routes <- route(
origin = origin,
destination = destination
)
id | departure | origin | arrival | destination | mode | traffic | distance | trafficTime | baseTime | travelTime | co2Emission |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | 2020-06-28 14:11:05 | Unterwilrain | 2020-06-28 16:18:40 | Avenue du Temple | car | disabled | 211462 | 7649 | 7655 | 7655 | 30.704 |
2 | 2020-06-28 14:11:05 | Via Riviera | 2020-06-28 17:00:46 | Giessliweg | car | disabled | 265417 | 10363 | 10181 | 10181 | 38.539 |
Construct a route label and print the routes on an interactive leaflet map:
The function route_matrix()
calculates a matrix of route summaries between given POIs. The function takes origin and destination locations as sf
objects containing geometries of type POINT
as input. If only one sf
object is provided as origin
an origin-destination matrix, which covers all route combinations, is constructed. Various transport modes and current or predicted traffic information are supported. The requested matrix is split into (sub-)matrices of dimension 15x100 in order to use the maximum allowed matrix size per request. Thereby the number of overall needed requests is minimized. The return value of the function route_matrix
is one route summary matrix, that fits the order of the provided POIs: origIndex
, destIndex
.
# From - to
mat <- route_matrix(
origin = poi[1:2, ],
destination = poi[3:4, ]
)
# Construct O-D matrix (all routes between the POIs)
mat <- route_matrix(
origin = poi
)
Print the first 10 rows of the matrix table, created from the POIs above, where the distance is in meters, the travel time in seconds and the consumption in cost factor units:
origIndex | destIndex | departure | arrival | distance | travelTime | costFactor |
---|---|---|---|---|---|---|
1 | 1 | 2020-06-28 14:11:06 | 2020-06-28 14:11:06 | 0 | 0 | 1 |
1 | 2 | 2020-06-28 14:11:06 | 2020-06-28 16:09:14 | 172687 | 7088 | 7153 |
1 | 3 | 2020-06-28 14:11:06 | 2020-06-28 16:18:44 | 211460 | 7658 | 7723 |
1 | 4 | 2020-06-28 14:11:06 | 2020-06-28 15:17:49 | 99286 | 4003 | 15682 |
1 | 5 | 2020-06-28 14:11:06 | 2020-06-28 15:31:05 | 117378 | 4799 | 4864 |
1 | 6 | 2020-06-28 14:11:06 | 2020-06-28 14:55:22 | 55301 | 2656 | 2701 |
1 | 7 | 2020-06-28 14:11:06 | 2020-06-28 16:49:53 | 265765 | 9527 | 9594 |
1 | 8 | 2020-06-28 14:11:06 | 2020-06-28 15:37:31 | 132421 | 5185 | 5308 |
2 | 1 | 2020-06-28 14:11:06 | 2020-06-28 16:13:32 | 175354 | 7346 | 8676 |
2 | 2 | 2020-06-28 14:11:06 | 2020-06-28 14:11:06 | 0 | 0 | 1 |
Isolines are constructed by the function isoline()
. The calculated polygons (POLYGON
or MULTIPOLYGON
) connect the end points of all routes leaving from defined centers (POIs) with either a specified length (isodistance), a specified travel time (isochrone) or consumption (isoconsumption), whereby time is measured in seconds, distance in meters and consumption as costfactor. By default the aggregate
parameter is set to TRUE
, which means that the isoline polygons are intersected and the minimum range value (time, distance or consumption) is taken in all intersecting areas, then the polyons are aggregated to polygons of geometry type MULTIPOLYGON
. Thereby overlapping isolines are avoided.
iso <- isoline(
poi,
range = seq(5, 30, 5) * 60,
range_type = "time",
type = "fastest",
mode = "car",
aggregate = TRUE,
traffic = FALSE
)
Convert range from seconds to minutes and print the aggregated isolines on an interactive leaflet map: