Visualising Traffic Data at Intersections: A QGIS Plugin Solution
Visualising traffic is a tricky yet important task in city planning. City of Helsinki was interested in where traffic occurs and in what magnitudes. As there can be vast amounts of traffic data available for a city and the data is geolocated, map visualisations give an intuitive and powerful way to look at the data. Intersections are particularly interesting places to examine since that’s where the most traffic usually occurs. We had a vision of what we wanted: Have traffic flows represented as directional arrows with meaningful colour- and width-coding. In this post, I will introduce a POC-spirited intersection traffic visualisation QGIS plugin we created for the city of Helsinki for this task.
Turning traffic would be represented with a curved arrow that would trail close to the intersection centre. We considered utilising road geometry data to create visualisations trailing accurately the roads, but ended up deciding that it was unnecessary and would potentially have even less illustrative power than freely created curved arrows. With the goal in mind, we dove into inspecting the data we had in our hands.
Combining the data
As a starting point we had two datasets: One vector point file showing roughly the intersection branch locations and another vector point file with the traffic data (where the points were located approximately at the intersection centre). We had traffic data for multiple days and individual hours in addition to sums for a given day, but decided that we would not focus our efforts on creating any interface for time selection and that the plugin would simply aggregate all data for each location. It would be up to the user to filter their data before running the plugin.
What we wanted was a dataset where one line or curve feature would have the traffic data from branch A to branch B. Fortunately, the datasets had two fields serving as links for combining: intersection ID and intersection branch ID. With intersection ID we could find the correct set of branch geometries for each traffic data point, and with intersection branch ID we could then find the specific branch point locations for each individual traffic data point.
Here are the processing steps for those interested in details:
- Find all unique intersections from traffic data
- For each intersection one at a time…
- Select features from both datasets that belong to the intersection
- Calculate an approximate intersection centre point from the branch location points
- For each traffic data feature in the current intersection one at a time…
- Find branch location points that correspond to the centre and end points for the traffic data feature
- Calculate the middle point between the start and end points of the previous step
After this, we had one dataset with line features consisting of three points, with traffic data attached. This was what we had wanted but not yet very illustrative.
Adjusting the geometries
Even with styling, our new geometry layer wasn’t very good yet – the traffic lines from A to B and from B to A were on top of each other and the lines for turns did not have any illustrative curvature. The next step was to make adjustments for the produced geometries. With trial and error, we ended up with some constant values by which we moved the lines either away or towards the intersection centre to avoid overlap and represent right-hand traffic.
Another geometry adjustment was to move the middle point of the line representing turning traffic towards the intersection centre. As we were anyway not aiming to accurately follow the road geometries, we decided that moving the centre point of the line half way towards the centre of the intersection already added a fair amount of illustrative power to the visualisation.
Lastly, we discarded the idea of using straight lines and chose to use CompoundCurve line type in QGIS. We simply used the start, middle and end points we calculated earlier and created the curved geometry from them.
From geometries to visualisation
Now that we had the geometries with traffic data as an attribute, the last task was to come up with illustrative styles. We had already thought in the beginning of the project that line width and colour are the two most intuitive styling options we want to utilise. Ultimately, it was quite simple to apply the styling since we had only one important variable to show: the amount of traffic. However, in testing we noticed that putting a colour or width scale for the whole dataset was not always very helpful when inspecting some smaller areas, and therefore we created two extra styles where the scaling was created separately for each intersection. The four different QGIS visualisation styles we created are:
- Colours-global: This style colour-codes the traffic lines globally; the minimum and maximum are taken from the whole dataset. Red represents a high amount of traffic and blue less traffic. The widths of the traffic lines do not change. This style works well if one wants to compare several intersections with each other and not obstruct any background details by widening the lines.
- Colours-local: Here the traffic lines are colour-coded for each intersection separately. This means that different intersections are not directly comparable with each other, as the same colour can signify different traffic amounts. However, in this style it is easier to distinguish variability within each one intersection, and so it fits when intersections are inspected one at a time. Red represents a high amount of traffic and blue less traffic. Here the line widths remain constant as in the other colour-coded style.
- Sizes-global: In this style, the line widths show the amount of traffic. The size scaling is linear with minimum and maximum from the whole dataset (although 0 traffic is still represented with a very narrow line!). Line colour represents the entry direction to the intersection. Sizes are a very intuitive and powerful visual element for the human eye and consequently for many the size scaling style is their preferred style to easily compare traffic flows.
- Sizes-local: As you might have guessed already, the only difference with this style and the previous one is that now the line widths are scaled within each intersection, not with the whole dataset. This style can be better for inspecting intersections one at a time since the visual differences are clearer within an intersection.
Afterthoughts
At the end of the project we were quite happy with the results. We had different visualization styles for different needs, and we had reached our goal without having to resort to any road geometry dataset. As the project’s aim was to demonstrate and test ways to visualize traffic data, the created workflow and QGIS plugin are applicable for the specific datasets we used.