ox_distance_matrix: Shortest-path distance matrix

View source: R/routing.R

ox_distance_matrixR Documentation

Shortest-path distance matrix

Description

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.

Examples

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

osmnxr documentation built on Oct. 20, 2026, 1:07 a.m.