def subgraph_within_box(self, bounding_box):
"""
Extract a subgraph bounded by a box.
:param bounding_box: the bounding coordinates in
(minx, miny, maxx, maxy) or a Polygon instance
:return: a subgraph of nx.Graph
"""
if isinstance(bounding_box, Polygon):
bbox = bounding_box
else:
bbox = box(bounding_box[0], bounding_box[1],
bounding_box[2], bounding_box[3])
nbunch = set()
for edge in self.graph.edges():
s, e = edge
if bbox.intersects(LineString([self.node_xy[s], self.node_xy[e]])):
nbunch.add(s)
nbunch.add(e)
return self.graph.subgraph(nbunch)
评论列表
文章目录