繁体   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