This function extracts distances from a gPath object returned by
dijkstraBetween() or dijkstraFrom(). Depending on res.type, it
returns either a dist object or a numeric vector of distances.
Arguments
- m
a
gPathobject obtained bydijkstraBetween()ordijkstraFrom().- diag
unused parameter added for consistency with
as.dist().- upper
unused parameter added for consistency with
as.dist().- res.type
deprecated parameter that is now ignored; the function automatically detects whether the input is from
dijkstraBetween()ordijkstraFrom()and returns the appropriate output type.
Value
Either a dist object containing pairwise distances between
nodes the gPath object was constructed from dijkstraBetween(),
or a numeric vector of distances if the gPath object was constructed from dijkstraFrom().
See also
Other dijkstra_methods:
dijkstraBetween(),
dijkstraBuffer(),
dijkstraFrom()
Examples
## for pairwise distances between multiple a "dist" object is returned
# select a few populations from the HGDP dataset
hgdp.sub <- hgdp[getData(hgdp)$Population %in%
c("Balochi", "BantuKenya", "Papuan", "Pima")]
hgdp.path <- dijkstraBetween(hgdp.sub) # compute shortest path
gPath2dist(hgdp.path) # extract as dist object
#> 1 2 3
#> 2 137
#> 3 135 249
#> 4 55 189 185
## for distances from a single origin node to multiple the output is a vector of distances
#' # choose an origin node
start <- "24988"
hgdp.path <- dijkstraFrom(hgdp.sub, start) # compute shortest path from origin
gPath2dist(hgdp.path) # extract as vector of distances
#> 24988:16798 24988:7348 24988:40768 24988:30164
#> 53 189 148 75
