小编Luc*_*rma的帖子

转换为 LineString 时的最短路线会错过 OSMNX 中的路径

我正在尝试将使用 OSMNX 绘制的路线保存到磁盘。生成的路线遵循道路路径,但是,当我尝试将路径转换为可以轻松保存到磁盘的 LineString 时,路线会以不遵循可以在两个图像之间进行比较的道路的方式进行更改。

ORIGIN_point = (13.013206, 77.670987)
DESTINATION_point= (12.821339, 77.678500)          

G = ox.graph_from_point(ORIGIN_point, distance=10000, distance_type='network', network_type='drive')      

ORIGIN_node  = ox.get_nearest_node(G, ORIGIN_point)
DESTINATION_node  = ox.get_nearest_node(G, DESTINATION_point)                   




# find the route between these nodes then plot it
route = nx.shortest_path(G, ORIGIN_node, DESTINATION_node, weight='length')
Run Code Online (Sandbox Code Playgroud)

该路线是使用 osmnx 绘制的最短路径IMAGE-1

from shapely.geometry import LineString, Point

graph_proj = ox.project_graph(G)
nodes_proj, edges_proj = ox.graph_to_gdfs(graph_proj, nodes=True, edges=True)
route_nodes = nodes_proj.loc[route]

# Create a geometry for the shortest path
route_line = LineString(list(route_nodes.geometry.values))
Run Code Online (Sandbox Code Playgroud)

路线现在转换为 lineString IMAGE-2

我想将路径保存到磁盘的形状文件中,请帮助我。

python shapely osmnx

3
推荐指数
1
解决办法
1420
查看次数

标签 统计

osmnx ×1

python ×1

shapely ×1