Calculate matrix of pair-wise distances between points.

dodgr_dists(graph, from, to, wt_profile = "bicycle", expand = 0,
  heap = "BHeap", parallel = TRUE, quiet = TRUE)

Arguments

graph

data.frame or equivalent object representing the network graph (see Details)

from

Vector or matrix of points from which route distances are to be calculated (see Details)

to

Vector or matrix of points to which route distances are to be calculated (see Details)

wt_profile

Name of weighting profile for street networks (one of foot, horse, wheelchair, bicycle, moped, motorcycle, motorcar, goods, hgv, psv).

expand

Only when graph not given, the multiplicative factor by which to expand the street network surrounding the points defined by from and/or to.

heap

Type of heap to use in priority queue. Options include Fibonacci Heap (default; FHeap), Binary Heap (BHeap), Radix, Trinomial Heap (TriHeap), Extended Trinomial Heap (TriHeapExt, and 2-3 Heap (Heap23).

parallel

If TRUE, perform routing calculation in parallel (see details)

quiet

If FALSE, display progress messages on screen.

Value

square matrix of distances between nodes

Note

graph must minimally contain three columns of from, to, dist. If an additional column named weight or wt is present, shortest paths are calculated according to values specified in that column; otherwise according to dist values. Either way, final distances between from and to points are calculated according to values of dist. That is, paths between any pair of points will be calculated according to the minimal total sum of weight values (if present), while reported distances will be total sums of dist values.

The from and to columns of graph may be either single columns of numeric or character values specifying the numbers or names of graph vertices, or combinations to two columns specifying geographical (longitude and latitude) coordinates. In the latter case, almost any sensible combination of names will be accepted (for example, fromx, fromy, from_x, from_y, or fr_lat, fr_lon.)

from and to values can be either two-column matrices of equivalent of longitude and latitude coordinates, or else single columns precisely matching node numbers or names given in graph$from or graph$to. If to is missing, pairwise distances are calculated between all points specified in from. If neither from nor to are specified, pairwise distances are calculated between all nodes in graph.

Calculations in parallel (parallel = TRUE) ought very generally be advantageous. For small graphs, Calculating distances in parallel is likely to offer relatively little gain in speed, but increases from parallel computation will generally markedly increase with increasing graph sizes.

Examples

# A simple graph graph <- data.frame (from = c ("A", "B", "B", "B", "C", "C", "D", "D"), to = c ("B", "A", "C", "D", "B", "D", "C", "A"), d = c (1, 2, 1, 3, 2, 1, 2, 1)) dodgr_dists (graph)
#> A B C D #> A 0 1 2 3 #> B 2 0 1 2 #> C 2 2 0 1 #> D 1 2 2 0
# A larger example from the included [hampi()] data. graph <- weight_streetnet (hampi)
#> The following highway types are present in data yet lack corresponding weight_profile values: living_street,
from <- sample (graph$from_id, size = 100) to <- sample (graph$to_id, size = 50) d <- dodgr_dists (graph, from = from, to = to) # d is a 100-by-50 matrix of distances between `from` and `to`
# NOT RUN { # a more complex street network example, thanks to @chrijo; see # https://github.com/ATFutures/dodgr/issues/47 xy <- rbind (c (7.005994, 51.45774), # limbeckerplatz 1 essen germany c (7.012874, 51.45041)) # hauptbahnhof essen germany xy <- data.frame (lon = xy [, 1], lat = xy [, 2]) essen <- dodgr_streetnet (pts = xy, expand = 0.2, quiet = FALSE) graph <- weight_streetnet (essen, wt_profile = "foot") d <- dodgr_dists (graph, from = xy, to = xy) # First reason why this does not work is because the graph has multiple, # disconnected components. table (graph$component) # reduce to largest connected component, which is always number 1 graph <- graph [which (graph$component == 1), ] d <- dodgr_dists (graph, from = xy, to = xy) # should work, but even then note that table (essen$level) # There are parts of the network on different building levels (because of # shopping malls and the like). These may or may not be connected, so it may be # necessary to filter out particular levels levs <- paste0 (essen$level) # because sf data are factors index <- which (! (levs == "-1" | levs == "1")) # for example library (sf) # needed for following sub-select operation essen <- essen [index, ] graph <- weight_streetnet (essen, wt_profile = "foot") d <- dodgr_dists (graph, from = xy, to = xy) # }