QGIS approach: A simple thematic map#
Introduction#
This tutorial focuses on creating static maps using network data from Open Street Map (OSM). In this first tutorial, the emphasis is on woking with colors, layout, and map elements. The goal is to get familiarized with data acquisition for QGIS and practice color choice and layouting in maps.
QGIS downloads:
How to follow this tutorial#
These instructions will guide you through a practical in QGIS. The instructions will alternate between text blocks like this and
Instruction blocks like these
Text blocks offer guidance and background information whereas instruction blocks prompt you to do something in QGIS, such as:
Open QGIS.
As this is an advanced course, the instructions will expect that the basic functionalities of QGIS and GIS concepts (layers, attribute tables, processing tools, styling etc.) are familiar to the reader. Thus, we will try to keep point-by-point instructions to a minimum.
Blocks of texts or code excerpts to copy and paste into QGIS will occassionally be given. The excerpts
will be provided within a code quote like this.
Or in a code block like this
QGIS is very good for many purposes, but there are things it is simply not built for, such as creating time-series plots. Occasionally, these tutorials will include blocks of Python code – to run them, open up the Binder workplace of this course (check if this makes sense)
Finally, there will be example visualizations throughout the instructions. We encourage you to experiment and create maps that you like – however, if you want to recreate the examples for reference, the layer style files to do so will be shared as .qml files in the folder QGIS-files in each week’s practical directory. Alongside the examples maps is a block that tells which style file(s) are used. For example:
This example uses the layer style: example_style.qml
Prerequisites#
In this practical, we will need to download street network data from OSM. The simplest way to do that within QGIS is to use the QuickOSM plugin. QuickOSM (see documentation) provides a user interface to get data from OSM using the Overpass API.
Navigate to Plugins -> Manage and install plugins…
Type quickosm into the search bar and install the plugin.
The plugin is now installed under Vector drop-down menu.
Retrieving and modifying street network data#
Here we define our area of interest and get the corresponding street network from OpenStreetMap. We will retrieve streets for Kamppi, Helsinki. OSM data is richly tagged with keys and values – for this acquisition, we will use the highway tag.
Open QuickOSM.
Look at the Key/Value table the Quick query tab. Paste
highway
under Key and leave Value empty.Paste
Kamppi, Helsinki, Finland
as the area of interest in the field below the Key / Value table.Open the Advanced drop-down menu and de-select Points and Multipolygons. This prevents us from downloading unnecessary layers.
Run the query.
A line layer titled highway_Kamppi, Helsinki, Finland has been added to the project.
If your project has QGIS’ default coordinate reference system in use (EPSG 84 | EPSG:4326), you will see a lot of distortion on the network. We’ll return to the topic of projections next week, but for now, change the the project CRS and reproject the data:
Open project CRS settings from the bottom right corner.
Search for
EPSG:3067
and set the project’s coordinate reference system to ETRS89/TM35FIN (EPSG:3067). This is a good default projection to use over Finland.NB! This setting only affects how the layers are drawn on the map screen – the underlying data retains its CRS.
Additionally, reproject the data itself to
EPSG:3067
using the processing tool Reproject layer.
Check out the attribute table! The data came with lots of unneccesary columns. Let’s trim the data we don’t need.
Open the processing tool Retain fields.
Select ‘highway’, ‘surface’, ‘name’ and ‘maxspeed’ on the layer reprojected.
Run the tool.
Finally, let’s enrich the road data with road length information:
Run field calculator on the output of the previous step (Retained fields) from the attribute table or processing toolbox.
Use the expression
length(@geometry)
. This adds the length of each feature in map units – meters, in this case.
Making maps#
Let’s make some maps now!
Styling#
Instead of using the standard style definition options (graduated for continous data and categorized for categorical data), let’s explore rule- and data-driven styling.
By using data-driven overrides, we can use expressions to modify layer style (color, width, transparency, symbology etc.) based on the values available or derived from the attribute data. Most layer features can be defined this way: look for a small symbol besides the definitions.
Apply a data-driven override to linewidth of the road network layer by clicking the symbol next to Width > Edit.
Paste this expression to the field that opens:
CASE WHEN
"highway" in ('footway', 'residential', 'tertiary')
THEN 0.3
WHEN "highway" in ('primary', 'secondary')
THEN 0.5
ELSE 0.15
END
The expression above is a conditional: all values in column highway that match the conditional get the corresponding outcome. For example, the outcome for primary roads is linewidth of 0.5 (in millimeters).
Conditionals and data-driven overrides are particularly useful when we apply the expressions to the data; no need to create new columns, we can do classification on the fly!
Let’s color the street network based on streetname endings: ‘katu’ = street, ‘kuja’ = alley, and a generic class for the rest. Since these are categories with no clear hierarchy, a quolitative color scheme fits our data the best.
Again, we’ll use expression, but this time rely on rule-based styling.
Select Rule-based as the styling type for the line layer.
Add two more line features. Copy the style of the first feature and paste it onto the other two (Copy symbol > Paste symbol).
Edit the first feature. Name it Streets. In filter, paste
right("name", 4)='katu'
. Use whatever color you wish: the example color is a bright red#d40a47
.The filter matches the last four characters from the streetname column with katu (street). If there’s a match, the rule is applied.
Paste the color hex code to: Color > Choose color… > HTML notation field.
Repeat for class #2.
Name: Alleys
Filter:
right("name", 4)='kuja'
Example color:
#e78119
And the final class
Name: Other roads
No filter: Select Else: Catch-all for other features
Example color:
#30bab0
Now, your style panel should look something like the picture below
Layout#
Next, it’s time to layout the map and export it. There are a thousand ways to create a good, eye-catching maps! Below is one attempt, but you are given free-hands to experiment.
If you need a refresher on QGIS’ Map composer, check out the official training manual.
The line layer in this example uses the style: QGIS-files/example_street_network_style.qml
This is far from a perfect map, but it has some basic cartographic elements and features that are good to keep in mind when making your map. However, it is highly encouraged to experiment with feature and background colors, map elements and their placement.
Replicating the processing flow of this notebook#
To get a street network file styled and ready for mapping, you may use this model file to replicate this process:
Download the style file and processing model in QGIS-files folder
In the top right corner of the Processing toolbox, select Open existing model and navigate to practical1_processing_steps.model3
Open the model and select example_street_network_style.qml as the Street network style file parameter. Run the model.
A new layer called Styled network has been added to the project.