Creating, visualizing, and managing networks is an important part of GIS. Many types of physical infrastructure such as roads, railways, utilities can be modeled as networks with lines and nodes - with properties attached to them. In this tutorial, we will learn how road networks are commonly modeled and apply some styling techniques to visualize the routing properties. We will also use QGIS3’s built-in tools for network analysis that to find shortest path between 2 points along the network.
We will take a layer of road centerlines for Washington DC, visualize the connectivity and build a network to find shortest path between any 2 points in the city.
District of Columbia government freely shares hundreds of datasets on the Open Data Catalog.
Download the Street Centerlines shared by DCGISopendata data as a shapefile.
For convenience, you may directly download a copy of the datasets from the links below:
Data Source: [DCOPENDATA]
Street_Centerlines.zip
file in the Browser panel. Expand it and drag the Street_Centerlines.shp
file to the canvas.Street_Centerlines
added to the Layers panel. This layer represents each road in Washington DC. Select the Identify tool in the Attributes Toolbar. Click on any road segment to see what attributes are attached to it. There are standard attributes like road name, type etc. there is an attribute called DIRECTIONA
. This is an import attribute for routing as it specifies whether the segment is two-way or one-way. It contains 4 different values. Two Way
for two-way streets. One Way (Digitizing direction)
for one-way streets where the traffic is allowed in the direction of the line (start-point to end-point) and One way (Against digitizing direction)
for one-way streets where the traffic flows in the opposite direction of the line. There is also Unknown
value where we will assume two-way traffic. We will now use the information in that attribute to display an arrow on streets that are one-way.Rule-based
renderer from the drop-down menu.DIRECTIONA
attribute and click All Unique in the right-hand panel. The 4 values that we discussed earlier will appear. Having these values here as a reference helps when building the expression. Also, you can double-click on any value to add them to the expression."DIRECTIONA" = 'One way (Against digitizing direction)' OR "DIRECTIONA" ='One Way (Digitizing direction)'
Marker line
.on center point
under Marker placement.Simple marker
symbol. Scroll down and pick the filled_arrowhead
marker. You will see that the arrow-like symbol now appears on the one-way streets. But all of them are pointing in a single direction, whereas we know that our filter contains roads in multiple directions. We can further refine the symbols with a data-defined override for the Rotation value.angle_at_vertex
function helps us find the angle and use it in the expression. Enter the following expression and click OK.CASE WHEN "DIRECTIONA" = 'One Way (Digitizing direction)' THEN angle_at_vertex($geometry, 1) - 90 WHEN "DIRECTIONA" = 'One way (Against digitizing direction)' THEN angle_at_vertex($geometry, 1) - 90 + 180 END
Street_Centerlines
as the Vector layer representing network. Keep the Path type to calculate as Shortest
. Next we need to pick a start and end point. You can click the ... button and click on any point on the network in the canvas. If you want to replicate the results in this tutorial, you can enter -76.99730092166396,38.887624846748984
as the Start point and -76.99154831062152,38.89151000569929
as the End point. Expand the Advanced parameter section. Choose DIRECTIONA
as the Direction field. You must be familiar with the one-way direction values for forward and backward traffic flow. Enter One Way (Digitizing direction)
as the Value for forward direction and One way (Against digitizing direction)
as the Value for backward direction. Keep other options to their default values and click Run.Shortest path
added to the Layers panel that shows the shortest path between start and end points.This work is licensed under a Creative Commons Attribution 4.0 International License