Graph utilities¶
Connectivity¶
Connectivity helpers inspect graph components and are useful before routing or
OD-matrix calculations. For undirected graphs use
connected_components(); for directed graphs choose between
weakly_connected_components() and strongly_connected_components().
The largest_* helpers return node-id sets. To actually keep only the largest
component, use UrbanGraph.keep_largest_connected_component() or the
keep_largest_subgraph parameter in graph builders.
See Connectivity diagnostics for a runnable connectivity workflow.
Editing and transformation¶
The editing helpers return new UrbanGraph objects and do not mutate the
source graph unless you use the corresponding UrbanGraph method with
inplace=True.
Use subgraph_by_nodes() for node-induced subgraphs,
clip_urban_graph() for geometry-based clipping,
relabel_urban_graph() for dense node indexes, and
join_urban_graphs() for concatenating compatible graph tables.
Use UrbanGraph.to_directed(), UrbanGraph.to_undirected(), and
UrbanGraph.simplify_multiedges() for topology transformations.
See Graph operations for editing examples.
Object matching and projection¶
Use nearest_nodes() when an object table only needs a nearest existing
graph node id.
Use project_objects2urban_graph() when objects should be inserted into
the graph topology. The function prepares an UrbanGraphChanges object
with new nodes, new edges, and source edges to delete. Apply the changes with
apply_urban_graph_changes(), or use UrbanGraph.project_objects()
for the in-memory shortcut.
See Objects, nearest nodes, and graph projection for both workflows, including
add_link_edge=True and add_link_edge=False.
Persistence¶
Use write_urban_graph() and read_urban_graph() to store and restore
.urbangraph archives. Archives contain node and edge tables and can
optionally include the cached adjacency matrix. See
UrbanGraph basics.
Return connected components of an undirected |
|
Return weakly connected components. |
|
Return strongly connected components. |
|
Return the number of connected components in an undirected graph. |
|
Return the number of weakly connected components. |
|
Return the number of strongly connected components. |
|
Return the largest connected component of an undirected graph. |
|
Return the largest weakly connected component. |
|
Return the largest strongly connected component. |
|
Return the largest component according to the selected connectivity mode. |
|
Relabel node ids to a dense |
|
Return an induced |
|
Clip graph nodes by geometry and keep only edges with retained endpoints. |
|
Join two compatible |
|
Return the nearest graph node id for each input geometry. |
|
Prepare graph changes that connect objects to their nearest edges. |
|
Apply prepared changes to an |
|
Read an |
|
Write an |
|
Validate all node, edge, topology and CRS contracts of an |
Optional NetworkX utilities¶
The following helpers are available when NetworkX support is installed.