1

我尝试以下代码:

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)

提前致谢。

4

1 回答 1

1

关于您关于 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 属性)。您不能只转换任何旧的 GeoDataFrame。

于 2018-11-12T22:14:35.857 回答