The example of Hanoi
This guide explains how to build the “Road Network” and “Zones” layers (QGIS vector layers) for traffic modeling with Q-Traf. Hanoi was chosen to demonstrate the software’s capabilities because of it’s massive metropolitan area. Hanoi is the capital and second-most populous municipality of Vietnam, encompassing an area of approximately 3,400 km² (1,296.8 mi²) with a population of nearly 9 million as of 2025 (Wikipedia 2026).
Hanoi (OSM)
How to build a macroscopic traffic model and calculate this road traffic map :


In retrospect, modeling this city presents several challenges :
- The center of Hanoi is dominated by two-wheeled vehicles (motorcycles/scooters)
- There are many complex junctions on two or even three levels
- Numerous roads and peripheral areas are currently under construction
- Crucial information is often not freely available. There is limited data regarding traffic flow direction, one-way streets, or forbidden maneuvers. Furthermore, the resolution of satellite imagery (Google Earth, Bing, etc.) available directly in QGIS is often lower than the original sources.
Here an example of a complex urban junction with three distinct levels :
- An elevated roadway (flyover)
- Ramps on each side
- Side alleys
- A ground-level route under the elevated section

Many projects are in progress :

Step 1 : Finding a Base Layer
First, we must find an open-data network layer in a vector format. For example, the Vietnam road layer (a 646 MB shapefile containing about 3 million links) can be found at Geofabrik (or OSM Wiki). We retain only the Hanoi region, totaling approximately 120 000 links.



Step 2 : Preparing the Road Network Layer
The raw network data is usually not ready for immediate use because :
- Topological Errors : Some links cross intersections without a node connection (they intersect visually but are not logically linked)
- Directionality : All sections are one-way (by construction, each section is represented by one directional link)
- Categorization : Road classification is too simplified
On this figures : One color = One link / line
Some sections / links are too long, and don’t connect to each other (no common end link / node) :
By default, all sections are one-way (since they are represented by only one directional link) :


It is easily corrected in QGIS :
- Splitting : Use the QGIS tool “Split with Lines” to ensure all intersecting lines are cut into elementary links at junctions (nodes).
- Directionality : In Q-Traf and QGis, each section is represented by a line. The lines are directional. So a two-way lanes require two separate links in opposite directions.
- Duplicate the links layer
- Apply the “Reverse line direction” tool to the second layer
- Merge the 2 layers (“combine multiple vector layers » into a single one)
Caution : Divided highways, interchanges, ramps, roundabouts, … are naturally one-way and should not be duplicated. If so, it will be necessary to “clean” all of them by removing the “wrong” way, which can take a lot of time. A faster solution is to create a “One-Way” attribute field, separate these sections from the two-way roads, and only duplicate/reverse the two-way links layer.
Start layer :
Corrected layer :


At this stage, the Hanoi network expands to approximately 350 000 links.
Step 3 : Categorizing Links
The original layer includes tags (pedestrian, cycle path, etc.) that allow to separate major routes from local service roads :
- Major Routes (~50 000 links, in blue) : Motorways, interchanges, grade-separated routes, dual Carriageways, and main urban arteries
- Local streets (~300 000 links, in red) : Residential streets and cul-de-sacs

Step 4 : Initial Assignments
An initial assignment is performed on the major network (50 000 links) to identify main errors.
Zoning and Trip Matrix
Approximately 190 zones are placed (more or less at random) across the metropolitan area (the “zones” QGIS layer). These are located at motorway termini and high-density built-up areas. A 190×190 matrix filled with “2” is created to simulate car trips between these origins and destinations (OD).


Generic modeling parameters (“parameters.csv” file) are sufficient to obtain a 1st assignment.
The first results / lessons learned are a lot of “bad” connections :
- Connectivity Gaps : “Missing” links, or links not connected but very close (1-2 meters gap)
- Some zones are “badly” connected
- Disconnected network parts : Groups of links not connected to the main graph
- Missing Data : Null values in IDs or categories
Each zone is automatically connected to the nearest link end (node). However, if a the nearest link is a one-way link (like a dual carriageway), vehicles may be able to depart but not return (or the opposite)
Many connections / links are missing, with sections not connected but separated by less than a few meters
These defects are resolved during the cleaning phase.
Step 5 : “Cleaning” the road layer
This is a laborious but essential phase. It involves:
- Connecting snapped or nearly-touching links.
- Removing duplicate links.
- Using aerial imagery to manually correct complex interchanges poorly represented by OSM.
Tools for verification:
QGIS provides graphical tools for this:
- Display the direction of traffic with arrows (always on the same side of the links)
- Display links with different colors
- Offset (staggering) the 2 opposite direction of the links


Q-Traf Logs “tools” : The log file gives warnings about “Link ends not connected but very close” and “Duplicate links”. For instance :
- WARNING – Links ends not connected but very close :
- 32 links between 1 and 2 meters apart
- 437 links between 2 and 3 meters apart
- First 20 links separated by 1 to 2 meters : 18118 18126 18126 18623 19005 19274 19274 20001 20016 21195 22704 …
- WARNING – 23 duplicate links : 11890 14362 14977 15071 15243 15337 15338 17951 19056 19057 19077 19081 …
Step 6 : Categorization and first usable network layer and Modeling
After several cycles of assignment and correction, and a better (more detailed) categorization of the links, the results improve.
Here the result with the 50 000 links of the main network (and the zones and the matrix described above) :

=> Attention : This map is provided for illustrative purposes and work material only, and may not be representative of actual road traffic.
We now have a solid foundation to keep on improving :
- The model runs successfully with the primary 50 000-link network
- There is no more major topological errors
Warning : This is a base tool, not the final result :
- The network must be specified (mainly more categories ; number of lanes, capacity, etc)
- The complex work of constructing realistic trip matrices—the other major step—still remains
- (and of course confronting the model with traffic counts)
You can download this project here (in its current state, with only the 50 000 main links – 800 kb) (you need Q-Traf and QGIS to use it ; see Download_Q-Traf).
Warning : The computation time with Q-Traf is about 5 minutes



