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.

connected_components

Return connected components of an undirected UrbanGraph.

weakly_connected_components

Return weakly connected components.

strongly_connected_components

Return strongly connected components.

number_connected_components

Return the number of connected components in an undirected graph.

number_weakly_connected_components

Return the number of weakly connected components.

number_strongly_connected_components

Return the number of strongly connected components.

largest_connected_component

Return the largest connected component of an undirected graph.

largest_weakly_connected_component

Return the largest weakly connected component.

largest_strongly_connected_component

Return the largest strongly connected component.

largest_component

Return the largest component according to the selected connectivity mode.

relabel_urban_graph

Relabel node ids to a dense RangeIndex and update edge endpoints.

subgraph_by_nodes

Return an induced UrbanGraph subgraph for the provided node ids.

clip_urban_graph

Clip graph nodes by geometry and keep only edges with retained endpoints.

join_urban_graphs

Join two compatible UrbanGraph objects by concatenating node and edge tables.

nearest_nodes

Return the nearest graph node id for each input geometry.

project_objects2urban_graph

Prepare graph changes that connect objects to their nearest edges.

apply_urban_graph_changes

Apply prepared changes to an UrbanGraph.

read_urban_graph

Read an UrbanGraph from an .urbangraph archive.

write_urban_graph

Write an UrbanGraph to an .urbangraph archive.

validate_graph

Validate all node, edge, topology and CRS contracts of an UrbanGraph.

Optional NetworkX utilities

The following helpers are available when NetworkX support is installed.