Obtain one-to-many, many-to-one and many-to-many matrices for time and distance.
ors_matrix(
locations,
profile = ors_profile(),
...,
api_key = ors_api_key(),
output = c("parsed", "text")
)
List of longitude, latitude
coordinate pairs, alternatively a two column matrix
or data.frame
.
Route profile, defaults to "driving-car"
.
Optional parameters as described here
Character scalar containing openrouteservice API key
Output format. By default the response is being parsed to a list-based R object
Duration or distance matrix for multiple source and destination
for "text"
, a character vector of length 1 re-encoded to UTF-8.
for "parsed"
, a parsed R object.
coordinates <- list(
c(9.970093, 48.477473),
c(9.207916, 49.153868),
c(37.573242, 55.801281),
c(115.663757,38.106467)
)
# query for duration and distance in km
res <- ors_matrix(coordinates, metrics = c("duration", "distance"), units = "km")
# duration in hours
res$durations / 3600
#> [,1] [,2] [,3] [,4]
#> [1,] 0.000000 1.588661 25.41464 109.66200
#> [2,] 1.574931 0.000000 25.33264 109.58000
#> [3,] 25.255472 25.112483 0.00000 84.71728
#> [4,] 109.501128 109.358133 84.64216 0.00000
# distance in km
res$distances
#> [,1] [,2] [,3] [,4]
#> [1,] 0.00 153.50 2413.19 9780.31
#> [2,] 153.80 0.00 2387.60 9754.72
#> [3,] 2361.93 2337.78 0.00 7328.38
#> [4,] 9714.39 9690.24 7312.83 0.00