Skip to contents

Calls the matrix service and returns a routing distance matrix.

Usage

ors_matrix(
  src,
  dst = NULL,
  profile = NULL,
  units = c("m", "km", "mi"),
  proximity_type = c("distance", "duration"),
  instance = NULL
)

Arguments

src

[sf/sfc]

Source dataset containing point geometries that should be routed from.

dst

[sf/sfc]

Destination dataset containing point geometries that should be routed to. If NULL, only routes between points in src.

profile

[character]

Means of transport as supported by OpenRouteService. Defaults to the first profile in a call to get_profiles. For ors_shortest_distances, profile can be a character vector, for all other functions it needs to be a character scalar. For details on all profiles, refer to the backend reference.

units

[character]

Distance unit for distance calculations ("m", "km" or "mi")

proximity_type

[character]

Type of proximity that the calculations should be based on. If distance, the shortest physical distance will be calculated and if duration, the shortest temporal distance will be calculated.

instance

[ors_instance]

Object of an OpenRouteService instance that should be used for route computations. It is recommended to use ors_instance to set an instance globally. This argument should only be used if activating an instance globally is not feasible.

Value

A distance matrix.

Examples

if (any_mounted() && ors_ready()) {
  # compute distances from each row to each other row
  ors_matrix(pharma)

  # if two datasets are provided, route from each row in `src` to each row in `dst`
  ors_matrix(pharma[1:4, ], pharma[5:8, ])

  # distance matrices can be based on time or physical distance
  ors_matrix(pharma, proximity_type = "duration")

  # units can be adjusted
  ors_matrix(pharma, units = "km")
}