0

使用 OSMnx,我希望能够保存具有曲率的路径,如下图所示。

import osmnx as ox
import networkx as nx

# Download the road network
G = ox.graph_from_place('Monterey, California', network_type='drive')

# Starting and ending point of a trip
start = [36.580665,-121.8297467]
end = [36.594319,-121.8727587]

# Retrieve nearest node
orig_node = ox.get_nearest_node(G, start)
dest_node = ox.get_nearest_node(G, end)

# Compute the path of the trip
route = nx.shortest_path(G, orig_node, dest_node, weight='length')

# Plot the trip
fig, ax = ox.plot_graph_route(G_projected,
                              route,edge_linewidth=1,
                              node_size=20,
                              fig_height=20,route_linewidth=10)

在此处输入图像描述

显然,我可以保存路由 python 列表,但我会丢失路径的曲率,因为路由列表包含的节点较少。是否可以以谷歌折线格式或类似的格式保存显示的红色路线以保存其弯曲形状?

4

1 回答 1

2

您可以将路线的边缘几何图形转换为 MultiLineString:

from shapely.geometry import MultiLineString
route_pairwise = zip(route[:-1], route[1:])
edges = ox.graph_to_gdfs(G, nodes=False).set_index(['u', 'v']).sort_index()
lines = [edges.loc[uv, 'geometry'].iloc[0] for uv in route_pairwise]
MultiLineString(lines)

现在您可以访问 MultiLineString 的.wkt属性并将Well-Known Text字符串保存到磁盘。

于 2019-02-12T14:38:54.830 回答