mamut_routing_tools.roadgraph¶
RoadGraph
dataclass
¶
RoadGraph(
osm_path: Path,
only_intersections: bool,
trim_to_connected: bool,
ref_lla: LLA,
node_enu: dict[int, tuple[float, float, float]],
vertex_of: dict[int, int],
node_of: list[int],
edges: list[tuple[int, int]],
edge_class: list[int],
edge_weight: list[float],
graph: PyDiGraph,
loaded_with: tuple[bool, bool] | None = None,
_kdtree: cKDTree | None = None,
_kdtree_nodes: list[int] = list(),
_vertex_kdtree: cKDTree | None = None,
_segments: tuple[Any, Any, Any] | None = None,
)
nearest_node
¶
Nearest road node (any node, not only graph vertices), matching OSMToolset's NodeSpatIndex/findnode contract exactly: candidate inclusion is an axis-aligned +-range box (L-infinity) around the query point, and the pick is the minimum EUCLIDEAN distance among the box hits. A node at 102 m Euclidean but inside the box still matches; one at 99 m outside the box does not exist geometrically.
Source code in MAMUT-routing-tools/src/mamut_routing_tools/roadgraph/build.py
nearest_nodes
¶
nearest_nodes(
points: list[tuple[float, float]],
node_range_m: float = 100.0,
) -> list[int | None]
nearest_node for many points at once, same contract per point.
One kd-tree call for the whole batch instead of one per point: the POI
selection asks this for every amenity in a city, where the per-call
overhead dominates the search itself. Results are identical to calling
nearest_node in a loop, including the +-range box semantics.
Source code in MAMUT-routing-tools/src/mamut_routing_tools/roadgraph/build.py
nearest_vertex
¶
Nearest GRAPH VERTEX to a point, as (vertex, distance_m).
Deliberately different from :meth:nearest_node: that one indexes every
road node and honours the Julia findnode box contract, so a POI whose
closest node sits mid-segment resolves to something absent from
vertex_of. Manual picks must always land on a routable vertex, so
this indexes node_of only and searches by true Euclidean distance,
growing the radius until it finds one or gives up at max_radius_m.
Source code in MAMUT-routing-tools/src/mamut_routing_tools/roadgraph/build.py
nearest_vertices
¶
nearest_vertices(
points: list[tuple[float, float]],
max_radius_m: float = 2000.0,
) -> list[tuple[int, float] | None]
nearest_vertex for many points at once, same contract per point.
Source code in MAMUT-routing-tools/src/mamut_routing_tools/roadgraph/build.py
nearest_edge_projection
¶
nearest_edge_projection(
lat: float, lon: float, max_distance_m: float = 50.0
) -> tuple[int, float, float] | None
Nearest EDGE to a point, as (edge_index, fraction, distance_m).
fraction is the position of the orthogonal projection along the
directed edge (0 at its tail, 1 at its head). Only node-level graphs
(only_intersections=False) qualify: their edges are the straight
segments between consecutive OSM nodes, whereas an intersection-level
edge stands for a whole polyline whose bends this graph no longer
knows. Returns None on an intersection-level graph or when no
edge passes within max_distance_m.
This is the escape hatch for a point that is on a road but far from every road node: a long straight segment, or a synthetic crop node of another extract of the same city (the generation-time bounds cut the road there; a re-fetched extract does not).
Source code in MAMUT-routing-tools/src/mamut_routing_tools/roadgraph/build.py
load_road_graph
¶
load_road_graph(
osm_path: str | Path,
*,
only_intersections: bool = True,
trim_to_connected: bool = True,
) -> RoadGraph
Load with the same progressive option relaxation as the Julia servers: requested options first, then (oi, False), (False, trim), (False, False).
Source code in MAMUT-routing-tools/src/mamut_routing_tools/roadgraph/build.py
road_graph_candidates
¶
road_graph_candidates(
osm_path: str | Path,
*,
only_intersections: bool = True,
trim_to_connected: bool = True,
) -> list[RoadGraph]
Candidate graphs in the cascade order the render path probes them.