亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

>OSMnx 中的層次結構節點

>OSMnx 中的層次結構節點

寶慕林4294392 2022-11-01 15:02:44
我正在與 OSMnx 和 Networkx 合作解決車輛路由問題。在我試圖實現的解決方案中,我需要一些層次較低的節點直接與層次較高的節點連接,但是,如果 OSMnx 可以選擇這樣做,這會更容易。有人知道OSMnx是否可以做到這一點?謝謝編輯使用 OSMnx,我以這種方式加載具有不同層次結構的圖形和道路節點:G = ox.graph_from_place({'city':'Medellín', 'state':'Antioquia'},network_type='drive', buffer_dist=60000,                                 infrastructure='way["highway"]',                                 custom_filter='["highway"~"motorway|trunk|primary|secondary|tertiary|unclassified|residential"]')custom_filter 為我提供了道路的層次結構。假設我有一個位置并計算離該位置最近的節點,如下所示:orig_node = ox.get_nearest_node(G, c_ori,method='haversine') #c_ori = position原來 orig_node 位于層次較低的道路上(住宅和未分類)。我需要知道 OSMnx 是否有辦法直接將該節點與具有更高層次結構(主干、主干等)的最近節點連接?謝謝
查看完整描述

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


查看完整回答
反對 回復 2022-11-01
  • 1 回答
  • 0 關注
  • 246 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號