我希望通过节点的属性从OSMnx的MultiDiGraph中获取节点对象。例如,通过指定纬度和经度坐标或osmid。但现在我只能通过列表索引。
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)
发布于 2022-05-26 17:03:44
您读过OSMnx 文档和使用实例以及NetworkX文档吗?它们演示了如何通过节点ID访问节点,OSMnx文档解释了如何找到最接近lat/long坐标的节点。
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)
https://stackoverflow.com/questions/72391216
复制相似问题