[英]How can I get a node object from networkx/OSMnx MultiDiGraph
I want to get a node object from OSMnx's MultiDiGraph by node's attribution.我想通过节点的属性从 OSMnx 的 MultiDiGraph 中获取一个节点对象。 For example, by specifying latitude and longitude coordinates or osmid.
例如,通过指定经纬度坐标或 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)
Have you read the OSMnx documentation and usage examples , and the NetworkX documentation?您是否阅读过 OSMnx文档和使用示例以及NetworkX文档? 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.
他们演示了如何通过 ID 访问节点,OSMnx 文档解释了如何找到最接近某些纬度/经度坐标的节点。
import osmnx as ox
G = ox.graph_from_place("Piedmont, CA, USA", network_type="drive")
# identify OSM ID of node(s) nearest to some point(s)
lat = 37.8262501
lng = -122.2476037
node_id = ox.nearest_nodes(G, lng, lat)
# access some node by its OSM ID
my_node = G.nodes[node_id]
# solve a shortest path between two nodes
path = ox.shortest_path(G, node_id, some_other_node_id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.