| dodgr_dists_categorical | R Documentation |
The main dodgr_distances function calculates distances between input sets of origin and destination points, and returns a single matrix of numeric distances. This function aggregates distances along categories of edges or segments, and returns an overall distance matrix (identical to the result of dodgr_distances), along with one additional matrix for each edge category.
Edges types must be specified in a column of the input graph named "edge_type". If this has two types of values (for example, "a" and "b"), then the function will return two additional distance matrices, one of total lengths of distances between all pairs of points traversed along edges of the first type, "a", and one of aggregated distances along edges of type "b".
See the description of dodgr_distances for details on the expected format of input graphs.
dodgr_dists_categorical(
graph,
from = NULL,
to = NULL,
proportions_only = FALSE,
pairwise = FALSE,
dlimit = NULL,
heap = "BHeap",
quiet = TRUE
)
graph |
|
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 |
proportions_only |
If |
pairwise |
If |
dlimit |
If no value to |
heap |
Type of heap to use in priority queue. Options include
Fibonacci Heap (default; |
quiet |
If |
If to is specified, a list of distance matrices of equal dimensions
(length(from), length(to)), the first of which ("distance") holds the final
distances, while the rest are one matrix for each unique value of
"edge_type", holding the distances traversed along those types of edges only.
Otherwise, a single matrix of total distances along all ways from each point
out to the specified value of dlimit, along with distances along each of
the different kinds of ways specified in the "edge_type" column of the input
graph.
The "edge_type" column in the graph can contain any kind of discrete or
categorical values, although integer values of 0 are not permissible. NA
values are ignored. The function requires one full distance
matrix to be stored for each category of "edge_type" (unless
proportions_only = TRUE). It is wise to keep numbers of discrete types as
low as possible, especially for large distance matrices.
Setting the proportions_only flag to TRUE may be advantageous for
large jobs, because this avoids construction of the full matrices. This may
speed up calculations, but perhaps more importantly it may make possible
calculations which would otherwise require distance matrices too large to be
directly stored.
Calculations are not able to be interrupted (for example, by Ctrl-C),
and can only be stopped by killing the R process.
Other distances:
dodgr_distances(),
dodgr_dists(),
dodgr_dists_nearest(),
dodgr_paths(),
dodgr_paths_expand(),
dodgr_times()
# Prepare a graph for categorical routing by including an "edge_type" column
graph <- weight_streetnet (hampi, wt_profile = "foot")
graph <- graph [graph$component == 1, ]
graph$edge_type <- graph$highway
# Define start and end points for categorical distances; using all vertices
# here.
length (unique (graph$edge_type)) # Number of categories
v <- dodgr_vertices (graph)
from <- to <- v$id [1:100]
d <- dodgr_dists_categorical (graph, from, to)
# Internal 'summary' method to summarise results:
summary (d)
class (d)
length (d)
sapply (d, dim)
# 9 distance matrices, all of same dimensions, first of which is standard
# distance matrix
s <- summary (d) # print summary as proportions along each "edge_type"
# or directly calculate proportions only
dodgr_dists_categorical (graph, from, to,
proportions_only = TRUE
)
# Pairwise distances return single matrix with number of rows equal to 'from'
# / 'to', and number of columns equal to number of edge types plus one for
# total distances.
d <- dodgr_dists_categorical (graph, from, to, pairwise = TRUE)
class (d)
dim (d)
# The 'dlimit' parameter can be used to calculate total distances along each
# category of edges from a set of points out to specified threshold:
dlimit <- 2000 # in metres
d <- dodgr_dists_categorical (graph, from, dlimit = dlimit)
dim (d) # length(from), length(unique(edge_type)) + 1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.