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.

keep_largest_connected_component

Keep only the largest component of an UrbanGraph.

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.

simplify_multiedges

Collapse a multigraph UrbanGraph into a simple graph.

to_directed

Return a directed copy of UrbanGraph using a boolean edge direction column.

to_undirected

Return an undirected copy of UrbanGraph.

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.

UrbanGraphChanges

Set of table changes that can be applied 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

NetworkX is not installed with IduEdu. Install it separately (pip install networkx) to use the helpers below; without it they raise ImportError when called.

urban_graph2nx_graph

Convert an UrbanGraph to a NetworkX graph.

nx_graph2urban_graph

Convert a NetworkX graph to an UrbanGraph.

graph2gdf

Convert a NetworkX graph to GeoDataFrames for nodes and/or edges.

gdf2graph

Convert a GeoDataFrame of LineStrings into a directed graph (nx.DiGraph).

keep_largest_nx_component

Keep only the largest connected component of a NetworkX graph.

clip_nx_graph

Clip a NetworkX graph by a polygon and return the induced subgraph.

read_gml

Read a GML file into a NetworkX graph and cast edge geometry from WKT strings to shapely.

write_gml

Write a NetworkX graph to GML, coercing node coordinates to plain floats.

reproject_graph

Reproject node coordinates (x, y) and edge geometries to a new CRS (in place).