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")
)

Arguments

locations

List of longitude, latitude coordinate pairs, alternatively a two column matrix or data.frame.

profile

Route profile, defaults to "driving-car".

...

Optional parameters as described here

api_key

Character scalar containing openrouteservice API key

output

Output format. By default the response is being parsed to a list-based R object

Value

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.

Author

Andrzej Oleś andrzej@openrouteservice.org

Examples

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.604628 25.18577 109.65616
#> [2,]   1.573203   0.000000 25.07776 109.54814
#> [3,]  25.131819  24.989258  0.00000  85.57442
#> [4,] 109.457067 109.314506 85.33261   0.00000

# distance in km
res$distances
#>         [,1]    [,2]    [,3]    [,4]
#> [1,]    0.00  153.50 2410.79 9860.26
#> [2,]  153.81    0.00 2385.20 9834.68
#> [3,] 2358.56 2334.40    0.00 7501.23
#> [4,] 9790.67 9766.52 7449.31    0.00