| travel_matrix | R Documentation |
Builds the dense matrix of travel distances or times between all units, depot included, in one of three ways:
travel_matrix(
coords,
method = c("haversine", "euclidean", "osrm"),
matrix = NULL,
unit = NULL,
detour = 1,
measure = c("duration", "distance"),
server = getOption("osrm.server"),
profile = getOption("osrm.profile"),
block = 100,
bases = NULL,
speed = NULL
)
coords |
Data frame or matrix with two coordinate columns: |
method |
|
matrix |
Optional square numeric matrix of travel costs already
computed; when given, |
unit |
Label of the travel unit ( |
detour |
Multiplier applied to straight-line distances ( |
measure |
For |
server, profile |
For |
block |
For |
bases |
Optional data frame of depots (a |
speed |
Optional speed in coordinate units per hour (kilometres per
hour with |
from coordinates, as straight-line distances: great-circle ("haversine",
kilometres) with lat/lon, or Euclidean with planar x/y. A
detour factor (the ratio of road to straight-line distance, typically
1.2 to 1.4 on rural road networks) turns them into a planning estimate of
road distances when no network is available;
from a road network, with method = "osrm": durations (minutes) or
distances (kilometres) from an OSRM server through the osrm package,
requested in blocks so that the server's table limit is respected (the
public demo server allows 10 000 cells per request, and is meant for
small tests only: run your own server for a frame);
from a matrix computed elsewhere (matrix), with the coordinates used
only for names and plots.
Road matrices need not be symmetric (one-way streets, different durations by direction); the routing solver prices every leg in the direction travelled.
A square numeric matrix of class fieldopt_matrix with unit names
as dimnames and attributes coords, method, unit, detour and, for
"osrm", snap (the distance in kilometres from each unit to the point
of the network it was snapped to: large values flag units far from any
road).
segments <- data.frame(
unit = c("depot", "s1", "s2", "s3"),
lat = c(-8.05, -8.10, -8.00, -8.12),
lon = c(-34.90, -34.95, -34.85, -34.80)
)
travel_matrix(segments)
travel_matrix(segments, detour = 1.3)
## Not run:
# road durations from the OSRM demo server (small frames only)
travel_matrix(segments, method = "osrm", measure = "duration")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.