How to Build a SUMO Traffic Data Query Module (Coordinate/Edge → Q/K/V/Travel Time)
I’m developing a Python module/interface to extract and standardize traffic metrics from SUMO simulations. The goal is to allow flexible input types (e.g., coordinates, edge/lane IDs, positions along an edge) and output structured traffic data such as: Flow (Q), Density (K), Speed (V), Travel time and so on.
Requirements: Accept various types of spatial input: Coordinates (x, y), Edge/lane IDs, Position along an edge (e.g., at 100m of edge X). Return structured output (JSON/CSV format). Optionally wrap this in a simple GUI for easy use.
Is there any existing SUMO utility or Python library that already supports this kind of spatial query and data extraction?
If not, what’s the most efficient way to implement this goal? How to map coordinates to edge/lane IDs. How to extract section-based traffic metrics (e.g., flow or speed at a specific position along an edge)?
Any guidance or pointers would be greatly appreciated!
You can use sumolib.net.getNeighboringEdges (ref) to find edges close to a certain coordinate. Do you want your interface to run while your simulating or just replay/have a static view after SUMO finished? If you need it to be dynamic then you have to use TraCI to query data - otherwise you can use the several output files. We have detectors which can give you values regarding a cross section or a stretch along lane(s).
You can use
sumolib.net.getNeighboringEdges(ref) to find edges close to a certain coordinate. Do you want your interface to run while your simulating or just replay/have a static view after SUMO finished? If you need it to be dynamic then you have to use TraCI to query data - otherwise you can use the several output files. We have detectors which can give you values regarding a cross section or a stretch along lane(s).
Thanks a lot for the clarification!
I'm currently aiming to analyze static data after the simulation, not during runtime. Based on your suggestions, I now understand that the right workflow for me is:
- Run the simulation and generate output files (e.g.,
edgeData.xml,fcd.xml, etc.). (have finished.) - Post-process these outputs to extract relevant traffic metrics
- Build a simple UI to load, query, and visualize the data
Right now, my main challenge is I’m not sure how to map my input (e.g., coordinates, edge IDs, or positions along an edge) to the relevant output data.
More specifically:
- Which output file contains which traffic metric (e.g., flow, speed, density, travel time)?
- How can I associate a given spatial input (like a coordinate, a section or 100m mark on an edge) with the right data entry in the output?
Any guidance, tools, or examples that help connect spatial input to simulation output would be really appreciated!
see https://sumo.dlr.de/docs/Geo-Coordinates.html