| dodgr_times | R Documentation |
Calculates distances from input data.frame objects (graph),
which must minimally contain three columns of from, to, and d or
dist. If an additional column named weight or wt is present, shortest
paths are calculated according to values specified in that column, while
distances returned are calculated from the d or dist column. 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.
Graphs derived from Open Street Map street networks, via the
weight_streetnet function, have columns labelled d, d_weighted,
time, and time_weighted. For these inputs, paths between origin and
destination points are always routed using d_weighted (or t_weighted for
times), while final distances are sums of values of d (or t for times)-
that is, of un-weighted distances or times - along those paths.
The function is parallelized for efficient computation of distances between
multiple origin and destination points, as described in the from parameter
below.
dodgr_times(
graph,
from = NULL,
to = NULL,
shortest = FALSE,
pairwise = FALSE,
heap = "BHeap"
)
graph |
The Note that longitude and latitude values are always interpreted in 'dodgr' to be in EPSG:4326 / WSG84 coordinates. Any other kinds of coordinates should first be reprojected to EPSG:4326 before submitting to any 'dodgr' routines. See further information in Details. |
from |
Vector or matrix of points from which route distances are to be calculated, specified as one of the following:
|
to |
Vector or matrix of points to which route distances are to be
calculated. If |
shortest |
If |
pairwise |
If |
heap |
Type of heap to use in priority queue. Options include
Fibonacci Heap (default; |
square matrix of distances between nodes
Other distances:
dodgr_distances(),
dodgr_dists(),
dodgr_dists_categorical(),
dodgr_dists_nearest(),
dodgr_paths(),
dodgr_paths_expand()
# 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)
# Example of "from" and "to" as integer-ish values, in which case they are
# interpreted to index into "dodgr_vertices()":
graph <- data.frame (
from = c (1, 3, 2, 2, 3, 3, 4, 4),
to = c (2, 1, 3, 4, 2, 4, 3, 1),
d = c (1, 2, 1, 3, 2, 1, 2, 1)
)
dodgr_dists (graph, from = 1, to = 2)
# That then gives distance from "1" to "3" because the vertices are built
# sequentially along "graph$from":
dodgr_vertices (graph)
# And vertex$id [2] is "3"
# A larger example from the included [hampi()] data.
graph <- weight_streetnet (hampi)
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/UrbanAnalyst/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
index <- which (!(essen$level == "-1" | essen$level == "1")) # for example
library (sf) # needed for following sub-select operation
essen <- essen [index, ]
graph <- weight_streetnet (essen, wt_profile = "foot")
graph <- graph [which (graph$component == 1), ]
d <- dodgr_dists (graph, from = xy, to = xy)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.