我正在尝试绘制一个网络,其中边缘根据其 Opens 街道地图属性(“高速公路”)具有不同的颜色。如果我使用它,它会起作用ox.graph
,但是,这会生成一个静态地图。如果我使用,ox.plot.plot_graph_folium()
如果我将所有边缘设置为具有相同的颜色,我只会得到一个交互式地图。如果我为 edge_color 分配一个颜色列表,它就不起作用。
import osmnx as ox
address_name='19, Molstraat, Van Leeuwenhoekkwartier, Delft, South Holland, Netherlands, 2611EM, Netherlands'
graph=ox.graph_from_address(address_name, distance=300)
ec = ['skyblue' if data['highway']=='footway'
else 'paleturquoise' if data['highway']=='residential'
else 'orange' if data['highway']=='cycleway'
else 'sienna' if data['highway']=='service'
else 'lightgreen' if data['highway']=='living street'
else 'grey' if data['highway']=='secondary'
else 'lightskyblue' if data['highway']=='pedestrian'
else 'black' for u, v, key, data in graph.edges(keys=True, data=True)]
#this works, but is static
ox.plot_graph(graph,fig_height=8,fig_width=8,node_size=0, edge_color=ec)
#this does not work
import folium
ox.plot.plot_graph_folium(graph, popup_attribute='highway',edge_color=ec) …
Run Code Online (Sandbox Code Playgroud) 我想使用 Osmnx 获取最短路径中节点之间的旅行时间。有没有办法获得节点之间的旅行时间。
import networkx as nx
import osmnx as ox
ox.config(use_cache=True, log_console=True)
import pandas as pd
pla__version__Piedmont, CA, USA
G = ox.graph_from_place(place, network_type='drive')
orig = list(G)[0]
dest = list(G)[-1]
route = nx.shortest_path(G, orig, dest)
#fig, ax = ox.plot_graph_route(G, route, route_linewidth=6, node_size=0, bgcolor='k')
for i, val in enumerate(route):
print(i, val, G.nodes[val]['x'], G.nodes[val]['y'])
Run Code Online (Sandbox Code Playgroud)
我想存储在上述循环中实现的节点、纬度和经度,但是有没有办法也存储两个节点之间的行程时间和/或两个节点之间的距离。