1 回答

TA贡献1891条经验 获得超3个赞
OSMnx 没有内置功能,只能在层次结构的某个级别搜索道路。但是您可以通过简单地制作第二个图表来仅搜索您想要的道路类型来做到这一点:
import networkx as nx
import osmnx as ox
ox.config(log_console=True, use_cache=True)
# graph of all the streets you want to model
place = {'city': 'Medellín', 'state': 'Antioquia'}
cf = '["highway"~"motorway|motorway_link|trunk|trunk_link|primary|secondary|tertiary|unclassified|residential"]'
G = ox.graph_from_place(place, network_type='drive', buffer_dist=60000, custom_filter=cf)
# graph of only the streets you want to search
cf_search = '["highway"~"motorway|motorway_link|trunk|trunk_link"]'
G_search = ox.graph_from_place(place, network_type='drive', buffer_dist=60000, custom_filter=cf_search)
print(len(G)) #40341
print(len(G_search)) #4562
# find a node in the road types you want to search
point = -75.54838, 6.22752
orig = ox.get_nearest_node(G_search, point, method='haversine')
dest = list(G)[0]
# impute edge speeds, add travel times, solve shortest path
G = ox.add_edge_speeds(G)
G = ox.add_edge_travel_times(G)
route = nx.shortest_path(G, orig, dest, weight='travel_time')
len(route) #141
添加回答
举报