iduedu.gdf_to_graph

iduedu.gdf_to_graph(gdf, project_gdf_attr=True, reproject_to_utm_crs=True, speed=5, check_intersections=True)[source]

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

Explodes multilines, optionally enforces topological intersections, merges collinear segments, transfers selected attributes back to merged lines via centroid-buffer spatial join, and constructs a directed graph whose edges correspond to line segments. Lengths are computed in meters in a local metric CRS; travel time uses a provided speed.

Parameters:
  • gdf (geopandas.GeoDataFrame) – Input with LineString geometries (other types are filtered out).

  • project_gdf_attr (bool) – If True, projects original attributes to merged lines via nearest overlay.

  • reproject_to_utm_crs (bool) – If True, lengths computed in UTM and optionally reprojected back.

  • speed (float) – Speed in km/h used to compute time_min for each edge.

  • check_intersections (bool) – If True, uses shapely.node before line_merge to enforce proper splits.

Returns:

Directed graph with:
  • node attributes: x, y;

  • edge attributes: geometry, length_meter, time_min, plus projected attributes;

Graph attribute graph[“crs”] is set to the (possibly reprojected) CRS.

Return type:

(nx.DiGraph)

Raises:

ValueError – If the input contains no valid LineStrings.

Notes

  • Attribute projection aggregates multi-matches via a uniqueness reducer (unique_list).

  • speed is internally converted to meters/minute.