簡體   English   中英

如何在osmnx中下載和構建圖形?

[英]How to download and constrtuct a graph in osmnx?

我嘗試以下代碼:

G = ox.graph_from_place('Greater London, UK', network_type='walk')

但它不斷給出以下錯誤:

ConnectionError: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?format=json&limit=1&dedupe=0&polygon_geojson=1&q=Greater+London%2C+UK (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f50301d5470>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))

有人知道這個錯誤嗎? 還有一種方法可以從邊緣和節點在 osmnx 中構建圖形嗎? 從以下代碼:

G = ox.gdfs_to_graph(london_nodes, london_edges)

我也不斷收到以下錯誤:

~/miniconda3/lib/python3.6/site-packages/osmnx/save_load.py in gdfs_to_graph(gdf_nodes, gdf_edges)
600     G = nx.MultiDiGraph()
601     G.graph['crs'] = gdf_nodes.crs
--> 602     G.graph['name'] = gdf_nodes.gdf_name.rstrip('_nodes')
603 
604     # add the nodes and their attributes to the graph

~/miniconda3/lib/python3.6/site-packages/pandas/core/generic.py in __getattr__(self, name)
 4374             if self._info_axis._can_hold_identifiers_and_holds_name(name):
 4375                 return self[name]
-> 4376             return object.__getattribute__(self, name)
 4377 
 4378     def __setattr__(self, name, value):

AttributeError: 'GeoDataFrame' object has no attribute 'gdf_name'

節點之前已保存為:

london_nodes = ox.save_load.graph_to_gdfs(G, nodes=True, edges=False)

和邊緣為:

london_edges = ox.save_load.graph_to_gdfs(G, nodes=False, edges=True)

提前致謝。

關於您關於 ConnectionError 的第一個問題,看起來 Overpass API 已關閉。 如果你再試一次,它應該可以工作。

關於您的第二個問題,是的,您可以在 MultiDiGraphs 和 GeoDataFrames 之間進行轉換:

import osmnx as ox
ox.config(log_console=True, use_cache=True)
G = ox.graph_from_place('Piedmont, CA, USA', network_type='drive')
nodes, edges = ox.graph_to_gdfs(G)
G2 = ox.gdfs_to_graph(nodes, edges)

正如您從錯誤消息中看到的那樣,OSMnx 確實希望其所有“預期機制”都存在以進行轉換(例如,包括 GeoDataFrames 上的 gdf_name 屬性)。 您不能只轉換任何舊的 GeoDataFrames。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM