iduedu.graph_to_gdf

iduedu.graph_to_gdf(graph, edges=True, nodes=True, restore_edge_geom=False)[source]

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

Reads CRS from graph.graph[“crs”]. Depending on flags, returns only nodes, only edges, or a concatenation of both. Optionally reconstructs missing edge geometries from node points.

Parameters:
  • graph (nx.MultiDiGraph) – Graph with node coords (x, y) and optional edge geometry.

  • edges (bool) – If True, include edges.

  • nodes (bool) – If True, include nodes.

  • restore_edge_geom (bool) – If True, fill empty edge geometries from node coordinates.

Returns:

Nodes and/or edges as GeoDataFrame(s).

If both edges and nodes are False, returns None.

Return type:

(gpd.GeoDataFrame | None)

Raises:

ValueError – If graph.graph[“crs”] is missing.

Notes

  • Edge GeoDataFrame uses MultiIndex (u, v).

  • When both are requested, the result is a vertical concat of nodes then edges.