【发布时间】:2019-03-21 04:22:25
【问题描述】:
我正在学习如何对国家/地区的道路网络进行网络分析。我已经有了 shapefile。 我一直在尝试将它们转换为 networkx,但没有取得多大成功,所以我尝试使用 ox.graph_from_file 函数来完成它。从 osm 获取国家级数据非常耗时/耗费内存,而且对于我想做的事情来说过于详细。
我使用 mapshaper 将 shapefile 转换为 .xml 文件,但 ox.graph_from_file 不起作用。我只是这样称呼它:
ox.graph_from_file('/Users/macbookair/Downloads/road_rmms_v10_3.xml')
---------------------------------------------------------------------------
EmptyOverpassResponse Traceback (most recent call last)
<ipython-input-4-5f835eba75d0> in <module>()
----> 1 ox.graph_from_file('/Users/macbookair/Downloads/road_rmms_v10_3.xml')
/anaconda3/lib/python3.6/site-packages/osmnx/core.py in graph_from_file(filename, network_type, simplify, retain_all, name)
1898 # create graph using this response JSON
1899 G = create_graph(response_jsons, network_type=network_type,
-> 1900 retain_all=retain_all, name=name)
1901
1902 # simplify the graph topology as the last step.
/anaconda3/lib/python3.6/site-packages/osmnx/core.py in create_graph(response_jsons, name, retain_all, network_type)
1327 elements.extend(response_json['elements'])
1328 if len(elements) < 1:
-> 1329 raise EmptyOverpassResponse('There are no data elements in the response JSON objects')
1330
1331 # create the graph as a MultiDiGraph and set the original CRS to default_crs
EmptyOverpassResponse: There are no data elements in the response JSON objects
我不确定是我说错了还是我的文件格式不正确。
【问题讨论】:
-
"我将 shapefile 转换为 .xml 文件" 你为什么首先使用 shapefile? OSM 数据通常存储为 PBF 或 XML。从 XML -> Shapefile -> XML 的转换肯定会丢失信息。首先尝试 OSM XML,直接下载 XML 或将 PBF 转换为 XML。
-
我已经有了完成任务必须使用的 shapefile:它们只有一些国家的国道和高速公路。从 OSM 导入国家数据(使用 osmnx 创建图表)根本没有效率,需要几个小时。
标签: python xml openstreetmap networkx osmnx