Skip to contents

Computes the matrix of minimum-weight distances between every from node and every to node (Rust core; one Dijkstra per source).

Usage

ox_distance_matrix(g, from, to = from, weight = "length")

Arguments

g

An osm_graph.

from

Node osmids for the matrix rows.

to

Node osmids for the matrix columns. Defaults to from.

weight

Edge column used as weight. Default "length".

Value

A numeric matrix (length(from) x length(to)) with osmid dimnames; Inf marks unreachable pairs.

References

osmnxr is an R port of OSMnx. If you use it, please cite:

Boeing, G. (2025). Modeling and analyzing urban networks and amenities with OSMnx. Geographical Analysis, 57(4), 567–577. doi:10.1111/gean.70009

Examples

g <- example_osm_graph(n = 3)
nodes <- g$nodes$osmid
ox_distance_matrix(g, from = nodes[1:2], to = nodes[3:4])
#>     3   4
#> 1 200 100
#> 2 100 200