1 回答

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊
OSMnx 沒有內(nèi)置功能,只能在層次結(jié)構(gòu)的某個(gè)級(jí)別搜索道路。但是您可以通過簡(jiǎn)單地制作第二個(gè)圖表來僅搜索您想要的道路類型來做到這一點(diǎn):
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
添加回答
舉報(bào)