为了账号安全,请及时绑定邮箱和手机立即绑定

如何根据 osmnx 上的一些“手动选择”节点绘制路径?

如何根据 osmnx 上的一些“手动选择”节点绘制路径?

绝地无双 2021-10-19 16:16:19
我想在 osmnx 地图上绘制一条路线。当我尝试手动创建路线时,它不起作用。import networkx as nximport osmnx as oximport requests import matplotlib.cm as cmimport matplotlib.colors as colorslocation_point = (50.345559621674596, 7.576892382877531)G = ox.graph_from_point(location_point, distance=500, distance_type='network', network_type='walk')origin_node = ox.get_nearest_node(G, location_point)destination_node = list(G.nodes())[-1]fig, ax = ox.plot_graph(G)G=nx.convert_node_labels_to_integers(G)route = [3 ,1 ,41 ,40 ,98 ,62 ,67 ,107 ,94 ,83 ,39 ]ox.plot_route_folium(G,route)我希望有一张带有彩色路线的地图,但我却收到了这个错误。    ---------------------------------------------------------------------------    IndexError                                Traceback (most recent call last)    <ipython-input-9-11235dc07ef4> in <module>()    ----> 1 ox.plot_route_folium(G,route)    ~\Anaconda3\lib\site-packages\osmnx\plot.py in plot_route_folium(G, route, route_map, popup_attribute, tiles, zoom, fit_bounds, route_color, route_width, route_opacity)        907     gdf_edges = graph_to_gdfs(G, nodes=False, fill_edge_geometry=True)        908     route_nodes = list(zip(route[:-1], route[1:]))    --> 909     index = [gdf_edges[(gdf_edges['u']==u) & (gdf_edges['v']==v)].index[0] for u, v in route_nodes]        910     gdf_route_edges = gdf_edges.loc[index]        911     ~\Anaconda3\lib\site-packages\osmnx\plot.py in <listcomp>(.0)        907     gdf_edges = graph_to_gdfs(G, nodes=False, fill_edge_geometry=True)        908     route_nodes = list(zip(route[:-1], route[1:]))    --> 909     index = [gdf_edges[(gdf_edges['u']==u) & (gdf_edges['v']==v)].index[0] for u, v in route_nodes]        910     gdf_route_edges = gdf_edges.loc[index]        911 如果我尝试通过最短路径算法找到路线并将其在地图上可视化,则效果很好。但我想绘制这条特定路线
查看完整描述

2 回答

?
FFIVE

TA贡献1797条经验 获得超6个赞

OSMnx 使用节点的 OSMID。当您运行时G=nx.convert_node_labels_to_integers(G),您会覆盖这些 OSMID。但是,您也没有在图边uv属性中覆盖它们,这些属性标识了边的端点(使用 OSMID)。


查看完整回答
反对 回复 2021-10-19
  • 2 回答
  • 0 关注
  • 307 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信