【问题标题】:Fastest way to project a graph onto espg:4326 in OSmnx在 OSmnx 中将图形投影到 epsg:4326 的最快方法
【发布时间】:2020-06-20 05:13:46
【问题描述】:

我使用 OSmnx 的 osmnx.graph_project 首先将我的图形投影到 UTM 坐标系上,以便使用 consolidate_intersections 函数,然后 ox.project_graph(G_proj_ConsolidateIntersection, to_crs='epsg:4326') 将其投影到纬度-经度坐标系上,以便使用 ox.get_nearest_nodes .最后一个投影需要很长时间(5 分钟),而第一个投影在几秒钟内完成。有没有更好更快的投影到 epsg:4326 的方法?我有looked at this answer 但是当我执行这行gdf = gpd.GeoDataFrame(geometry=intersections) 时,我收到以下错误:

ValueError: Unknown column

这是一个极端的例子(我正在处理的图表较小,但我希望它能说明我的观点):

import osmnx as ox
G = ox.graph_from_place('Edmonton, Canada', network_type='drive', simplify=False)
# 39.1 s

G_proj = ox.project_graph(G)
# 15.9 s

G_proj_ConsolidateIntersection = ox.consolidate_intersections(G_proj)
# 14 min 45 s

G_proj_ConsolidateIntersection_LatLon = ox.project_graph(G_proj_ConsolidateIntersection, to_crs='epsg:4326')
# 44 min 35 s

gpd.GeoDataFrame(geometry=G_proj_ConsolidateIntersection) 也会引发 Unknown column 错误。

【问题讨论】:

  • 请提供一个完整的最小可重现示例,我会看看。
  • @gboeing 刚刚用一个例子更新了这个问题。如果您需要更多信息,请告诉我。

标签: python osmnx


【解决方案1】:

两件事。首先,确保您使用的是最新版本的 OSMnx,因为在之前的版本中有显着的性能增强。其次,如果您先简化图表,这一切都会快得多。

但更重要的是,合并交叉点实际上没有意义除非您已经简化了图表,因为现实世界中的“交叉点”的概念在未简化(扩展)中是没有意义的图形。只有当图被简化时,模型的节点才会映射到现实世界的交叉点和死胡同的概念。有关详细信息,请参阅文档和相关文献。

这是一个比较原始时序(左)和我的简化时序(右)的代码 sn-p:

import osmnx as ox
ox.config(use_cache=True, log_console=True)

G = ox.graph_from_place('Edmonton, Canada', network_type='drive', simplify=True)
# 39.1 s vs 18.2 s

G_proj = ox.project_graph(G)
# 15.9 s vs 8.9 s

G_proj_con = ox.consolidate_intersections(G_proj)
# 14 m 45 s vs 24.2 s

G_con = ox.project_graph(G_proj_con, to_crs='epsg:4326')
# 44 m 35 s vs 6.4 s

编辑:我刚刚重新运行了上面共享的代码 sn-p,但更改了 simplify=False,我使用最新版本的时间仍然比您看到的要快得多。例如,上面的最后两行代码分别在 6m 20s 和 12s 内完成(与您的 14m 45s 和 44m 35s 时间相比)。

【讨论】:

  • 感谢您的详细解答。我使用的是 0.13.0 版。我将更新软件包并检查性能。我首先通过simplify=False 的原因是因为我想将具有曲率的街道划分为更多部分,而simplify=True 会丢失这一点:# finally remove all the interstitial nodes between the new edges G.remove_nodes_from(set(all_nodes_to_remove)) 使用consolidate_intersections 然后有助于清理交叉路口,同时保留更多交叉点之间的节点。如果有其他方法可以做到这一点,请告诉我。
  • 我用 0.14.1 版本运行了我的代码,它快了很多。在我目前正在工作的图表上,过去运行ox.consolidate_intersections(G_proj) 需要 5 分钟,现在只需不到 2 分钟即可完成。将其投影到epsg:4326 也需要 9 秒。新的更新速度更快。
  • 很高兴听到这个消息。
猜你喜欢
  • 2020-06-08
  • 2017-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-31
  • 2019-07-03
  • 1970-01-01
  • 2011-11-26
相关资源
最近更新 更多