This practical is an Introduction to QGIS. QGIS (previously known as
Quantum GIS) is a free and open-source desktop geographic information
system (GIS) application that provides data viewing, editing, and
analysis. Anyone can download it from the Internet and it works on a
wide range of operating systems including Windows, Ubuntu and Mac. QGIS
is consistent with the principles of Windows software, so if you are
familiar with programs such as Word or Excel you should find that
similar concepts apply.
Many of the principles of using QGIS are the same in other GIS software,
such as ArcGIS and MapInfo. You can apply the principles you learnt here
into any other GIS software, but the location and the names of some of
the features might be slightly different.
Outside of campus, students will be able to access QGIS via one of at
least three possible routes:
(a) Download QGIS to your machine (go to https://qgis.org/download/, then download and install
QGIS; ideally you’d choose the 3.38 version - as university computers
have this version installed, however the 3.36 version should also be
fine - the differences are really minor)
(b) Use Apps Anywhere - https://www.liverpool.ac.uk/csd/apps-anywhere/
(c) Connect remotely to a University PC - https://www.liverpool.ac.uk/it/pc-centres/remote/
Once you have your access to QGIS sorted, the next step involves downloading the required data files for this practical to your designated directory on the M:drive/Documents (the university shared drive). It is important to use the M:Drive because it allows you to access your data, saved work, etc. from any University Managed Windows machine, as well as from home and any place in the world, provided you have internet access.
As there are several files, they have been compressed into a single zip file, and you will need to first copy this and then extract the data files. Follow the instructions on screen to download the zip file from:
Let’s start off by adding data to the map display.
Start by clicking the Open Data Source Manager
button and then Vector button
Next, locate the “Browse” button adjacent to the
“Source>Vector Dataset(s)” window and navigate to your designated
working directory, most likely within the “Documents/GIS/Prac1”
folder.
Change the option in the drop down menu on the bottom right to ESRI
Shapefiles (.shp). Select the world_countries.shp file, click
Open,and then click the Add and
Close button.
Keep the coordinate system (CRS) as EPSG:4267 - NAD27 if the system asks you to change it (click on the Cancel button)
This will add a layer (a polygon shapefile) which shows the countries of the world
Note If you end up with a different CRS then go to Project>Properties>CRS and type 4267 in the search window, select NAD27 - EPSG:4267, then Apply> OK
When we added the world_countries shapefile, QGIS randomly assigned a colour. We can change this to something more sensible - green, for instance.
Right click on the world_countries layer in the
Layers Panel on the left hand side of the screen, and
click on Properties
This will open the Layer Properties window, where we can change many different options for how the layer is displayed, as well as other options about the layer.
Click on the Symbology option on the left hand
side.
To change the colour, click on the drop down menu next to the
Color option
You can then either select one of the preset colours, or select a colour from the colour picker. Use either option, and change the colour to something you like.
Click OK (and OK again if necessary) and this will close the Layer Properties window and update the colour on the map.
The options you have in this layer will depend on what type of spatial data you are dealing with. The countries layer is a polygon layer, so we can change the colour of the polygons. Point layers or line layers will have different options. Try experimenting with different colours, and other options in the Symbology section of the Layer Properties window. Click on Simple fill and play with various options e.g. Fill style,Stroke color, Stroke style etc.
You might have noticed that when QGIS started, many toolbars and panels were displayed. Let’s tidy it up by displaying only the buttons we need.
Right-click on the toolbar (grey area at the top) and you should
see something similar to the menu below:
You can click different panels and toolbars on/off by checking their checkbox. Spend some time turning the toolbars on/off to see what the different options do. Once you are finished, leave the following toolbars with their checkboxes checked : Layers Panel; Attributes Toolbar; Label Toolbar; Manage Layers Toolbar, Digitizing and Map Navigation Toolbar.
This is a basic set of tools to get you started; we will turn on others as we require them.
Once you have done this setup phase, QGIS should remember it, but if you use the software on a different computer you may need to follow these instructions again.
Using the same steps as previously (or select Layer > Add Layer > Add Vector Layer > Browse (…)) add two more shapefiles to the map. The files to add are: world_deg30.shp and world_rivers.shp shapefiles. To select multiple files, select the one at the top of the list, hold down Shift on the keyboard and click on the bottom file.
QGIS will add the layers, and again assign a random colour. However, you may not be able to see all the data. This is because the order of the different layers in the Layers Panel is important.
The colours of the different layers will also need to be changed, so update the colours to reflect what the layers represent. Remember also to save the project file!
We have already added polygon data and line data, and now we are going to look at adding some point data. Go to your M:drive/Documents folder and open up the world-cities.csv file included in the zip file - it should open in Excel. You can see the file contains four columns: Name, Latitude, Longitude and Country. As this data has some coordinates, QGIS can plot the data on our map. Close the file (without saving, if Excel asks), and return to QGIS.
You should now see the 15 cities added to the map. Update the symbols
to a colour that fits in with your existing map. See if you can work out
how to add a name to each of the cities. Look in the Layer
Properties window > Labels.
An important component of each GIS file/layer is the data associated with it. Tabular information is the basis of geographic features, allowing you to visualize, query, and analyse your data. In the simplest terms, tables are made up of rows and columns, and all rows have the same columns. Tables allow you to map and visualize your data. For example, you can’t generate text to label each feature, perform spatial queries or classify and categorize attributes to symbolize a layer.
In GIS packages, spatial data is typically accessed through the Attribute Table.
The basic spatial queries we are going to use in this practical are: select by attribute, select by location and export selected features. These are basic, but very important functions and are very often used in any GIS analysis. You will be required to select some features and extract them almost in all the practicals, so please pay extra attention to the exercise below.
Open Attribute Table of the world countries layer
Click on Select features using an expression
button
, type “NAME” = ‘Canada’ and click Select
features and then Close
In the Attribute Table, from the drop down menu on the bottom left hand corner choose Show Selected Features
Now your attribute table should only display one row with the data associated to Canada
Next, in the main QGIS tool bar go to Vector > Research Tools > Select by location and try to select only those rivers that flow through Canada
If you are not sure how to do it, use the picture below and then
click Run and Close
You can see that only those rivers that flow through Canada have been highlighted - 15 in total (you may need to turn off the world countries layer to see the selected rivers)
Next create a layer of the selected rivers by right clicking on
the world rivers layer > Export > Save Selected
Features As..
Choose ESRI Shapefile as your
Format, browse to your working directory and save it as
Canadian Rivers (use the Browse button to navigate to your
working directory)
The new layer should be automatically added to the Layers
Panel
Right click the Canadian Rivers layer > Zoom
to Layer and then label the rivers
Repeat this exercise for Brazil
(how many rivers
have you got selected this time?)
We only need the world_countries layer for this exercise, so turn all of the other layers off by clicking on the check box next to each layer entry in the Layers Panel.
Not every dataset you want to use comes as a Shapefile or in a spatial format (in fact, the majority do not!). Often data will be in the format of a report, spreadsheet or table that you need to link to your existing spatial data for use in some analysis. For example, you may be working with population data for a country where the data is in a table, csv, Excel file (.xls, .xlsx), or any other non-spatial format. To map this data, you have to merge this with a Shapefile containing country boundaries. This operation is known as a Join and this section will cover how to carry out table joins in QGIS. To demonstrate this we will join a table with population data to our world_countries layer.
In order to join tabular data it is necessary that both of your
datasets have a common attribute (e.g. a name, unique reference or
code). This attribute must be unique
(i.e. a country must
not be listed twice in your Attribute table) and identical (i.e. the
country names must be the same and spelt identically, e.g. Gambia and
The Gambia will not join successfully).
Open the Attribute table of the
world_countries layer and you’ll see that the NAME
field is unique (different) for each country.
Close the Attribute table.
In the data files that you copied today, there is also an Excel
file named Pop.xls. Double-click this file and it should open
in Excel. The dataset contains three fields, a unique identifier called
NAME, POP2011 and
POP2021. Close the Excel file once you have finished
viewing the data.
Now that we’ve identified the two fields in our datasets that we will
use to make the join, we can move on.
To add our table to the map, we need to use either the Add Vector Layer button or just simply drag and drop the table into the Layers Panel
The table will now appear in the Layers Panel
Right-click on the table and Open Attribute Table to check that the data appears correctly (if you have all null values there has been a problem with importing your data ( remove it from the Layers Panel and add it again). You should see both fields with data populated, row 0 containing Afghanistan with a population of 25,500,000 people. Close the attribute table once you are finished with viewing the data
Now we will join this table with your spatial data. Right-click on the world_countries layer, select Properties and click on the Joins option
Click on the plus button to create a new join. The Add Vector Join
dialogue box will now open
Make sure that Pop is selected in the Join layer dropdown box
NAME should be selected in the Join field dropdown box
NAME should also be selected in the
Target field dropdown box
Hit OK, and then OK again
Open Attribute Table of the world_countries layer and you will see that two new fields (named Pop Pop_2011 and Pop Pop_2021) have been added to the Attribute table! Please see the available video if you are unsure how to do it.
The join that we have made is not permanent; it is a temporary link between the two datasets. To make the Join permanent we need to save a new copy of the world_countries layer.
ESRI Shapefile
The Refactor fields tool is very useful and you can
do a number of operations in here, e.g. you can delete columns or change
precision of the decimal numbers; try to set the precision of the
Pop_2011 layer to 1 and see what happens
- Remove the redundant layers world_countries_updated and
Refactored and then Save your project
We will now add a new field to the attribute table and calculate some values (the change in population between 2004 and 2011) using a simple mathematical operation. This can be useful when you want to create new data or undertake some analyses.
Open Attribute Table of the world_countries_Pop
layer
Click on the Toggle editing mode button
Click on New field button
Set Name to POP_DIFF
Leave Comment blank
Set Type to Whole number (integer), change Length to 10.
Hit OK
In this instance we are dealing with whole numbers, so we can use the integer setting. If we were calculating something else (for example, % population change) which involves decimal numbers, we would need to select Decimal number (real), and set Length to 10 and Precision to 2 or 3.
You will see that the new field contains values, by default, as NULL. We now need to populate this new field (column) with some data.
Field calculator
window will open. It is here that we can
undertake all mathematical calculationsFirst, we need to update the POP2004 field and then we perform a simple calculation to populate the newly created field.
Check the checkbox next to Update existing field and select the field named POP2004 from the dropdown box
Under the Function List (middle window) group click on the expand plus sign next to Fields and Values
Double-click the field named POP2004 to add it to the
Expression window, then type * 1000 so the expression is as follows:
POP2004 * 1000
, and hit the OK
button
Then, still in the field calculator, check the box next to Update existing field and select the field named: POP_DIFF from the dropdown menu
Under the Function List (middle window) group click on the expand plus sign next to Fields and Values
Double-click the field named Pop_2011 to add it to the Expression (the full name of the field has been cut off)
Now click on the minus (-) sign and double-click on POP2004. Your expression should look like this: “Pop_2011” - “POP2004”(notice how the expression builder puts in the double quote marks for you)
Hit OK to run the calculation and the POP_DIFF field will populate with the calculated values (the first few values should be 75000 (Luxembourg), 632000 (Switzerland) and 5644000 (France), ask if this is not the case)
Finally, click on the Toggle editing mode button and choose Save when prompted. Close the attribute table
Save your project.
Now we have calculated the change in population between 2004 and 2011, we need to display it on the map.
Now we have a map of population change. However, how informative it is, are there any problems with it? There are a number of things you can do to alter the classification:
You may notice that some countries are missing from the map – for
instance, Burma and Taiwan. This is because their data is missing from
the files – you will see NULL written in place of the number, which
means the number is missing. You do need to be aware of how missing
values are represented, because each data set is likely to use a
different setting. Some population data uses a value of -99 to
represent a missing value, which will play havoc with the population
change calculation. Some will also use a value of 0, which is more
subtly misleading, and can often be missed, because a value of 0
population (meaning a missing value) is very different to a value of 0
(meaning a population count of 0).
Once you have finished, remember to save your QGIS Project. If you wish to open this up on another computer, it should be fine provided that you’re using the University M: Drive.
Please also remember that if you change the location of your files e.g move them to a different directory or change a folder, those layers won’t display in QGIS. In such case you’ll need to either move them back to the original destination or reset the source of your data using a plugin called: changeDataSource
We have the option of adding a base map to the data in QGIS. We can
do this through plugins called QuickMapServices
. To install
any plugin follow the steps below:
However, there is a new core functionality XYZ Tile provider which was implemented with some other nice enhancements for tiled services. This means, that there is no need for an external plugin although for an easy setup you can still use external plugins. Layers added this way: load faster, support reprojection, support printing and are cached in a powerful way. - In the Browser Panel, locate the Tile XYZ > right click New connection
Browser Panel
Some example URLs are below:
OpenStreetMap http://tile.openstreetmap.org/{z}/{x}/{y}.png
Google Hybrid https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}
Google Satellite https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}
Google Road https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}
Data capturing is of key importance in GIS, and these types of operations are often called digitizing. It is a process of converting geographic data either from a hard copy or a scanned image into vector data. During the process, features from the map or image are captured as coordinates in either point, line, or polygon format.
In this exercise, we will create a point shapefile by adding
London
to the world-cities layer and then a line
shapefile by adding River Thames
to the world
rivers layer.
First, make the world-cities layer permanent by right clicking on the layer > Export > Save Feature As (follow the steps from part 2.4.1)
Then, go to the world-countries layer and select the extent of the UK by using a simple spatial query in the Attribute table, as you did in part 2.3.2
Still in the Attribute table, click on Zoom map to the selected rows
Right click on the world-cities layer > Toggle editing
Turn on the basemap, and find London
Click on the Add Point Feature button from the
digitizing toolbar
Hover over the area where London is and then left click to add a new point
A dialogue box with Attribute table of the new feature will open up
In the Name field type London
,
click OK
Right click the world-cities layer > Open Attribute Table, find London and fill in the remaining fields, close the table
Right click the world-cities layer again > Toggle Editing, save all the changes that you have made
You have just created a new spatial entity by adding the new
point shapefile (London in this case).
Now, try to repeat the abobe steps for the world-rivers
layer and digitize the Thames River
It may be a bit more tricky to digitize line features, so if there are any difficulties, follow the steps below including some tips:
Make sure that the world-rivers layer is in editing mode (Toggle Editing)
Click on the Add Line Feature button and start
digitising a new line feature by adding new nodes following the River
Thames (no need to add the full length of the Thames River; beginning
around Reading area should be sufficient)
To finish digitizing a line, right click and enter the required information about the newly created entity
You can of course re-visit the new entity and for instance alter its shape, extent or include more detail
To add a new/move an existing node (vertex) go to the
Vertex Tool , select an area (on the line) where you want to place
a new vertex and hold Shift + double click on it
To delete an existing vertex, click on the Vertex, highlight the vertex and press Delete
To move a vertex: click on a vertex to enable vertex editing for that feature. Left click on vertex you want to move, drag it to new location, left click again.
If you are happy with the new entity, right click the world-rivers layer again, click on Toggle Editing and save all the changes that you have made
Save the project
So far, the new spatial entities that we have digitized used schemas
(data structure) of the existing layers, rather than creating new ones.
Both types of operations are really common in GIS, so in this last
exercise we will create a new polygon layer called UK
Islands.
If you turn the background map and world-countries layer on and then
Pan the map to the South Coast where Southampton and
Portsmouth is, you will notice that the largest English island (home to
a popular music festival) is missing. So your task is to create a new
polygon layer and digitize the Isle of Wight
.
Make the world-countries layer semi-transparent: right click on the layer > Properties>Style tab and set the Opacityy to 50%
Tidy up a bit the existing UK boundary around Hampshire coastline
by Toggle Editing the world countries layer
and moving the existing vertices as required (use the Vertex
Tool)
Then go to Layer > Create Layer > New Shapefile Layer
Hit the Browse … button next to File Name find your working directory and and type UK Islands
In the window that pops up make sure that you select Polygon as the new layer Type
Choose the coordinate system (EPSG:4267 - NAD27)
Create an additional Text data field, call it
Isle
, click on Add to fields list
Click Ok
The new layer has been added to the Layers Panel. From now on, you can follow the instructions on digitising a line feature - the same principle applies
Right click on the UK Islands layer > Toggle Editing
Click on Add Feature from the main menu and start digitising the polygon by following the Isle of Wight coastline
To finish your digitising, right click and populate the window that appears, click OK
Right click on the UK Islands layer >Save Layer Edits> Toggle Editing
Save the project
Now, try to digitize the Isle of Man, which is situated to the north west of Liverpool, by following the above steps. Once you finish with it, you are done with this practical. Well done!
Please note: This practical introduces you to only basic digitizing/editing; this is sufficient for our exercise, and as you have probably noticed it is more accurate that the provided layer of the world-countries, however often a much higher degree of accuracy and precision is required. Especially when we digitize adjacent polygons, the nodes (vertices) need to be snapped to each other in order to avoid polygons overlapping. At times, it may not be possible to do it manually and therefore there are tools which can do the job for us. It is called tracing/auto tracing tool as it allows you to trace existing features. For instance, such tool is enabled by default in ArcGIS but in QGIS you need to install an additional plugin called: Auto Trace. Using the Trace tool is beyond the scope of this practical but if you are interested, use this hyperlink to get more info.