python - 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
我不确定我说错了还是文件格式错误。
解决方案
你有错误的文件格式。您不能仅将任何文件结构转换为 XML,然后将其读入。相反,您可以直接将 OSM 数据的提取下载为 XML 格式的 .osm 文件。然后用 OSMnx加载它。
推荐阅读
- javascript - 在图表中显示分组数据(不同颜色)的图例
- python-3.x - 如何将大图像数据集转换为 csv 文件?
- discord.py - Discord.py:浏览特定频道的历史,选择随机消息并发送它的链接
- wget - wget:如何排除某些已知之外的子域?
- android - React Native Android:找不到标签-1的视图管理器可能是由React Native Reanimated引起的
- mysql - 在 MySQL 中连续存储每个产品的时间序列数据的最佳方法
- c# - 使用嵌套类构建 xUnit 测试
- html - 固定底部的 CSS 媒体查询位置元素不相对于父元素
- javascript - 在异步函数中放置等待的位置
- ios - 旋转效果在导航视图中未按预期工作,但在不在导航视图中的任何其他视图中按预期工作