def voronoi_partition(G, outline):
"""
For 2D-embedded graph `G`, within the boundary given by the shapely polygon
`outline`, returns `G` with the Voronoi cell region as an additional node
attribute.
"""
#following line from vresutils.graph caused a bug
#G = polygon_subgraph(G, outline, copy=False)
points = list(vresutils.graph.get_node_attributes(G, 'pos').values())
regions = vresutils.graph.voronoi_partition_pts(points, outline, no_multipolygons=True)
nx.set_node_attributes(G, 'region', dict(zip(G.nodes(), regions)))
return G
评论列表
文章目录