如何在osmnx中下载和构造图形?

时间:2018-11-08 09:35:48

标签: python geospatial 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)

谢谢。

1 个答案:

答案 0 :(得分: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。