Merges groups of nodes lying within tolerance of one another into single
nodes placed at the group centroid, then rewrites edges to the consolidated
nodes and drops the resulting self-loops. Useful for collapsing the multiple
OSM nodes that represent one complex junction (e.g. dual carriageways).
Arguments
- g
An osm_graph.
- tolerance
Distance below which nodes are merged, in CRS units. Either one number for the whole graph (default
10), or one number per node for junction-specific radii (as in OSMnx 2): each node is buffered bytolerance / 2, and nodes merge when their buffers overlap — i.e. two nodes merge when their distance is at most the mean of their two tolerances, so a0keeps a node out of every merge it does not fall inside another node's radius for.
Value
A consolidated osm_graph (with meta$consolidated = TRUE).
Details
Clustering uses sf::st_is_within_distance(); connected components are found
by the Rust core. tolerance is in the units of the graph CRS, so project
the graph first (e.g. to a metric CRS) for a meaningful distance.
Consolidating an already-consolidated graph (meta$consolidated is set)
warns but proceeds, clustering the consolidated nodes again — legitimate
for growing the tolerance, but usually a mistake.
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 = 4, spacing = 100)
# nothing is within 10 units here, so the graph is unchanged
ox_consolidate_intersections(g, tolerance = 10)
#>
#> ── osm_graph ───────────────────────────────────────────────────────────────────
#> 16 nodes, 48 edges
#> Network type: "drive"
#> Simplified: TRUE
#> CRS: "EPSG:3857"