首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在找到Osmnx之间的路由时,Osmnx只返回起始和目标OSM ids。

在找到Osmnx之间的路由时,Osmnx只返回起始和目标OSM ids。
EN

Stack Overflow用户
提问于 2022-10-05 07:06:37
回答 1查看 109关注 0票数 0

为了使用osmnx获取两个坐标之间的路由,我使用了以下代码:

代码语言:javascript
运行
复制
import osmnx as ox

ox.config(use_cache=True, log_console=True)
G = ox.graph_from_place('Sydney,New South Wales,Australia', network_type='drive')

import networkx as nx
# find the nearest node to the start location
orig_node = ox.get_nearest_node(G,(intersections['lat'][0],intersections['lon'][0]))
# find the nearest node to the end location
dest_node = ox.get_nearest_node(G,(intersections['lat'][1],intersections['lon'][1]))
shortest_route=nx.shortest_path(G,orig_node,dest_node,weight='time')

其中,交叉口是一个数据,其中包含了各种交叉口的纬度和经度在悉尼。

交叉口‘’lat‘,交叉口’‘lon’代表第0项的纬度和经度等等。

当我绘制这幅图时,我确实得到了适当的结果:显示路线的图解

我获得这些路由中的点的OSM ids,如下所示:

771347,1612748582

但这些似乎是起点和终点本身。是否可以使用osmnx本身获取上面图像中所示路线中的所有坐标。我知道我可以为此使用各种API,但是由于我有75000个点,而且我需要找到所有这些点之间的路径(以及构成路径的坐标),所以我想要一个更有效的解决方案。

EN

回答 1

Stack Overflow用户

发布于 2022-10-05 13:43:24

nx.shortest_path()返回构成路由的节点的OSM ids列表。

osmnx中,您可以使用ox.graph_to_gdfs()获取OSM的节点信息,该信息将返回包含图中所有节点的GeoDataFrame。

一旦有了GeoDataFrame中的所有节点,就可以很容易地提取坐标:

代码语言:javascript
运行
复制
# Get the nodes given the graph, as a GeoDataFrame
nodes = ox.graph_to_gdfs(G, nodes=True, edges=False)
# Extract only the nodes that form your route
nodes = nodes.set_index('id').reindex(shortest_route).reset_index()
# Store all the route information into a DataFrame keeping only useful columns
route_df = nodes[['id', 'lon', 'lat']]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73956882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档