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) – Clipping polygon in the same CRS as the graph.

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.