【问题标题】:Traffic Congestion Simulation using OSMNX in Python在 Python 中使用 OSMNX 进行交通拥堵模拟
【发布时间】:2022-11-08 04:11:30
【问题描述】:

我正在尝试使用 OSMnx 进行交通流模拟可视化,以使用 Python 从 OpenStreetMaps 中提取数据。我正在尝试对基于代理的拥塞分析进行宏观交通模拟。 我尝试了以下代码以找到最短路径,并且效果很好。

import osmnx as ox
import networkx as nx
ox.config(log_console=True, use_cache=True)
# define the start and end locations in latlng
start_latlng = (37.78497,-122.43327)
end_latlng = (37.78071,-122.41445)
# location where you want to find your route
place     = 'San Francisco, California, United States'
# find shortest route based on the mode of travel
mode      = 'walk'        # 'drive', 'bike', 'walk'
# find shortest path based on distance or time
optimizer = 'time'        # 'length','time'
# create graph from OSM within the boundaries of some 
# geocodable place(s)
graph = ox.graph_from_place(place, network_type = mode)
# find the nearest node to the start location
orig_node = ox.get_nearest_node(graph, start_latlng)
# find the nearest node to the end location
dest_node = ox.get_nearest_node(graph, end_latlng)
#  find the shortest path
shortest_route = nx.shortest_path(graph,
                                  orig_node,
                                  dest_node,
                                  weight=optimizer)

但是对于交通拥堵或拥堵分析,我没有找到任何有关如何将合成拥塞数据包含到 OSMnx 中的文档,例如插入更多汽车并使用 Python 中的 OSMnx 地图可视化模拟结果。 任何帮助表示赞赏, 谢谢,

【问题讨论】:

    标签: python openstreetmap osmnx traffic-simulation


    【解决方案1】:

    简短的回答是 OSMnx 不是流量分析或流量模拟包。您可以 1) 更新图形边权重以表示给定交通条件的新阻抗值,然后重新求解路径,或 2) 保存您的 OSMnx 网络模型并将其导入交通仿真工具以进行进一步分析。

    【讨论】:

    • 非常感谢@gboeing 的回复。但是,我们可以使用 geopanads 例如将数据输入到 osmnx 吗?如果是的话,请提供有关此的任何文档或示例?
    • 是的,您可以按照usage examplesdocumentation 中的说明将GeoPandas GeoDataFrames 加载到OSMnx 中。
    【解决方案2】:

    正如 OSMnx 负责人所说,它不是流量模拟器。但是,我在这里一直在尝试一些想法:https://github.com/donjpierce/traffic 如果这可以帮助您入门。

    我认为最好的方法是从 OSMnx 检索地图,获取每条道路的所有 (x,y) 坐标,然后使用 matplotlib 在您希望汽车所在的道路上绘制点。

    然后,您可以通过编写物理模拟来更新每辆车(即点)的位置,其中每个点都有一个指向道路的速度和速度矢量。以某个增量 dt 更新所有点,将每一帧保存为 PNG,您通常会看到汽车像您期望的那样沿着道路“行驶”。

    【讨论】:

      猜你喜欢
      • 2014-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 2015-08-02
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      相关资源
      最近更新 更多