Introduction To QGIS
Introduction To QGIS
This practical will visualise England domestic electricity consumption at MSOA level in
2021. The main data we use for this practical are: MSOA boundary (shapefile) and electricity
consumption data (csv).
The following are the main study objectives of this practical. You will learn:
1
1. The menu bar provides access to various QGIS features using a standard hierarchical
menu. For example, to access QGIS setting options click: Settings > Options > General >
Application
3. Panels allow browsing data and tools. The most commonly used include layers,
browser, and processing toolbox panels.
Browser panel works the same way as the folder tree in Windows Explorer [or Finder in
Mac] and is the easiest way to open data in QGIS. It lacks, however, the fine-tuning
options available via the menu (Layer > Add layer…) or Layer Manager toolbar (left to
the Browser panel)
Panels and toolbars can be added or removed by right-clicking in the toolbar area and
(de)selecting the toolbar/panel from the pop-up menu. They can also be undocked and moved
around by clicking and dragging.
Layers panel displays data loaded into QGIS, the order of display and allows to toggle their
visibility. Removing layers from the panel remove data from the map but NOT from your
computer.
4. Map view displays the data in the order specified in the layers panel.
5. Status bar shows the coordinates of the cursor in the map view, current scale and rotation
of
the map, the coordinate system of the current project, and allows to toggle rendering on and
off.
2
2. Set up a project
Before beginning the practical component of this tutorial, it is recommended to set up a QGIS
Project file. The Project file is used to store reference to all the included spatial data,
symbology, map projection, and map layouts. The steps are:
• Once QGIS is open, select Project > Save and in the new dialog box give you project
an appropriate name with the extension .qgs. Save the project on your preferred
directory.
• In the Menu Bar select Project > Properties. In the Project properties dialogue box
select Enable ‘on the fly’ CRS transformations, and then in the filter search box type
“27700”; this is the reference for the British National Grid map projection (the
standard map projection for UK data).
• Finally, press Okay to close the dialog box and save the project.
3. Import data
In the case of both vector, and raster data there are three methods for importing data: using
the Menu Bar, the Tool Bar, or using simple drag and drop.
For the file menu, select Layer > Add Vector Layer or for the Tool Bar press the button on
the top left. In both cases, the user will be presented with the Add vector Layer dialog box.
3
The data we imported is msoa boundary. The data is downloaded from Geoportal
[download].
(Note: The spatial data is in shapefile format. This format consists of a collection of files with
a common filename prefix, stored in the same directory. The three mandatory files
have filename extensions .shp, .shx, and .dbf. The actual shapefile relates specifically to
the .shp file, but alone is incomplete for distribution.)
Besides, we also need to load energy consumption data (csv) (data source). Similar to
importing vector data, to import csv data, from the main menu Add Layer> Add Delimited
Text layer, or using the button. To see the tabular data you created you will need to set the
file type dropdown in the bottom left to All Files (*).
4
After select import data, the data source manager | delimited text window pops up. The msoa
electricity domestic data has no geometry information, so select No Geometry > Add.
5
For now, we have imported two datasets we need. You can also find the imported data in the
layer panels.
Have a quick look of the data we imported. Right click the layer from the layer panel, and
select Open Attribute Table.
4. Spatial Joins
With both vector and csv data loaded, the next step is to join two data together. Since the
electricity consumption visualisation will show up on vector data, this step joins the
electricity consumption data (csv) to msoa (vector data). To do so, right click msoa layer and
select Properties. Joins shows on the left side panel of properties window, select Joins.
After navigating to the joins tab, click the plus icon to create a new join and then use the
parameters as specified in the figure below. Step 4 is optional, if you want to differentiate
which are the joined attributes and which are original attributes, you could click the box of
‘custom field name prefix’ and write down a name. e.g., de_
(Note: before doing the spatial joins, check attribute tables of two layers can tell the common
id of two layers. As these attributes are shared between the two datasets we can use them to
join them into one.)
6
To check if we have joined successfully, we can look at the attribute table of msoa layer, you
will see that all the electricity csv layer’s columns are now in msoa attribute table. The name
of each joined columns has a prefix “de_”.
The properties dialog presents a number of tabs which allow the user to control style,
labelling, attribute fields, and general layer settings. In order to edit the style of layer, select
the style tab. The attribute to display, median electricity consumption, is a continuous
attribute, for this reason, we choose Graduated. Value section requires you to clarify which
specific variable you would like to present, which is meandian_consumption (step 3 see
below).
There are several defaulted colour ramp and feel free to choose the one you prefer in the
colour ramp dropdown. Noting that, we normally select one single colour from light to dart if
we want to showcase one continuous attribute. Do not forget to select Classify. After clicking
Classify, you will see the symbols and their corresponding values and legend. With the above
steps complete press the Apply button at the base of the dialog and the Map View will be
updated.
For now, you should now have created your first map, congratulations!
7
6. Attribute queries
Next, we will move forward to explore more useful functions of QGIS. What if we want to
identify which MSOA have a median electricity consumption greater than 4500 kwh per
metre. To do so, we can use Select features. As shown in the steps below, we firstly select
Select features using expressions > Select features by expressions (Step 1). In the new
dialogue, we select Fields and Values and find the median variable (step 2). Followed by step
2, we write a formula ‘>4500’ to filter MSOA for greater than 4500, and then select Select
features.
8
MSOAs mean value greater than 4500 are highlighted in the map view. To save the selected
features, right click the MSOA layer and select Export > Save selected features as…. This
means we will only select highlighted features instead of all msoa. We name the selected
feature as ‘high_consumption’. The newly exported features will appear in a new layer.
9
As we just want to keep the border of selected features, so we need to change the symbology
of new layer. Select Properties > Symbology > Simple fill. For the fill style, select No
brush. Feel free to change stroke colour.
Question 1: How many MSOAs have a median electricity consumption of over 4500
kWh/meter?
Question 2: Look at the new layer and see which MSOA has the highest median electricity
usage in England, can you guess the reason behind it?
(image source)
10
7. Map publications in QGIS
For the remainder of the exercise, we are going to work on a publication map using the QGIS
Print composer. To open the Print Composer select Project > New print layout. You will
them be prompted to give your map design a name. Call it ‘MSOA_domestic_elec_2021’.
Our map is better to present in a portrait way. To change the direction of layout, right click on the
page in your layout to find "Page Properties", the item properties window then show up, you can
change the orientation to Portrait.
To add the map we produced, select Add item > Add Map from the main menu. Nothing will
happen. What you need to do is to draw a rectangular in the layout to define the map frame. The map
frame is drawn by clicking and dragging the box to the area of the page you want (in this case the
entire page).
To set the position of the map data within the frame you can use the button from the Edit > Move
content. The map can be moved by left clicking and dragging. To zoom in or out use the scroll wheel
on your mouse while holding the command keyboard (mac user). Often you need more exact control
of zoom, which can be modified using the ‘Scale’ property in the Item Properties tab. Smaller
numbers increase the map size, e.g. change to 3,000,000.
11
The next step in the production of the map is the addition of a title. It is pretty much the same
procedure as adding a map. Select Add Item > Add label. Draw a text box. The text can be edited
from the Item properties in the Options tab box. We can edit the font, colour and size.
12
Legend: Add Item > Add legend. What you may want to change are two things: 1) change the name
of MOSA, to do so, go back to the main QGIS interface, right click mosa vector layer, select
Properties > Source, and update the name in Layer name. Note, to ensure the changes update well
with print composer, we need to click refresh button every time we make some changes.
Finally, we can add the attribution text using the same method you used to create the title. Add text
that describes data source, copyright information, and mapmaker. E.g., “Electricity consumption data
from BEIS 2021. MSOA Boundary data from ONS. Map created by Yuerong Zhang”
To save your current map design as an image, go to Composer -> Export as image. Export options
(resolution, page width, height) can be edited in Image export option box.
13
14