iduedu.nx_graph2urban_graph

iduedu.nx_graph2urban_graph(nx_graph, restore_edge_geom=True, *, check_oneway=True, oneway_column='oneway')[source]

Convert a NetworkX graph to an UrbanGraph.

This helper is intended for compatibility with libraries that still produce NetworkX graphs. Nodes must contain x and y coordinates, the graph must expose a crs attribute, and edges are expected to carry geometry, length_meter and time_min attributes.

Parameters:
  • nx_graph (Any) – NetworkX graph, directed graph, multigraph or multidigraph. Directed graphs are accepted for compatibility, but a warning is emitted because stable behavior for directed NetworkX inputs is not guaranteed.

  • restore_edge_geom (bool) – If True, empty edge geometries are restored as straight lines between endpoint nodes. If False, edges with empty geometries are removed.

  • check_oneway (bool) – If True and oneway_column exists on edges, that column is used as the UrbanGraph edge direction column.

  • oneway_column (str) – Boolean edge attribute that marks one-way movement.

Return type:

UrbanGraph

Returns:

Converted UrbanGraph instance.

Raises:
  • TypeError – If nx_graph is not a NetworkX graph.

  • ValueError – If required CRS, node or edge data is missing or invalid.