OSMNX Python程序产生错误“图”包含“没有边”。

发布于 2025-02-08 03:20:31 字数 1295 浏览 2 评论 0原文

在以下代码段中,当坐标之间至少有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文