iduedu.clip_nx_graph

iduedu.clip_nx_graph(graph, polygon)[source]

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

Builds a GeoDataFrame of node points using graph.graph[“crs”], clips it by the given polygon, then returns the node-induced subgraph (keeping original node/edge attributes).

Parameters:
  • graph (networkx.Graph) – Graph with node coords stored as x, y and a CRS in graph.graph[“crs”].

  • polygon (Polygon | gpd.GeoSeries | gpd.GeoDataFrame) – Clipping polygon: a shapely geometry in EPSG:4326, as territory of the graph builders, or a GeoSeries / GeoDataFrame in any CRS.

Returns:

Subgraph containing only nodes whose points fall inside the polygon.

Return type:

(nx.Graph)

Notes

Edges are preserved only if both endpoints remain in the subgraph.