首页 > 解决方案 > Osmnx:从 shapefile/XML 创建图形

问题描述

我正在学习如何对国家的道路网络进行网络分析。我已经有了 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

我不确定我说错了还是文件格式错误。

标签: pythonxmlopenstreetmapnetworkxosmnx

解决方案


你有错误的文件格式。您不能仅将任何文件结构转换为 XML,然后将其读入。相反,您可以直接将 OSM 数据的提取下载为 XML 格式的 .osm 文件。然后用 OSMnx加载它。


推荐阅读