OSMNX Python程序产生错误“图”包含“没有边”。
在以下代码段中,当坐标之间至少有1个差异时,我能够为纬度和经度产生路线和相应的地图。
但是,在以下方面,仅通过小数点区分(假设您想找到穿越城镇的路线)的坐标我会发现没有图形边缘的错误。
我认为这是因为该程序将起点解释为由于比例而与终点相同吗?
感谢您的帮助!
import osmnx as ox
import networkx as nx
import folium
ox.settings.log_console=True
ox.settings.use_cache=True
# define the start and end locations in latlng
start_lat = float(80.87399)
start_long = float(-117.92435)
end_lat = float(80.91732)
end_long = float(-117.93312)
# location where you want to find your route
place = 'city, state, United States'
# find shortest route based on the mode of travel
mode = 'walk' # 'drive', 'bike', 'walk'
# find shortest path based on distance or time
optimizer = 'length' # 'length','time'
# create graph from OSM within the boundaries of some
# geocodable place(s)
graph = ox.graph_from_place(place, network_type = mode, simplify=True, retain_all=False )
orig_node = ox.nearest_nodes(graph, start_lat,start_long)
dest_node = ox.nearest_nodes(graph, end_lat,end_long)
shortest_route = nx.shortest_path(graph,
orig_node,
dest_node,
weight=optimizer)
route_map = ox.plot_route_folium(graph, shortest_route)
route_map.save('route5.html')
'''
In this following segment of code, I am able to produce a route and a corresponding map for the latitude and longitude when there is a difference of at least 1 between the coordinates.
However, when it comes to following, coordinates that only differentiate by decimal places (say you want to find a route across town) I get the error that there are no graph edges.
I assume this is because the program is interpreting the starting point to be the same as the ending point because of scale?
Thanks for any help!
import osmnx as ox
import networkx as nx
import folium
ox.settings.log_console=True
ox.settings.use_cache=True
# define the start and end locations in latlng
start_lat = float(80.87399)
start_long = float(-117.92435)
end_lat = float(80.91732)
end_long = float(-117.93312)
# location where you want to find your route
place = 'city, state, United States'
# find shortest route based on the mode of travel
mode = 'walk' # 'drive', 'bike', 'walk'
# find shortest path based on distance or time
optimizer = 'length' # 'length','time'
# create graph from OSM within the boundaries of some
# geocodable place(s)
graph = ox.graph_from_place(place, network_type = mode, simplify=True, retain_all=False )
orig_node = ox.nearest_nodes(graph, start_lat,start_long)
dest_node = ox.nearest_nodes(graph, end_lat,end_long)
shortest_route = nx.shortest_path(graph,
orig_node,
dest_node,
weight=optimizer)
route_map = ox.plot_route_folium(graph, shortest_route)
route_map.save('route5.html')
'''
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论