我如何从NetworkX/OSMNX多边形获取节点对象
我想通过Node的归因从OSMNX的Multidigraph获取一个节点对象。例如,通过指定纬度和经度坐标或渗透。但是现在,我只能通过列表索引获取它。
import osmnx as ox
# G: MultiDiGraph
G = ox.graph_from_bbox(n, s, e, w, network_type='all')
# get node by node's index
orig = list(G)[5]
dest = list(G)[24]
# Is there a way similar to the following?
# orig = G.nodes(osmid="123456")
route = ox.shortest_path(G, orig, dest, weight="length")
fig, ax = ox.plot_graph_route(G, route, route_color="r", route_linewidth=6, node_size=2)
I want to get a node object from OSMnx's MultiDiGraph by node's attribution. For example, by specifying latitude and longitude coordinates or osmid. But now I can only get it through the list index.
import osmnx as ox
# G: MultiDiGraph
G = ox.graph_from_bbox(n, s, e, w, network_type='all')
# get node by node's index
orig = list(G)[5]
dest = list(G)[24]
# Is there a way similar to the following?
# orig = G.nodes(osmid="123456")
route = ox.shortest_path(G, orig, dest, weight="length")
fig, ax = ox.plot_graph_route(G, route, route_color="r", route_linewidth=6, node_size=2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您阅读OSMNX 用法示例和 networkx 文档?他们演示了如何通过其ID访问节点,并且OSMNX DOCS解释了如何找到最接近某些LAT/长坐标的节点。
Have you read the OSMnx documentation and usage examples, and the NetworkX documentation? They demonstrate how to access a node by its ID, and the OSMnx docs explain how to find the node nearest to some lat/long coordinates.