我目前正在学习数据科学课程,并正在开展一个研究城市复杂性演变的项目。我的目标是分析和比较北卡罗来纳州夏洛特市 OpenStreetMap (OSM) 的可视化和数据,重点关注 2020 年 2 月 8 日和 2024 年 2 月 8 日的数据。有没有办法获取过去的数据?
我已成功下载 OSMnx 软件包,不知道下一步该做什么。
是的,可以使用 attic data 查看 OSM 在 osmnx 中特定时间点存在的状态。
为了请求此数据,您需要更改
overpass_settings
以请求特定日期的数据。
示例:
import osmnx as ox
# Must be an overpass instance which supports attic
ox.settings.overpass_endpoint = "https://overpass-api.de/api"
def query_year(coordinate, year):
date = f'{year}-01-01T00:00:00Z'
# Request attic data
ox.settings.overpass_settings = '[out:json][timeout:{timeout}][date:"' + date + '"]{maxsize}'
graph = ox.graph.graph_from_point(coordinate, dist=1000)
# Restore old settings
ox.settings.overpass_settings = '[out:json][timeout:{timeout}]{maxsize}'
return graph
使用此功能和
ox.plot.plot_graph()
,我制作了一个动画,展示博尔德市中心的道路网络在 8 年来如何变化。这是您可以使用阁楼数据的示例。
本示例使用
ox.graph.graph_from_point()
,但每个从 Overpass 查询数据的函数都可以使用此技术来获取阁楼数据。以下是支持此功能的函数列表:
osmnx.features.features_from_address()
osmnx.features.features_from_bbox()
osmnx.features.features_from_place()
osmnx.features.features_from_point()
osmnx.features.features_from_polygon()
osmnx.graph.graph_from_address()
osmnx.graph.graph_from_bbox()
osmnx.graph.graph_from_place()
osmnx.graph.graph_from_point()
osmnx.graph.graph_from_polygon()
此技术有一些注意事项:
https://overpass-api.de/api
支持阁楼数据,但将来可能并非如此。您可以查阅此列表来查找支持阁楼数据的端点。ox.settings.overpass_settings
是全局的,因此更改一个函数中的查询日期会更改所有函数的查询日期。因此,上面的代码示例在查询完成后立即恢复原始设置。