Basi Craster Operations Tutorial
Basi Craster Operations Tutorial
net/publication/341343109
CITATIONS READS
0 2,393
1 author:
Samuel Ngugi
University of Nairobi
4 PUBLICATIONS 0 CITATIONS
SEE PROFILE
All content following this page was uploaded by Samuel Ngugi on 13 May 2020.
1
BASIC RASTER AND VECTOR OPERATIONS TUTORIAL
On the first instance, you will find a webpage that looks like this:
In the part labelled “Address/Place” type in “Nakuru”. The Earth Explorer website will bring up a table
below the address/place box with an underlined link written “Nakuru, Kenya” with the coordinates of the
place next to it. Click on this link. A new table showing the latitude and longitude coordinates of the place
in decimals, minutes and seconds (D:M:S) format will show up. In my case the coordinates read:
If you notice, a blue pin appears on your map to the right of the Search criteria which contains the details
of our place. Next, we put in the time period from which we want to acquire our data. Below the table
that shows the coordinates of our place is a box with the Date range and Result option tabs. In the date
range, put in ”01/01/2001” in the Search from box and “01/28/2020” as our last date. Leave the option
all for the months to search for. Click on Data sets. This takes us to the Data sets table. Scroll down the
table to the Digital Elevation link and in the drop-down, right-click “GMTED2010”. The Additional criteria
table is not relevant to download our file, so we skip it, but if the Entity ID of the file is already known
beforehand, it would put it in one of the boxes below it. Click on the Results button at the bottom.
2
Figure 2: Search Criteria in Earth Explorer
3
Figure 3:Address box in the Search Criteria of Earth Explorer
The Search Result for the GMTED 2010 data set of the area brings up an image with the Entity ID:
GMTED2010S10E030
Hover the mouse over the icons till you come across the one showing Show browse overlay. Click on it.
The image below appears over the East African map.
4
Figure 4: DEM of East Africa
The dark image to the right of the data set result table is a Digital Elevation Model (DEM). This is the image
to be downloaded. To see information of this file, hover the mouse over the icons till you come across
Show metadata and browse and click it. A table appears showing some attributes of this data. The
attributes of this file are called metadata. Close the table, hover to Download options and click on this
icon. Select download “7.5 ARC SEC (382.2 MB)”. Save this file to a folder called “Nakuru_manual”. The
7.5 arc seconds data is the most accurate DEM of the GMTED 2010 data sets with a resolution of 26 and
30 meters. The other data sets of 30 ARC and 15 ARC seconds have resolutions of 25 and 42 meters and
29 and 32 meters respectively. For this tutorial, the 7.5 Arc seconds data will be used.
5
Figure 5: Qgis Window
1. Menu – contains the bars that host the various tools that are used in Qgis. This part is like a row
of the ‘parents’ to most toolbars. For example, the bar for “Vector” will have a drop down to most
vector processing tools for Qgis
2. Toolbars – these are the tools used to carry out various actions on the layers loaded into Qgis
3. Panels – the layers loaded into Qgis are displayed by name in this box
4. Map view – displays the output of Qgis’ loaded layers and the results from processing tasks
5. Status bar – provides general information of the map view such as: coordinates, scale,
magnification scale, rotation and the coordinate system.
Going to the menu and selecting Layer>Add Layers> Add Raster Layer is a lengthy process to add the
DEM. To make sourcing for files easier, the Manage Layers toolbar icon is added to the panel on the
left. Go to the Qgis Menu, select View>Toolbars and right-click Manage layers toolbar. A list of icons
should appear on the extreme left of your Qgis view.
We want to add the DEM we downloaded. How do we go about it? Go to the Nakuru-manual folder
where we saved it and hover your mouse over one of the files. What item type is it? It should read
“Item type: TIFF” and other information such as rating, dimensions and size. We are only interested
in the item type. The item type is what will guide us on how to open the file in Qgis.
Bring up the Qgis window. For this work, the file – “10s030e_20101117_gmted_max075” will be used.
6
Go to the Manage layer toolbar and click Add raster layer.
A Guided User Interface (GUI), the Data Source Manager, will come up. The raster option will be
highlighted and to the right will be the Raster datasets source browser. Leave the source type as File, click
the ellipsis icon on “Raster dataset(s)” and browse to the Nakuru-manual folder where the DEM file was
saved. Select the file - “10s030e_20101117_gmted_max075”. Your screen should look like below:
7
Figure 7: Qgis Data Source Manager
Click Add and then Close to exit the datasource GUI. The DEM appears on the Qgis canvas and layers
panel.
There are many operations that can be done on a layer in the layers panel, this tutorial alone cannot cover
even half of them. It is recommended you go through the “QGIS User Guide” available at their website.
Right click the DEM layer and select Properties. Scroll up to the Information tab which gives the metadata
for this DEM. The metadata provides useful information concerning the DEM but these below are of
interest:
8
GDAL Driver
The type of file.
Description
Look at the statistics to the right of “Compression Band 1”. Some of the statistics are mean, median, max
and minimum among others. For this DEM, the highest height above sea level is indicated next to the
“STATISTICS MAX” and the lowest height next to the “STATISTICS MINIMUM”. The values are 4268 and -
6 respectively.
Mount Kilimanjaro, which is 5886m above sea level is the highest mountain in both East Africa and Africa,
yet in this file, where the mountain is also included, the maximum height is at 4268m. There is obviously
some error with this data. Despite this, the raster processes that will follow will rely on this file.
Click on Cancel.
Hover the mouse on the Qgis toolbars on the top left and click Save. Browse to the Nakuru_manual folder
and save this Qgis session as “Raster open” in a newly created folder called “qgis”.
On the Qgis menu, click Project> Exit Qgis to quit this session. Click Save on the pop-up window that
appears asking if you would like to save the current project.
9
Clipping a Raster
On the Start menu of your computer, go to All apps>Qgis 3.8 and in the drop down choose “Qgis 3.8 with
Grass 7.6.1”. Qgis 3.8 is the version used in the entire tutorial. Once Qgis is open, to your right is a list of
previously opened Qgis projects (if you have). Click on the “Raster_open” project and Qgis restores the
project just as you had last saved it.
We want to clip the DEM raster to the country borders of Kenya, and further clip this to Nakuru county.
For this, a shapefile of Kenya’s administrative boundaries is needed. The file is available from here.
Download it and save it to your working folder. To add the administrative shapefile, click on Add vector
layer to the left of your Layers panel.
The datasource manager with the vector field highlighted pops up. The GUI used and process of adding a
vector is the same as that of adding a raster file. Leave Source Type as file, and below this in the Source
dialog box, click the ellipsis icon and browse to the “Kenya_admin_WGS84” shapefile in your working
folder. A list of five files appears. Click the All files drop-down at your bottom right, scroll and select “Esri
Shapefiles (*.shp .Shp). Now only the files that mathc this format appear on the search window. In this
10
case it is “Kenya_admin_2014_WGS84.shp”. Select this file, click Open and then Add. Close the data
source manager once the shapefile is loaded into Qgis.
The Kenya administrative shapefile appears on the Qgis canvas. Qgis chooses any single random colour
for its appearance. The loaded files have long names. Let’s shorten them. Right-click the DEM file and
select Rename layer in the options. Rename the DEM to “DEM_EA”. Rename the loaded administrative
shapefile to “Kenya”.
We want to clip DEM_EA to the Kenyan boundaries as this will do away with the unnecessary data of the
other East African countries. On the Qgis menu, go to Raster>Extraction>Clip Raster by Mask Layer. A
dialog box appears. Ensure the “DEM_EA” appears in the Input Layer and “Kenya” appears in the Mask
Layer. Ensure the boxes of Match the extent of the clipped raster to the extent of the clipped layer and
Open output file after running algorithm are ticked. In the Clipped (Mask) dialog box, click the ellipsis
icon to save the output in a newly created folder called “outputs” within the Nakuru_manual folder and
name it “DEM_EA_clipped”, and using the Save as type dropdown, save it in the “.tif” format.
11
Figure 10: Clipping a Raster by Mask
Click Run and then Close to exit the dialog window. A new .tif file is added to the layers panel. Uncheck
“DEM_EA” file and rename the newly created “Clipped (Mask)” to “Kenya_DEM”. Right-click, this file and
select Zoom to layer. Your Qgis window should look as below.
12
You may ask, how varied is the altitude of Kenya’s land surface? To find out, the height differences have
to be categorized with various colours. Right click on the clipped file, select Properties and select the
Symbology tab. Next to Render type, in the drop down, change from “Singleband gray” to “Singleband
pseudocolor”. Under Min/Max value settings, to the right of Interpolation, change from “Linear” to
“Discrete”. In the dropdown next to Mode, change from “Continous” to “Equal interval”. Increase the
classes to “8”. Click the dropdown next to “Color ramp”, go to “All color ramps” and select “RdYlGn” in
the list of colours. Leave all other settings in their defaults. Click Apply and then Ok. What do you see?
The Kenya DEM has been divided into height differences of approximately 536m, with each height range
represented with a different hue or colour.
13
Figure 13: Colour Categorization of Kenya's Elevation
Uncheck “Kenya_DEM”. The next step involves extracting Nakuru county from the administrative
shapefile. Right-click “Kenya” and select Filter. This opens a Query builder window. This is a window for
carrying out simple mathematical queries on Qgis data. Under Fields select, “COUNTY” and then under
the Values box select All. All the 47 counties of Kenya appear in the Values box. Go back to the Fields box
and double-click “COUNTY” attribute. It appears in the Filter Expression box. From the Operators choose
the equals sign (=). In the Values box, double click “Nakuru” which should appear in the expressions box.
The mathematical expression in the expressions box should read:
"COUNTY" = 'Nakuru'
Click the Test button at the bottom of this dialog window. The Query Result tells us the expression has
returned one row. This means that there is only one county in this administrative shapefile that fulfils the
query ‘Nakuru’. If there were more, the Query Result would return the number of rows of those that
counties share the same name in this file. Click Ok in the Query Result window and then Ok in the Query
Builder window. Right-click Kenya> Export>Save features as. In the File Name box, browse to the
“Outputs” folder and save the output as “Nakuru”. The Save as type should be ESRI shapefile. Next to
“CRS”1, besides the dropdown box, select the world icon next to it. In the CRS dialog window that pops
up, type “32737” in the filter box, or type “WGS 84” and scroll down in the CRSs of the world until you
find WGS 84/UTM Zone 37S. Select this CRS and then OK. We are shifting from the former, which is a
geographic coordinate system, to the latter, EPSG 32737, which is a projected coordinate system.
Geographic coordinate systems are normally used for world scale measurements, and are normally
measured in degrees, which will bring problems to area measurements. We prefer to use the latter, a
projected coordinate system, which is normally used for local areas and measurements are in metres or
feet.
1
CRS – Coordinate Reference System
14
Figure 14: Coordinate Reference System Selector
Ensure the box of Add saved file to map is ticked. Click Ok in the Save Vector Layer As dialog window.
The Nakuru file should appear on the Qgis window. Zoom to this newly created layer. Click Save on Qgis.
As a precaution, keep saving your work as the project progresses to avoid losing your work in case Qgis
crashes. Quit Qgis.
15
Clip Kenya DEM to Nakuru County
Activate the “Kenya_DEM” layer by clicking on it. Select the “Nakuru” shapefile and drag it above the
“Kenya_DEM” in the layer manager. The “Nakuru” shapefile should now be superimposed over the DEM
layer. Zoom to the extent of the “Kenya_DEM” layer. Take note of the altitude range at which Nakuru
county lies. The next procedure involves clipping the DEM to the confines of Nakuru county. The clipped
DEM will be assigned a projected coordinate system as explained on page 14. If we were to clip the Kenya
DEM in EPSG: 4326 using a mask of EPSG: 32737 as in this case, the output would be a file with the default
EPSG: 4326, which is a CRS not recommended for local scale calculations. So how do you go about it?
Go to Raster>Extraction>Clip raster by Mask Layer. In the dialog window that appears, put in the details
as below:
Notice that this time round the Source CRS and the Target CRS are being specified. The Source CRS refers
to the projection of the Input Layer which eventually dictates the CRS of the output. The Target CRS, on
the other hand is the projection the output file will be adjusted to. In other words, the Target CRS is the
projection we would like our output file to be in. Ensure that Match the extent of the clipped raster to
the extent of the mask layer and Open output file after running algorithm are ticked. Save the output in
your working folder as “Nakuru_DEM” in .tif format using the Save as type dropdown. Rename the newly
created file as “Nakuru_DEM” in the Qgis layers panel. Zoom to the extents of “Nakuru_DEM”. Uncheck
all the other layers.
16
To find out the height variations of Nakuru county, a categorized colour scheme will be used. To duplicate
“Nakuru_DEM”, right-click the layer and select Duplicate Layer. A duplicate is created if one would like
to perform an analysis without altering the original “Nakuru_DEM”. “Nakuru_DEM_copy” appears below
our active DEM. Activate “Nakuru_DEM_copy” and deactivate our earlier layer. Take note of the minimum
and maximum values of the two DEMs. Right-click Kenya_DEM> Styles>Copy styles and then select
“Nakuru_DEM_copy”, right-click it and select Styles>Paste styles. Let’s go on. Activate the “Nakuru_DEM”
and deactivate the duplicate DEM. Right-click the “Nakuru_DEM” and in the symbology tab (by now you
should know where it is) go to “Singleband pseudocolor” and next to Interpolation select “Discrete”, for
Color Ramp chose RdYlGn, set Mode as “Equal Interval”, set 5 for “Classes” and finally click Classify.
Notice that in the duplicate DEM, when we pasted our symbology styles from Kenya_DEM to it, all the
colour stylings and classes initially meant for country wide analysis were copied to this duplicate DEM. But
for the “Nakuru_DEM”, you have specified the classes to make the height variations more applicable for
a county analysis.
Before closing this session, this section introduces a different way of clipping “Kenya_DEM” to individual
regions. In this case, there are 47 counties in the administrative shapefile. Clipping your DEM to each of
these counties would be a tedious task! Luckily, there exists a shapefile of the former provinces which
were scrapped after the promulgation of Kenya’s 2010 constitution. Download this shapefile from here.
Create a new Qgis file by going to the extreme left of your toolbars and select the white icon next to the
edge. Alternatively, you can go the long route of Projects>New.
In the new Qgis project, load the “Kenya_DEM”. It is initially saved as “DEM_EA_clipped” in the output
folder. Save the new project as “DEM_clip_batch” in a new folder called “Qgis-projects” within the
Nakuru_manual folder. Using Add Vector Layer, browse to the Provinces folder and with the type “Esri
shapefiles” selected, highlight all the .shp files. You can alternatively click the first file and while pressing
the “shift” button, click the last file to select all .shp files. Click Open and then close the dialog window.
All the eight provinces should appear in your Qgis canvas. Drag the “Dissolve” shapefile to appear above
the DEM.
17
Select Raster>Extraction>Clip Raster by Mask Layer. In this dialog window, select Run as Batch Process at
the bottom. Using the plus (+) sign, add eight more rows in the empty box. Under the Input Layer header
row, all rows under the “Autofill” field should read “DEM_EA_clipped” and under the “Mask Layer”
header, each cell should read the name of a province to be used as the mask. Under the Match extent of
clipped raster to the extent of the mask layer all the dropdowns should read “Yes”. Leave other fields in
their defaults. In the cells under “Clipped (Mask)” save the output .tif file in a new folder called
Province_DEMs with the name of the province acting as the mask. For example, “…/directory/Central.tif”.
An “Autofill setting” dialog will keep popping up as you save, leave it at “Do not autofill” and click Ok in
all instances.
Click Save and then close. The file details used in the batch process will be saved as .json file which can be
retrieved at a different time and the same process rerun to produce the same result. Give your .json file
a name in the “Provinces_DEM” folder. Finally close this dialog window. Look at your map view. There is
a separate DEM for every province loaded onto the Qgis canvas. You can play around with the Qgis tools
you’ve learnt so far to know the height variations and metadata for each province’s DEM. Save this Qgis
session and create a new project.
To assess how good the .json file works, go to Clip Raster by Mask Layer, open the .json file we had saved
earlier. The file directories and the settings initially saved for each file are loaded into the box. Add digit 2
18
at the end of each provinces’ name just before the .tif extension. Ensure “Load layers…” is ticked and then
run to view the results. The DEMs are identical to the previous ones.
Is there an easier way to clip a raster to separate files? Yes, there is. Open Clip Raster by Mask Layer again,
and using Kenya DEM as the input layer and the “Dissolve” shapefile as a mask, click the iteration arrow
circled in red below. Save the outputs to a folder called iteration within your working folder and then run
the algorithm. The DEM for each province will be generated separately.
19
Figure 19: DEMs of Kenya's Provinces
Optional Exercise
This is a short exercise on a simple vector operation. The objective is to show how the administrative
provinces are extracted from the counties’ shapefile.
Load the Kenya admin. shapefile into Qgis. Right-click and go to Open Attribute Table. Analyse the fields
by looking at the columns. Look at the “Province” tab, click this field and the names are ordered in
ascending alphabetical order. Notice that the eight names of provinces repeat themselves in the list. Close
the attribute table. Go to Vector>Geoprocessing tools>Dissolve. The input layer is the counties shapefile.
Under Dissolve Fields click the ellipsis icon and select “Province”. Save the output as .shp in your working
folder. Run the program. Your result in the Qgis canvas will be a shapefile where all the counties have
been merged according to the names of their former provinces.
Adding Vectors
Some vectors will be added to view some of the infrastructure and physical features existing in Nakuru
county. The additional files representing these features will be loaded into Qgis. Right click Nakuru_DEM>
Properties>Symbology. Below the colours box there is an icon labelled Export color map to file. Click on
it and save the DEM’s symbology stylings as “nakuru_dem_style” in the Outputs folder of your working
folder. The same symbology settings can be opened and applied to any DEM loaded into a Qgis project.
20
Figure 20: Saving Symbology Settings
Open a new Qgis project by clicking the icon located at the top left of your toolbars under the
Project menu. Notice your current CRS is EPSG: 4326. Load your “Nakuru_DEM” into the new Qgis project.
Notice the CRS changes to EPSG: 32737, which is the projected coordinate system you chose to work with
for this county. In the Symbology tab, change from “Singleband gray” to “Singleband pseudocolor” and
below the colour box select Load color map from file. Select the symbology file you had saved earlier and
apply it to the Nakuru DEM. The DEM acquires the same stylings. Save your current Qgis project as
“Nakuru_analysis” in your directory: …>Nakuru_manual>Qgis. Now load the following shapefiles,
“major_roads”, “major_rivers”, and “waterbodies” to Qgis. These files are available from here. These files
will be further clipped onto the DEM raster to view the infrastructure and physical features falling within
Nakuru county. Clipping vector to vector is easy, but how about clipping a vector to raster? Unfortunately,
there is no tool in Qgis that clips a vector to raster boundaries, unless the raster is converted to a polygon
shapefile. To vectorize a raster, go to Raster>Conversion>Polygonize(Raster to Vector). Save the output as
“vectorized” as shown in the dialog window below:
21
Figure 21: Vectorizing a Raster
A polygon vector containing the digital numbers for each value in the raster is loaded to the Qgis canvas.
This polygon boundary will be used to clip the three shapefiles to match the outlines of the DEM. Go to
Vector>Geoprocessing tools>Clip and Run as batch process. Under Input Layer select all three shapefiles
in the multiple selection dialog. The Overlay layer should read “vectorized” in all cases. Rename the
clipped outputs by adding the suffix “clip” to their names. Run the algorithm. The process may take some
time depending on your computer. Save the outputs; “rivers_clip”, “roads_clip” and “waterbodies_clip”
using the local CRS EPSG: 32737 as “nakuru_rivers”, “nakuru_roads”, and “nakuru_waterbodies”
respectively. Remove all the other shapefiles to remain with these newly created ones. Customize the
shapefiles to your desired stylings.
Slope Analysis
This section will guide how to view the topography of Nakuru and to some extent, the infrastructure on
the surface of its DEM. To do this, the relevant layers will have to be loaded to a Grass mapset within Qgis.
For windows users, creation of a Grass mapset in versions 3.x and above causes Qgis to crash. Therefore,
you will create a new mapset and map location for this work using the GRASS GUI. Go to the Start menu,
open the Qgis folder and select Grass 7.6.1. Create a new folder to serve as the GIS Grass database
directory. This directory will be used store all of your GRASS related work. In the Grass Location box, click
New to create a new map location for your work. Save the Project Location name and Location Title as
“Nakuru_manual” within your directory. For the method of creating a new map location, choose the
option of selecting an EPSG as spatial reference and in the next window, search for “32737”. Leave as
Option 1 in the pop-up dialog that comes up and then Finish. Quit the Grass interface.
22
Figure 22: The Grass GUI
23
Figure 23: Creating a Map Location in Grass
The reason for creating a new map location and mapset in Grass is to avoid a system crash when done in
Qgis. Now open Qgis and restore the previous project.
Open the Plugins menu, go to Grass>Open mapset. A combo box appears. Browse to the map location
and mapset you have just created.
Click Open Grass Tools icon to open the Grass tools menu. If you can’t see it, go to the View menu, to
Toolbars and select Grass. The icon should now appear. For Grass tools to work with Qgis layers, they
have to be imported into the Grass database. To demonstrate this requirement, you will try to change the
slope DEM colours without importing first importing it to Grass. In the Grass modules, go to
Raster>Manage map colours>r.colors.table. No layers in the current Qgis project are available in the input
dropdown. Click the Close button below to exit this dialog window. Go back to Grass modules, to File
24
Management>Import to Grass>Import raster into Grass from Qgis view and click r.in.gdal.qgis. Configure
the combo box to the details shown below and run the process. To view the result, click Output. This
loads the Grass layer into Qgis.
You will notice the Grass output is identical to that of Qgis from the slope analysis operation. The reason
the slope layer was imported to Grass was to assign the slope gradients meaningful colours. Within the
Grass modules, go to Raster>Manage map colours>r.colors.table. Select Color palette for Shuttle
Topography Radar mission or any other colours from the list you prefer. If for some reason the colours in
your Grass’ slope layer do not change, consider right clicking the layer, right under singleband
pseudocolor, create a new color ramp and select the type as Catalog: cpt-city. Go to the topography
theme and select “wiki-knutux.” Change the symbology settings to match those shown below:
25
Figure 26: Grass Symbology Loaded to Qgis
Overlay the shapefiles to be on top of “Slope_grass” layer and uncheck the other raster layers. Analyse
the map, do you see any connection between the location of the waterbodies and the degree of slopes
adjacent to them?
Now that you have learnt how to import a Qgis raster layer into Grass database, carry out the same
procedure for “Nakuru_DEM” on your own. Name your Grass file as “Nakuru_grass”. To assess if the Grass
tools will return the same results for the slope analysis, go to Grass modules, Raster>Spatial
Analysis>Terrain Analysis>r.slope. Select “Nakuru_grass” as your elevation map and name the output as
“grass_slope”. Use the region of the elevation map and select slope steepness to be in degrees. If the
result appears in the layers panel but does not appear in the Qgis canvas, save it as “Nakuru_slopes” in
your output folder. Copy the stylings of “slope_grass” layer by right-clicking it, Styles>Copy Style and paste
them to the new Slopes layer by selecting Styles>Paste Style. “Nakuru_slopes” and “slopes_grass” should
now be identical. Save and quit this Qgis session.
26
saved earlier. Add the three shapefiles of “rivers”, “roads”, and “waterbodies” all at once and overlay
them on the slopes layer. Open the attribute table of the “waterbodies” shapefile by right-clicking it.
On the attribute table, click the edit icon at the top left and also click New field, the sixth icon from the
right. The new field will contain the names of these lakes.
A dialog window will pop up. Put in the details as in the box below and press Ok:
27
Now there are about nine lakes in the “waterbodies” shapefile. How do you know which one to label?
Minimize the attribute table and beginning with the large lake at the bottom, use the Select tool and click
on this lake. Maximize your attribute table. The row of the selected feature is highlighted in blue. Click on
the empty cell under the Name field and type “L. Naivasha.” Save your edits. Do the same for the other
remaining lakes. Use the map below that has the names for each lake.
Once you are done, toggle edits to exit edit mode. Click the Deselect all icon to deselect the selected
features. Close the attribute table. With the “waterbodies” layers selected, click on the Layer labelling
options icon. In the layer styling menu that appears, set your Label combo box settings to match these:
28
Figure 30:The Layer Labelling Menu
Close the menu and go to Project>New Print Layout. Name your print layout title as “Nakuru Lakes” and
then Ok. A new Qgis window with an empty canvas, menu and tools appears. Use the Add new map
and draw a rectangle that fills the entire layout page.
29
Figure 31: The Print Composer Canvas
Under Main Properties next to the Scale box, type in 847649. This should zoom into the map and make it
fit to the page margins. Right under Main Properties, tick to enable frame. Leave the color, thickness and
join style in their defaults. Scroll to Grids, add a grid. Draw Grid 1 should be ticked, then click Modify grid.
This will take you to Map Grid Properties. Under the Appearance drop down, put in the following
properties.
Under Frame properties, change the settings to match those shown below:
30
Figure 33:Frame Settings
Under the Draw coordinates properties, change the dropdowns to match those in the image below:
31
The background of this map looks plain. To ameliorate the layout, you will add the Kenya administrative
counties shapefile as a base layer. Go back to the main Qgis window, add the counties shapefile and drag
it to below your slopes layer. Go to Styles>Edit symbol and in the Symbol Selector dialog window, select
“Simple fill” diagram in the white box. Select the fill style to “No brush” and then Ok. Using the layer
labelling procedure you learnt earlier, label the administrative file using the “COUNTY” names attribute
with red as the font colour. Go back to print composer and click to refresh your map to view the new
changes applied. Use to add a scale to the lower left corner of the map and stretch it to an
appropriate size. With the scale bar selected on the print composer, look at Item Properties. You will
notice the properties have changed to suit the settings of the scale bar. Set Style to be “Single box” and
for the rest of the properties, tweak them to be as in this picture:
Leave the rest at their defaults. If you made a mistake and it’s hard to undo some changes in the print
composer, simply select the added item and click the delete button on your computer. This will remove
the item.
Search for the Add arrow icon from the tools on your left and add it to the top right of your map. Click the
arrow for Search Directories and wait for the images to load. Select the North arrow of your liking and
change the original fonts. Search for the Add new label icon and stretch it to an appropriate size at the
top of your map. In the box of Label properties, type “NAKURU COUNTY: Slopes and Relief”. Customize
the Font to be “Ms Shell Dig2”, size “18”, style “bold”. The font colour is black by default. This is a good
place to save your work. One can save the Qgis project from the “Print Composer” by simply clicking the
Save icon or Layout>Save Project.
32
One more thing, from which part of Kenya are these features located? It would be good to show the larger
Kenya as an overview map. Click on the map frame and under the Layers dropdown, tick Lock Layers and
Lock Styles for Layers to lock all the layers within the map frame. Use to do the same for the Scale,
North arrow and Title. Locking the items within the frame prevents them from moving when carrying out
zooming operations in the main Qgis canvas. Go back to the main Qgis canvas in this project. Zoom to the
layer extents of the Kenya counties’ layer. Set the fill style of this layer to “No brush”. Go back to Print
composer and using the procedures learnt, add the map of Kenya to the top left of the main map.
With the new map selected, go to the Properties tab and put in an appropriate zoom level by progressively
decreasing the first left digits of the scale number. Scroll down to Overviews and add a new overview.
Select Map 1 to be the map frame. Leave the rest of the settings at their default. A pink box appears on
the Kenya map where Nakuru is located. Add a frame to this overview map and lock it as was similarly
done for the main map frame. Go back to the main Qgis canvas, activate all layers and zoom to
“Nakuru_slopes”. Maximize the print composer window, unlock all items and refresh the map frame of
“Nakuru_slopes”. Ensure that the slopes layer and the shapefiles are visible.
33
All seems okay for this map. Click on to export it as pdf. Save it as “Nakuru_relief”. In the pop-up
dialog that appears, ensure only Export RDF metadata and Export text as paths are ticked.
During your free time explore other tasks that the print composer can do.
Figure 37: The Final Map Output with the Overview Map Highlighted
Create Atlas
So far in this project you have created a single page output of your features. How about a single print
output of more than a single page and each page had a different feature? This is the function of the Atlas
tab in the Qgis print layout. In a new project load the administrative constituencies’ shapefile available
from here. Also load the slopes DEM and the “vectorized” shapefile. Name your new project,
“Nakuru_atlas”. Remember the “vectorized” shapefile took some computation time when infrastructure
was clipped to within its boundaries. Dissolving all field in it reduces the computation process. Go to
Dissolve tools and name your output as “vectorized_dissolve”. Run the tool and you will get a result where
all the fields have been dissolved to a single vector layer. The EPSG of the parent file has also been
retained. Remove “vectorized”. The constituencies shapefile will also have to be clipped to only remain
with those of Nakuru county. Go ahead and do so. Then save this clipped file with the name
“Nakuru_const” with CRS 32737. Remove the “clipped”, “dissolved” and country shapefiles. Overlay the
34
Nakuru constituencies layer over the slope layer, make it transparent but let the boundaries remain visible
with a stroke width of 0.3. Add the Nakuru “roads”, “rivers” and “waterbodies” shapefiles. It would be
helpful to know the area of each constituency. You will append a new field of the area for each
constituency in square kilometres to theconstituencies’ layer. Click the field calculator icon on the
attribute table to open a new dialog window. Check Create New Field and Output Field Name as
“Area(Km2)”. In the box of rownumbers, search for “$area” which should be under the Geometry
dropdown. You can also type “area” in the search field and choose the appropriate function. Take note of
its description to the right and how the “$area” function differs from the “area” function. “$area” will
compute the area of each constituency based on the CRS settings which means that the area for each
constituency will be in sq. metres. The value of sq. metres will be lengthy, so divide “$area” with 1000000
to get values in sq. kilometres.
35
Press ok if your details correspond to those above and save your edits. The clipping operation left out
sections of other constituencies not of Nakuru county. They have to be removed. Click Select features
by expression and in the dialog box, key in "COUNTY_NAM" IS NOT ‘NAKURU' in the expression box using
the values in the two boxes to your right.
You will notice the remnants of those counties outside Nakuru have been selected in the attribute table.
Use to delete the selected rows. Save your edits and close the attribute table. Use Layer Labelling to
add labels using the “CONSTITUEN” field. Create a new print layout called “Nakuru_atlas”. Create a map
showing the whole of Nakuru county as previously. Set an appropriate scale that will make the map fit in
the frame. Add frame. Also add coordinate grid frame using the settings below:
36
Figure 40: Adding a Grid Frame to the Map
37
Figure 41: Adding Coordinates to the Grid Frame
Add a scale bar and snap it to position on the bottom left of your map. Set it to the options shown below:
38
Figure 42: Scale bar settings
Add a North Arrow and in its image rotation properties, ensure that the arrow is synced with map with
its north alignment set to true north. Use to add a legend to the map layout. Place it slightly above
the scale bar. Under Legend Items double-click the items to change the names of the layers to the
following new ones:
From To
Change the values of the Slope Steepness Index to the following categories:
<= 0 to Level
39
27.19 – 36.25 to Extreme Slope
Scroll down and disable the background of the legend. Under the Main Properties give your legend the
title: LEGEND. Next, you are to add a page number box that will autoincrement to other pages of the atlas.
Using the Add Text icon, draw a text box. Use the Insert an Expression and under the Variables dropdown
double-click “layout_pagenumber” which will appear in the box to your left. Align your text well using the
Appearance drop-down. Put a text label at the top of your map frame with the words: NAKURU COUNTY
RELIEF MAP: [% "CONSTITUEN" %]. Use Insert an Expression to fill in the last part after the colon (:). Select
the map frame and tick both boxes of lock layers and styles for layers. Go back to main Qgis canvas,
deactivate all other layers except for constituencies and remove the labels for this layer. Draw an overview
of the constituencies layer at the top left of your map. Add a frame for the overview map. Under the
“Overview” dropdown, add a new overview and select “Map 1” as the map frame. Lock both this layer
and its styles.
Go back to the main Qgis canvas and restore the layers and their settings to be as before. Go to the print
layout and to Layout>Save Layout as template or simply click . Unlock only the layers and stylings of
your main map frame. Go to the atlas tab and adjust its settings to be as below:
40
Figure 44: Atlas Generation Tab
Click the Preview Atlas icon at the top to check your atlas. Scroll through the pages and note the
title of constituencies changes as we scroll through the pages. You will note the page number is stuck at
1. Click the text box, clear layout_pagenumber and replace it with atlas_featurenumber. To get more
data of the constituencies, such as the area, you will need to add an attribute table. Click to the
bottom right of the map frame. Set the source of the attribute table as Current Atlas feature under its
main properties. Select Attribute remove all other rows except for the COUNTY_NAM, CONSTITUEN and
Area (Km2). Under the “Heading” field, edit the names of the field columns as shown in the diagram
below:
41
Figure 45: Adding and Customizing the Attribute Table for Print Layout
Under Appearance, increase the cell margins of our attribute table to 2.00mm. Click Advanced
Customization and set the header rows of our column to be grey in colour. Change the fonts of your
headers and rows to your preferences.
Scroll through the map pages to check for any problem. For example, if the attribute table size extends to
beyond the map frame due to many area values for large constituencies, you can take it further inward.
If you are satisfied with your results, go to the Atlas menu at the top and select Export Atlas as Pdf. The
final pdf result is downloadable from here.
42
Hydrology Analysis
For this section, you will carry out small hydrological analysis of Nakuru county. Some analyses are done
using GRASS and SAGA tools in Qgis. However, in some instances they are complicated to work with, either
due to limited information as in the SAGA tools, or errors being generated from Grass. Grass GIS will solely
be used in this hydrological analysis. In your start folder, go to Qgis 3.8>Grass GIS 7.6.1 and open it. Open
the map location and mapset that had been created earlier on page 21.
The GRASS interface opens up two windows. The window on your left contains the tools for various
analyses. The window to the right is mainly for map display and addition of map elements.
A watershed is an area of land that drains all the streams and rainfall to a common outlet such
as the outflow of a reservoir, river, or any point along a stream (1). A watershed consists of all
surface water and underground water that drains downstream along the flow of gravity. All of
the land that drains water to the outflow point is the watershed for that outflow location.
The desired output for this exercise is a map of the watersheds of Nakuru county. In the Grass
layer manager to your left, go to File>Import raster data>Simplified raster import with
reprojection and browse to the Nakuru_DEM file. Once it’s loaded, click on color properties and
set the color table to elevation. Click on the Raster menu at the top and go to Hydrological
modelling>Watershed analysis. In the dialog window that appears, put in Nakuru_DEM as our
input elevation and a value of 1000 as our minimum exterior watershed basin size. We are putting
such a large size since a smaller value will generate too many small watersheds that will be
irrelevant in our analysis. In the Outputs tab, only give names to the outputs shown below:
43
Figure 47: Grass Tool to Create Watershed
Leave the settings in the Outputs tab at their default and Run the tool. Four raster layers are
loaded into the map. Except for the “watershed_basins” and “stream_segments” raster, uncheck
the other two outputs from this analysis. Look at the watersheds map to your right on the map
display. Click on the watershed layer and using set color table, in the Define tab, check Invert
colors and Name of our color table as bgyr and run the tool. It is difficult to attach a value of
importance for each watershed depending on the volume of water that flows from it when
compared to the rest. To solve this, we will use a legend. Click on and select Add raster
legend. In the dialog window that pops-up, select “nakuru_watersheds_basins” as the raster map
to use.
Under Advanced of r.legend, put in a thinning value of 20, and under the Gradient tab, check
draw smooth gradient. Customize the font of your legend in the font settings tab. The thinning
value arranges the legend to an appropriate size with readable texts. To check if the
44
“stream_segments” output corresponds to the streams network of Nakuru, load the
“Nakuru_rivers” vector into the map. The alignment of some of the shapes in the
“streams_network” raster match to those of the “rivers” shapefile. Go to File>Workspace>Save
and save your work as “nakuru_hydrology” in a new working folder called hydrology_test.
Waterbasins with a higher value on the legend scale have more water flowing from out of them.
Open r.watersheds again, create an accumulation map called “nakuru_accumulation”. Uncheck
the names in the rest of the output boxes so as not to generate their files. Load the Nakuru
waterbodies shapefile and overlay it over the accumulation raster. Does the location of our
waterbodies match the areas of greatest accumulation? Save this workspace.
45
sum: -897874.620001049
1st quartile: -117.882
median (even number of cells): -1.65
3rd quartile: 85.35
90th percentile: 191.838
(Tue Feb 11 13:00:02 2020) Command finished (0 sec)
The highest USLE R value for Nakuru is 372 while the lowest is -232. Go back to the layer manager,
uncheck all rasters except for the annual precipitation and USLE R raster. In the File menu, go to
Map Swipe, click on it and a new window appears. Select “nakuru_usle” as the top/left map and
“nakuru_annual_rain” as the bottom/right raster map and click ok. Drag the Map Swipe window
to the left and using the legend of the precipitation and USLE R layers, drag the scroll bar at the
bottom of Map Swipe window left-to-right. You will notice areas of high USLE R factor values also
experience high annual precipitation compared to other areas and vice versa.
46
Click the power button to quit map swipe. Go back to the map display window. Right click
on the legends to remove the legends of “watershed” and “annual_rainfall”. With the USLE R
factor map on display, click on and save your USLE R factor map in .jpg format. Save this
workspace and quit Grass.
Rainfall erosivity is the kinetic energy of raindrop’s impact and the rate of associated runoff. The
R-factor is a multiannual average index that measures rainfall’s kinetic energy and intensity to
describe the effect of rainfall on sheet and rill erosion. A precise assessment of rainfall erosivity
requires recordings of precipitation at short time intervals (1-60 minutes) for a period of at least
several years. The rainfall erosivity is calculated by multiplying the kinetic energy by the
maximum rainfall intensity during a period of 30-minutes for each rainstorm. The R-factor
accumulates the rainfall erosivity of individual rainstorm events and averages this value over
multiple years2. The units [MJ.mm/ha.hr.year] stand for Megajoules per millimetre per hectare
per hour in each year. 4184 megajoules make a 1 ton. So, a conversion of the above maximum R
factor 373 to tons results in a loss of 0.08891013384 tons. When converted to kilograms, this is
2
Esdac.jrc.ec.europa.eu
47
a loss of 80.65 kilograms of soil per unit millimetre in every hectare per hour per year. This is the
rainfall erosivity for Nakuru for an average total annual rainfall of 1488 millimetres.
Optional Exercise
The purpose of this exercise is to assess the watersheds in Nakuru county based on their areal
and percentage coverage. Open a new Grass workspace and load the watersheds raster into it.
Go to Raster>Map type conversions>Raster to vector. Give a name for your output vector map
and in the output feature type select area in the dropdown. Click the v option in the attribute tab
and then run the tool. A vector map with the delineated watersheds is created.
Right-click the watershed vector map and in the labels tab, select cat as the column to be
displayed as label. The next step is to generate the unit area of each watershed. This will help to
identify the watershed that possibly generates the greatest outflow in the county. Click on
v.report under the Reports and Statistics option of the Vector menu. Apply the settings shown
below:
In the Optional tab, set your units of calculation to be in kilometres and the result to be sorted
in descending option (desc). Run v.report. The report will be generated in the command output
tab. The codes of the watersheds are under the CAT field while the values under the “area”
48
display the extent of each watershed in square kilometres. Next, the area statistics will be
appended to the watershed vector. This will help in selection of the necessary watersheds based
on area criteria which can be saved to a different file. On the Grass GUI, go to the menu
Vector>Update attributes>Update database values from vector. Select Area as the value to
upload and give a name for your new column in the columns=name field. Check only for
boundary as feature type and in the Optional tab, set units to be inkilometres. Run the tool.
Right click the watershed vector to view the new “Area_km2” column of the area for each
watershed in square kilometres. Using the SQl Query below the attribute data, select the
watersheds that are greater or equal to 200 sq. km. and click apply.
The watersheds that fulfil this function are shown in yellow in the map display. To create a new
vector for the watersheds that fulfilled this function, right click at the attribute data and select
Extract selected features. Give your new vector a name and ensure the box for adding your map
to the layer tree is checked. Click ok. Save your Grass workspace.
Geomorphology of Nakuru
Open Grass, and still using nakuru_manual as your map location and map Permanent as the
mapset, start a new Grass session and name it “nakuru_geomorphology_3D”. Load the Nakuru
DEM raster to your layer manager. Grass tools will be used to view the terrain forms
(geomorphology) on Nakuru’s DEM surface. Go to the menu Settings>Computational region>Set
region. Go to the Print tab and select both the (p) and (m) options. Run the tool.
49
Figure 52: Setting the Grass Region to the DEM
In the command output tab, the tool prints out the North-South, East-West bounds, projection,
zone and the resolution of our DEM at the bottom. The resolution values read as follows:
nsres: 231.00644481
ewres: 230.92923433
These are the resolutions of the DEM where nsres stands for the North-South resolution and
ewres stands for the East-West resolution of this DEM. The resolution values are in metres
because we ticked the (m) option. Therefore, the overall resolution of this DEM is roughly 230
metres which is not good but due to lack of other freely available data it will still be used in this
analysis.
In the layer manager, go to Raster>Terrain analysis>Landforms. In the window that appears,
select “Nakuru_DEM” as your input elevation map. Set your outer search radius to be 230. In the
Patterns tab, type in nakuru_landforms under forms=name. This will be the output. Put in an
outer search radius of 230 since that is the resolution of this DEM. Run the tool. Add the legend
50
of landforms to the map display where the colors will help you identify the various landforms. To
check if the result corresponds to what is on the ground, add the waterbodies shapefile to the
map and apply labels. You will notice that most lakes, if not all, lie on the valley floor (in blue) and
some like L. Nakuru and L. Elementaita are situated in depressions. Save your landforms file as
“nakuru_landforms” in .tif format. Quit Grass.
Viewing in 3D
Go to your Start on windows, browse to the Qgis 3.x folder and open SAGA GIS. An interface such
as the one below will open.
Click on “empty”. Go to Open on the top left, below File menu and click it. Browse to the 3D
folder available from here. Open the Extracted_Dem to your Saga interface. If you can’t see it use
All Files in the file browser dropdown. Save your Saga session with the name, “Nakuru_3D”. Right
51
click the DEM file and select Add to Map. Enlarge the window to your right containing the map.
Thereafter, scroll along the toolbar icons until you find Zoom and click it. Zoom to the extents of
your DEM. Make sure it fills the window as much as possible. Go to Open files, select all files and
download the natural colour Landsat image in the folder. Select Load all bands and Okay. Select
Geoprocessing menu>Visualization> Grid>RGB Composite. You will combine the Red, Green, Blue
bands that make up this Landsat image to form a composite a natural colour image. Next to the
dialog box of Grid System select the grid system for which your Landsat bands fall under in the
Data tab. Tweak your settings as they appear below.
52
Figure 55: Combining Individual Bands to form an RGB Image
Click Okay. A new feature appears under the Landsat image coordinate system with the name
Composite. To view the DEM and the Landsat composite in the same window, the grid system of
the former will have to be transformed to match that of the Landsat image. Go to
Geoprocessing>Projection>Coordinate Transformation (Grid).
53
Figure 57:The Coordinate Transformation Dialog Box
Next to Loaded Grid, click the empty box and select the Grid System of the Landsat image and in
the box for Grid, select Composite. Under Data Objects, put in the Grid system of
“Extracted_DEM” as you see in the Data tab and as source, select “Extracted_DEM” as shown
above.
Click Okay in this window and in the next pop-up dialog box as well. A new “Extracted_DEM” file
appears. To the right of layer manager, under Properties, use the Descriptions tab to find the
DEM file with the projection WGS84/UTMzone36N. Once you find it, go to the Settings tab and
rename it to “Extracted_DEM2” and click Apply at the bottom. Right click Composite and select
Add to Map. Right click “Extracted_DEM2” and select it to be added to the Composite map as
shown below.
54
The new DEM appears overlain on the Landsat image.
Zoom to the extents of “Extracted_DEM2” image. Drag the “Extracted_DEM2” to the Composite
image and ensure it appears below the Composite image. Go back to the Data tab of the layer
manager. Click the 3-D icon on the toolbar. On the dialog window that appears, select the grid
system for “Extracted_DEM2” which should be identifiable in the Data tab. Select
“Extracted_DEM2” as your Elevation, check for the Bounding box and for Background colour,
set it to Black.
55
Figure 60: Settings for 3-D Viewing
Click Okay. A 3D view of the extents of “Extracted_DEM2” appears overlain above the subset of
the Landsat image. You will have noticed that the toolbars at the top have changed to those of
3D.
Search for to exaggerate the terrain of the area and to bring your map closer. Experiment
with the rest of the 3D tools in this toolbar. Once you are done, click the 3D view tab>Save image
as and save the map in .jpg to outputs in your working folder. Go to the top left of your SAGA
interface, click 3D and Close to exit 3D view. Save your project and in the pop dialog window,
check Save all and Okay. Exit SAGA.
56
Georeferencing
Suppose you have a scanned map in either jpeg or pdf format that you would like to overlay on
a georeferenced file, either a raster or vector. You would need to use a raster or vector with a
known spatial reference that will be used to reference the scanned document to the correct
geographical location. For this exercise, you will georeference an old toposheet map of Lodwar
to Turkana county and underlay a current Landsat image to view any similarities between the
two. The Lodwar toposheet is available from here.
Open Qgis. Load the counties’ administrative shapefile from the Kenya_admin_WGS84 folder.
Add the ke_waterbodies, ke_major-rivers and kenya_roads(wfp) shapefiles from the vectors
folder. Open the attribute table of the administrative shapefile, under the COUNTY field, search
for Turkana and zoom to this county using Zoom map to selected rows.
Close your attribute table and deselect all selected features. Save your Qgis session as
“Georeference”. Time to add the Lodwar toposheet and to georeference it to the administrative
layer. Go to Raster>Georeferencer. A new interface window will appear. Use on the top
left of your Georeferencer interface to add the Lodwar toposheet. The toposheet appears in your
georeferencer window. Click to open the Transformation settings dialog box. Save your
output as “Lodwar_modified” in a new working folder. Change the rest of the settings to those
below and click ok.
57
Figure 63: Transformation Settings of the Georeferencer Plugin
The checked Save GCP3 points auto-saves the points used in georeferencing to a .gcp file which
can be opened later.
Minimize this window and look at your Qgis map and maximize it again. Do you notice any
features that appear at the same places on both maps? Minimize the georeferencer window, go
back to Qgis and zoom to the region shown below.
3
GCP is an abbreviation for Ground Control Points.
58
Figure 64: Region of the Lodwar Toposheet Map
On the georeferencer window, zoom to the region below. You should see the name Lake Rudolf
which was the colonial name for the current Lake Turkana. Zoom in to the camp at Ferguson gulf.
59
Figure 66: Ferguson Gulf, Lodwar, 1960
At the point of Government camp, click that point using . A popup will appear, select From
Map Canvas. Back to your Qgis map, select the point at which this area appears and click. You
will notice that coordinates have automatically been added to the X/East and Y/North boxes.
Press ok.
Keep adding coordinates to the georeferencer window by using intersections of rivers and roads,
bends on rivers etc. Though this is not the best practice, the quality of the data we have dictates
so. The best points for georeferencing are points of landmarks, edges of boundaries, map
60
coordinates and tall structures such as communication masts. Use the points below for the
toposheet and Qgis window respectively.
Once finished, look at the GCP table below the canvas of the georeferencer window. Starting with
the count of 0, the table is composed of nine points. Depending on how you placed the points,
the values will vary. What is of interest is the residual pixels field that will be used to rectify the
positions of the GCPs. To have an accurate output, the residual pixel values should be close to 0
61
as much as possible. Zoom in to one of the points. Use to drag the head of the GCP to the
tip of its tail until both the head and tail coincide. Click to go back to our previous zoom
extent, choose another point and do the same. Drag head to tail until both coincide. Do this for
all the other points. Use to zoom to the layer extents of your toposheet. After doing this
for all the points, you will notice that some GCPs have increased in their residual errors while
others have reduced. That’s okay. Check and uncheck the GCP with the largest residual value to
spot its location on the toposheet. Starting with the GCP with the largest residual values, repeat
the same procedure for all the points until the residual pixel values are as close to 0 as possible.
Look at the information at the bottom of the georeferencer. It displays the transformation setting
currently in use, rotation and mean error. The lower the mean error, the more accurate the
georeferenced file will be relative to the position of the file loaded in Qgis.
Once satisfied with values in the GCP table, click to run the georeferencer or go to File>Start
Georeferencing to add your georeferenced file to Qgis. The file is added to Qgis in .tif format.
Lake Rudolf is a bit off from Lake Turkana by a small margin. Set the transparency of
Lodwar_modified to 57.8% and see if there any similar features to the underlain vectors. Add the
Landsat look image to Qgis and check for any similarity between the toposheet and Landsat
image.
62
In your Browser tab, scroll down the icons until you see the XYZ Tiles layer. Right click it and select
New Connection.
Name: Google Earth
URL: https://mt1.google.com/vt/lyrs=m&x=%7Bx%7D&y=%7By%7D&z=%7Bz%7D
Leave the rest of the options at their defaults and press ok. A new layer appears under XYZ Tiles
named Google Earth. Right click this layer and select Add Layer to Project. Place it under
“Lodwar_modified” and use the activation button and transparency to note any similarity or
difference between the features on the Lodwar map and the Google image.
Supervised Classification
Downloading a satellite image
Last time, at the beginning of this tutorial, you learnt how to download a DEM image from the
Earth Explorer site. The same procedure will be used to download a Landsat Satellite image that
will be used to carry out land cover classification.
Open Earth Explorer and sign in. Search for Nakuru as you learnt in page 2 and put in the dates
from 01st January 2019 to 31st March 2019. In the datasets tab, select Landsat Collection 1 –
Level1 and check the Landsat 8 OLI option. Go to the Additional Criteria tab and set Land Cloud
cover and Scene Cloud cover to be less than 10%. Click the Results button. Two Landsat scenes,
one for 12th March and 23rd January will appear on the screen. To check the quality of the images,
such as the quantity of cloud cover, browse through the icons below the January image until you
find the Show Browse overlay icon . Do the same for the March image. Which of the two has
less cloud cover? Under the 12th March image, in the Download options button, select the Level-
1 GeoTIFF Data Product (923.6 MB). Download and extract the contents of this folder. Open
Qgis 3.x with Grass. The SCP plugin will be used for land cover analysis. Go to Plugins>Manage
and install plugins and search for semi-automatic classification plugin. Install it. Once the plugin
is successfully installed, close the plugin window.
Click to open the SCP plugin. If you can’t see it, activate it under View>toolbars.
63
Figure 71: Bandset Menu of the SCP Plugin
Under Bandset, select the Open file icon shown in red above and browse to the extracted Landsat
components. Select Bands 1 to 11 abbreviated by their shortforms B1, B2... and so on.
The bands will be loaded into the singleband list and under Bandset definition. The bands will
be grouped into one list called Bandset 1. You will notice that the images have been loaded into
the Qgis canvas. Load your “Nakuru_waterbodies” shapefile as well. On the list of tabs to your
left, go to Preprocessing tab. On the list of menus above, search for Clip multiple rasters.
64
Figure 72: Clip Multiple Rasters tab of SCP
The plus (+) button is used to highlight the area on the map that is used to clip bands. To highlight
an area, click on this tool. On the Qgis canvas, left click on the map for the starting point, which
will be the top left border. To finish, right click to set up the closing point which will be the bottom
right point of the area’s rectangle. The area of interest (AOI) is shown below.
65
Figure 73: Drawing the Area of Interest (AOI) on Qgis using SCP
UL - 819475.721; -29298.544
LR - 854486.440; -54447.088
Click Run and save the outputs to a new folder with the name
“Nakuru_supervised_classification”.
New layers with the prefix “clip_..“ will be loaded to the layer manager and map view. Remove
all the other previously loaded Landsat images. Save your project as “Nakuru_supervised”. Zoom
to the extents of one of the clipped Landsat images. Still in the Preprocessing tab, scroll the list
of menus back to the left until you find the Landsat menu. The next step involves cleaning the
Landsat image from the atmospheric effects of scattering and haze.
66
Figure 74: Loading Raster using the Landsat tab of SCP
In the box next to Directory containing Landsat bands, select the folder containing your clipped
Landsat images. For the MTL file, browse to the original extracted Landsat folder downloaded
from Earth Explorer. You will see two text files, select the one with the “.MTL”. You will notice
the data for the bands in the directory appears in the Metadata table. Check for Apply DOS1
atmospheric correction and Use Nodata value but uncheck all the other boxes. Click Run and
save your outputs to clipped_supervised folder. New images with the prefix “RT_...“ appear in
the layer manager tab. Remove all other previously loaded “clip_...” images. Go back to the
Bandset tab and refresh the singleband list. The new RT layers replace the remove layers. In the
Bandset 1 list under Bandset definition, click Reset to remove all the previous bands.
67
Figure 75: Adding bands to the bandset list
In the Single band list, click Select all and the (+) button to make the RT layers show up in the
Bandset definition list. They will be listed as Bandset 1. In the dropbox of Quick wavelength
settings, select Landsat 8 OLI (bands 2, 3, 4, 5, 6, 7). The Quick wavelength settings shows the
bands that SCP will use to create a composite image. Use the minus (-) menu to delete the
unnecessary bands 1, 8, 9, 10 and 11 from the Bandset list. Once done, check Create raster of
bandset (stack bands) under Bandset tools. This will create a composite image for the bands in
Band set 1. Click Run and save your image in a folder named 2019 bandset. Once the bandset is
loaded into Qgis, save it as Geotiff with the name “2019_image”. Leave it with the default CRS of
EPSG 32636/ UTM Zone 36N. Saving it as geotiff will make your file readable to other softwares
such as ENVI. Remove the RT bandset and all other RT bands from Qgis. Save your work.
68
Figure 76: Symbology settings for a false colour image
You will notice areas of green vegetation turn red in the image. This is called a false colour image.
Go back to Bandset tab in the SCP window. Click Refresh list and select “2019_image”. The bands
composing the 2019 image to be classified will appear under Bandset definition. Select Landsat
8 in the Quick wavelength settings dialog box.
On the SCP dock, click the training input tab and go to ROI signature list4. Select create a new
training input and save it to a folder named 2019_image_training and save your training_input
as “2019_training_inputs”.
4
ROI stands for Region of Interest
69
Table 1: Macroclass Table for the 2019 Image
MC ID MC Info
1 Vegetation
2 Urban
3 Rangeland
4 Bushland
5 Agriculture
6 Lake
Browse the SCP tools in the Qgis toolbars to be oriented with their purpose. Using ROI
pointer, point to the vegetation area to the south east of the map and click. If the ROI region
(highlighted in yellow) exceeds the border of the area in red, reduce the ROI distance and click
70
to readjust the area. If the ROI region in yellow is too small, increase the ROI distance and
click the redo button. The ROI distance enables you to change the ROI size captured by SCP. In
this case the ROI size is being adjusted to have a perfect fit of the land cover to be classified. In
the MC ID box, the value should be 1. Change the value in the MC Info box to Vegetation. Leave
the value at C ID box as 1 but in the C Info box change the value from 1 to be forest. Click the red
icon below the C Info box which when the mouse is highlighted over it reads Save temporary ROI
to training input. Go to the areas in red around the lake. Place your ROI pointer to the vegetation
south of the lake. Click on it. Use ROI distance to adjust size of the ROI till it only covers the red
pixels of the vegetation area. You will notice MC Info remains the same but the C ID has
autoincremented to 2. This is the crux of how ROI capture works. If a land cover is under the same
Macroclass (MC), various categories of this land cover class can be captured in the same MC only
that their numbers will increase as you add more classes to the same MC. C Info, which stands
for Class Info, can capture the names of the various land classes within the same Macroclass.
Capture as many areas of vegetation around the lake, but give the name “Shore Vegetation” in
the C Info as you autoincrement their ID Numbers. Note that classifying another class within the
same C ID number and clicking the Save icon will replace the former C ID.
In this Landsat image there are human settlements such as residences, urban areas and estates.
These are located some distance away from the lake and their reflectance is mostly in the colour
grey. Since this land cover class is different from vegetation, you will give it a different MC ID. In
this case it will be MC ID – “2” since you are adding another Macroclass. The areas to be classified
as MC Info – “Urban” are located to the Northwest and East of our lake. Using the ROI pointer,
classify them as MC Info – “Urban” and C Info – “Built-up”. Remember to increment the C ID as
you add different forms of Urban settlements in the C Info such as estate, CBD et cetera. For
rangeland, which is open country in this case, it is located south east of the lake and characterized
by an open space that is pale grey in colour. Classify it using the ROI pointer. The identification of
this land cover class should be MC ID – “3”, MC Info – “Rangeland”, C ID – “1” and C Info –
“Barren”. The land class is classified as barren due to its scarcity of vegetation. MC “Bushland” is
located between lake and human settlements. Give it the C Info – “Savannah, thickets”. MC Info
– “Agriculture” is located to the Northwest of the map. Activate ROI pointer in one of the plots
and ensure the ROI region fits within a particular plot. Give the plots the C Info “farmplot”. Do
this for several farm plots here and elsewhere in the Landsat image. For the lake, which should
be MC ID 6, only classify starting from the edge, and all around the edge. Your ROI distance should
be set in such a way that the ROI region extends from the edge of the lake’s waters and extending
inwards. Do this all around the lake and save your ROIs. Ensure the ROI covers the colour
variations in the lake to avoid problems during classification.
Highlight all the training signatures in the signature list by selecting the first row, press “Shift”
and select the last row. On the left of your signature list, press the icon which says “Add
highlighted signatures to spectral signature plot” shown in red below.
71
Figure 78: Highlighted Signatures in the ROI Signature List
72
Figure 79: The Spectral Signature Plot
In the spectral signature box plot, you will notice some rows are highlighted in yellow. This shows
that their spectral signatures are overlapping with other land classes. Note the class that it
overlaps with in the column labelled “Color – Overlap [MC_ID – C_ID]”. The easiest option in this
case is to note the MC ID and C ID of the overlapping signatures (in yellow) and delete them from
the ROI signature list so as to preserve only those that are accurate. Highlight all the rows in the
spectral signature plot and delete them using the delete row icon. In Qgis, replace the
deleted training signatures with new ones, with smaller ROI pixel size. After you are done, open
the spectral box, remove all the previous signatures and close the box. Go back to the SCP dock.
highlight all signatures in the updated signature list and add them to the spectral plot. If you
repeated the ROI classification well, note that there are few overlapping spectral signatures.
Highlight all the signatures in the spectral box plot and click to calculate the spectral
distances of your signatures. Go to the Spectral distances table at the bottom, some of the
signatures for Built-up and barren, and built-up and farmplots are really similar to each other as
can be seen in their high Bay-curtis similarity values. A Bay-Curtis similarity value appearing in
red is an indication that the two land classes in comparison have very similar spectral signatures.
This may lead to incorrect classification. Minimize the spectral signature plot. Go back to SCP
dock and in the Macroclass list, select appropriate colours for your MC IDs by double-clicking on
the Color tab.
73
Figure 80: Macroclass Tab of SCP
To preview the classification results, click the to activate the classification preview pointer
and click on an area to preview your results. You can use the preview button to
show/hide classification preview or by simply unchecking the temporary preview layer in the
layer manager tab. You can remove temporary layers by clicking the button. Once satisfied,
go to the classification tab and set your settings to be as below:
74
Figure 81: Classification Tab of SCP
Click Run and save your work to a folder called 2019_classification and the .tif file as
“2019_landcover”. The landcover .tif file will be loaded to Qgis. Save your training file as a
permanent file by right-clicking it, select Make permanent and save it as
“2019_training_file.shp”. Add it to the map and open its attribute table. The MC ID and C ID for
each ROI also appear on the table.
75
Loading 2003 image
Using Earth Explorer, download the Landsat georeferenced tiff image for March 8 th 2003. Your
Landsat Product ID should read "LE07_L1TP_169060_20030308_20170126_01_T1". The file size
is about 292MB. Create a new project in Qgis, and name it “2003_image”. This Landsat 7 image
will be clipped to the same AOI as for the 2019 image and preprocessed to remove atmospheric
effects of light scattering.
Using SCP’s Bandset browse to the extracted Landsat 7 folder and load all the 9 bands from B1
to B8. Select Landsat 7 in the Quick wavelength settings dialog box.
In the Preprocessing menu, under Clip Multiple Rasters tab, use the previous coordinates given
in page 59 to clip your images. Click Run and save to a folder named “2003_clipped_supervised”.
Remove all previous layers and remain only with those with the prefix “clip_”. Zoom to the
extents of these layers.
Still under the Preprocessing tab, scroll to the left of the Landsat tab. The Directory containing
the Landsat Bands should be the folder with the clipped 2003 images. Select the MTL file from
the extracted Landsat 7 folder. Notice the values are updated in the Metadata table once the
MTL file is loaded.
Check only for Apply DOS Atmospheric Correction and Use No Data value and uncheck for all
the other boxes. Click Run and save to a folder named “2003_preprocessed_bands.”
Remove the bands with the prefix “Clip_” and only remain with those with the prefix “RT_”.
Go back to the Bandset tab, refresh the Singleband list. The new “RT_” layers should show. Under
Bandset definition, click the Reset icon to clear all the previous layers.
Select all the RT layers and add them to the Bandset definition list. Remove the row with the
band numbers ending with B8, B6_VID1 and B6_VCID2 from the bandset definition list. This is
because your Quick wavelength settings show that SCP will only use Bands 1, 2, 3, 4, 5, 7 to
bandset Landsat 7 data. Click on B8 and using CTRL button select the two remaining B6 bands
and delete them from the bandset definition list.
Click Run and save to a folder named “2003_bandsets”. Once the stacked raster is loaded to Qgis,
export it as .tif and name it as 2003 image. The newly created .tif format will enable it to be easily
read by other softwares such as ENVI.
76
Remove all other layers with the prefix “RT_” and remain only with your “2003_image.tiff”.
Go to the Symbology tab of the 2003_image.tiff and set your symbology settings to the following:
Refresh the image list located in the Bandset tab and select the 2003_image in the Multi_band
image list dropdown.
Using the SCP dock, create a new training file called “2003_training_inputs” in a newly created
folder named “2003_image_training”.
Just like you created ROIs for the 2019 image using the land classes on page 63, do the same for
the 2003 image. However, an extra seventh class will be added to account for the shiny surface
around the edge of Lake Nakuru.
Table 2: Macroclass Table for the 2003 Image
MC ID MC Info
1 Vegetation
2 Urban
3 Rangeland
4 Bushland
5 Agriculture
6 Lake
7 Sandy shore
77
Figure 82: Extra Classes around Lake Nakuru
Once you are done creating and saving the ROIs, set appropriate colours in the Macroclass tab
and set your Classification settings to these:
78
Figure 83: Classification Tab of SCP Dock
Click Run and save the output to the folder 2003_classification with the name “2003_landcover”.
Make your .scp file permanent by saving it as a shapefile with the name “2003_training_file” in
your 2003_image_training folder.
Minimize the Qgis window, go to the 2019_classification folder you had saved your 2019 land
cover image. Click the file with the prefix “_report” and open it with notepad. Copy the contents
to an excel file for better view. Put a suffix of the year of the image acquisition, in this case
“_2019” to differentiate with the report for the 2003 image.
79
You will notice that the area of each land cover class has been calculated in square metres under
the field Area [metre^2]. This is because the layers were in a local datum, EPSG 32636. If a world
geodetic ellipsoid had been used, such as for EPSG 4326, the area would have been calculated in
degrees. Using the classification table on page Error! Bookmark not defined., rename the class
names from their numerical digits to their appropriate class name. For example, Class 1 stands
for Vegetation, 2 – Urban and so forth.
The area and percentage values of your classification result may differ from those above. Don’t
worry, the purpose is to understand the concept. Create a new Qgis session. Load the 2003 and
2019 classification results. In this next step, you will assess the land cover change by class that
has occurred in this AOI between 2003 and 2019. Maximize the SCP window or click its icon in
the Qgis toolbars if you had closed it. Go to the Postprocessing tab and to the Cross-Classification
menu. Put in your 2003 image as the reference raster and 2019 as the new classification to
assess. Leave the Use No Data value checked. When this box is ticked, the land cover changes on
the class categorized as Unclassified (0) are excluded from the report.
80
Figure 85: Cross Classification Menu of SCP
Click run and save the outputs to a folder called 2003_2019_land_cover_changes. A .tif file is
loaded onto the map and the report appears in the SCP window under Output. Scroll down the
output to view the Cross-matrix table.
81
In your land cover changes folder, open the report in Excel using the same procedures as was
done for the classification statistics. We are most interested in the Cross-matrix table which is
located below the large table. The column header > Reference stands for the reference raster, in
this case the 2003 image, while the row header of V_Classification stands for the 2019 image.
You are free to rename the header names to their appropriate years to avoid confusion. Recode
the values of the land class labels to their appropriate names as was previously done for the
classification statistics on page 80.
Table 3: Cross-matrix table for Landcover Change
Using Excel workbook, Excel functions can be used to calculate in square kilometres the land
cover change from one class to another.
82
CrossClassCode Reference Classification PixelSum Area [metre^2] Area(Km2)
1 1 1 58965 53068500 53.0685
2 1 2 34185 30766500 30.7665
3 1 3 264 237600 0.2376
4 1 4 6171 5553900 5.5539
5 1 5 18064 16257600 16.2576
6 1 6 5553 4997700 4.9977
7 2 1 1485 1336500 1.3365
8 2 2 132010 118809000 118.809
9 2 3 9770 8793000 8.793
10 2 4 1008 907200 0.9072
11 2 5 16764 15087600 15.0876
12 2 6 4042 3637800 3.6378
13 3 1 6190 5571000 5.571
14 3 2 186615 167953500 167.9535
15 3 3 61609 55448100 55.4481
16 3 4 12656 11390400 11.3904
17 3 5 47575 42817500 42.8175
18 3 6 7503 6752700 6.7527
19 4 1 9457 8511300 8.5113
20 4 2 43973 39575700 39.5757
21 4 3 1939 1745100 1.7451
22 4 4 36157 32541300 32.5413
23 4 5 17488 15739200 15.7392
24 4 6 2133 1919700 1.9197
25 5 1 5829 5246100 5.2461
26 5 2 109945 98950500 98.9505
27 5 3 9296 8366400 8.3664
28 5 4 2810 2529000 2.529
29 5 5 80232 72208800 72.2088
30 5 6 2594 2334600 2.3346
31 6 1 126 113400 0.1134
32 6 2 884 795600 0.7956
33 6 3 35 31500 0.0315
34 6 4 159 143100 0.1431
35 6 5 71 63900 0.0639
36 6 6 37582 33823800 33.8238
37 7 1 14 12600 0.0126
38 7 2 1045 940500 0.9405
39 7 3 0 0 0
40 7 4 0 0 0
41 7 5 0 0 0
42 7 6 5748 5173200 5.1732
83
Accuracy Assessment
Once classification is done, the validity of the classification results is assessed by measuring the
level of accuracy of the user and the machine during the classification process. In the context of
image interpretation, accuracy assessment is defined as the quality of information
derived from remotely sensed data (2).
Go to the SCP dock and use to load the 2003 and 2019 training inputs to Qgis. Ignore the
error message stating “Signature bands don't match band set. Calculate the spectral signature
again”. Maximize the SCP window, go to the Postprocessing tab and to the Accuracy menu. Select
the 2019 landcover image as the classification to assess and the “2019_training inputs.scp” file
as the reference raster. Choose MC ID as your vector field. The reference raster or vector is the
file which was used to create land cover classes, in this case the training inputs file. In other
words, it is the file which the classification results will be assessed against. The classification file
is the SCP output of a classification process. The vector field stands for the class group that
trained SCP to classify an image. Save your .tif file to a new folder. In the output tab, tables are
generated. Scroll down the output tab to the Cross-matrix table at the bottom, to the AREA
BASED ERROR MATRIX. We are interested in the following information:
Overall accuracy [%] = 91.8790
Kappa hat classification = 0.8856
In my case a kappa hat classification of 0.88 is not that bad. According to (3) this value is almost
a perfect match. It shows that there was a high level of accuracy during classification. The PA
and UA above refer to the SCP and individual accuracy performance respectively. The values are
calculated in percentages for each classified land cover. For further explanations on accuracy
assessment, read this chapter by Anupam Anand.
The output table report is located in the folder you saved your accuracy .tif image.
Using the above procedure of calculating accuracy assessment, perform accuracy assessment for
the 2003 classification image using the 2003 training inputs file.
84
Figure 88: Accuracy Assessment Menu in SCP
Save your Qgis session. Conducting an accuracy assessment of your classification results adds
credibility to the validity of your classification results. A kappa hat and/or Overall accuracy that
is too low is a sign the classification process may have erroneously labelled some land classes and
this may prompt for a repetition of the classification procedure.
85
Optional Exercise
After classifying the land cover classes in an image, the result looks speckled (presence of isolated
pixels in a certain class) and this makes the image appear ‘noisy’. To remove some of the speckled
spots so as to get a refined image, go to SCP>Postprocessing>Classification sieve. Select the 2003
classification image. Set threshold to 10 and pixel connection to 8. Click “Run” and save the sieved
result as “2003_classification_sieved” to the 2003_classification folder. The sieved 2003 .tif
result is loaded to the Qgis canvas. Compare it with the former 2003 classification by activating
and deactivating both images. You will notice that patches of land classes having less than 10
pixels of the same class around them are no longer present in the new image. Sieving is normally
done to smoothen out a noisy image.
86
Figure 91: The 2003 Classification after Sieving
𝑁𝐼𝑅 − 𝑅
𝑁𝐷𝑉𝐼 =
𝑁𝐼𝑅 + 𝑅
87
Table 4: Landsat 8 Bands
Wavelength Resolution
Landsat 8 Bands
[micrometers] [meters]
From the table above, the NIR and R bands for Landsat 8 from which the 2019 Nakuru image is
sourced are bands 5 and 4 respectively.
88
Table 5: Landsat 7 Bands
Wavelength Resolution
Landsat 7 Bands
[micrometers] [meters]
From the table above, the NIR and R bands for Landsat 7 from which the 2003 image is sourced
are bands 4 and 3 respectively.
Open Qgis. Name the project “NDVI_analysis”. Load the preprocessed clipped bands 5 and 4 for
the 2019_image from the folder clipped_supervised. The bands are
“RT_clip_LC08_L1TP_169060_20190312_20190325_01_T1_B5” and
“RT_clip_LC08_L1TP_169060_20190312_20190325_01_T1_B4” respectively.
On the Qgis menu, go to Raster>Raster Calculator. Using the equation below as a guide, select
the appropriate bands in the calculator box to calculate the NDVI of the 2019 Landsat image.
Equation 2: NDVI Formula
𝑁𝐼𝑅 − 𝑅
𝑁𝐷𝑉𝐼 =
𝑁𝐼𝑅 + 𝑅
89
Figure 92: Calculating for NDVI using Raster Calculator
Save your work to a folder called NDVI_results with the name “2019_ndvi” for the output .tiff
image. Click Ok. A singleband grey colour image loads into the Qgis canvas by default. Dark areas
have a lower NDVI value, with the lowest NDVI value being -0.137903 largely represented by Lake
Nakuru, completely covered in black. The higher NDVI values have a brighter hue and they are
shown by the forests to the south of the lake and to the south west of the image. Load and change
the “2019_image bandset” file to true colours to verify your observations.
To categorize the NDVI range, you will create a colour classification map of Nakuru’s NDVI. In the
symbology tab of the NDVI output, choose the RdYlGn colour ramp, set interpolation to discrete,
mode to equal interval and classes to 5. Areas in red have low NDVI, which signifies vegetation
stress, areas in yellow are experiencing moderate vegetation stress or moderate health, while
areas in green show healthy vegetation.
90
The value range of an NDVI runs from -1 to 1. Values approaching to -1 correspond to water,
values ranging from -0.1 to 0.1 generally correspond to barren areas of rock or sand. Low, positive
values from 0.2 to 0.4 represent shrub and grassland while higher values approaching to +1
indicate temperate and tropical rainforests. Remove the Landsat 8 “RT_” bands 5 and 4 as it is
no longer needed and is only used for pansharpening.
Load the preprocessed clipped bands 4 and 3 for the 2003 Landsat image from the folder
“2003_preprocessed_bands”. The bands 4 and 3 to be used for NDVI analysis are
“RT_clip_LE07_L1TP_169060_20030308_20170126_01_T1_B4” and
“RT_clip_LE07_L1TP_169060_20030308_20170126_01_T1_B3” respectively. Derive an NDVI
map for 2003 using Raster calculator as previously but use B4 and B3 as the as the NIR and R
bands respectively. Save your output as “2003_ndvi” in the NDVI_results folder. Remove the
bands with the prefix “RT_”.
Compare the two NDVI images of 2003 and 2019 time sets. Using the information tab in the
Properties menu, the maximum and minimum NDVI values of 2019 were 0.91 and -0.13
respectively. Likewise, the maximum and minimum NDVI values of 2003 were 0.89 and -0.61
respectively. From the above comparison, vegetation biomass for Nakuru county was healthier
in 2019 than in 2003 for this particular season under study.
We can create an NDVI deviation image with a colour coded scheme to visually show areas that
have gained or decreased in NDVI values. Use the Raster Calculator to subtract the 2003_NDVI
image from the 2019_NDVI image. Save your output as “2019_2003_ndvi_deviation” in the same
working folder for the NDVI outputs.
Once the ouput is loaded to the Qgis canvas, change the default singleband gray colour scheme
to singleband pseudocolour and apply the same symbology settings used in this exercise.
91
Figure 94: NDVI Deviation Image showing gains and losses for NDVI
The areas surrounded by the red boxes above, had the greatest reduction in NDVI between the
two dates. For the area around Lake Nakuru, the decrease in NDVI value is due to the increase in
the areal extent of the lake water from the year 2012. Experts attributed the increase in lake size
to increased surface and sub-surface water inflows. The area in the box to the left consists of
several human settlements and the reduction of NDVI is mostly from anthropogenic factors, such
as conversion of natural vegetation cover to other land uses. Zoom in to the area within the box
to the left and using the 2003 and 2019 true colour images, assess if this is the cause of the
reduced NDVI.
Right click on the NDVI deviation layer, select Properties and click the Histogram tab. Click the
“Compute Histogram” icon for Qgis to draw the histogram diagram of the NDVI deviation map.
Click the Prefs/Actions dropdown and check for Always show min/max markers. From the
histogram of the NDVI deviation layer, the minimum deviation values are close to -0.8 while the
maximum values are near +0.7. Most of the deviation values of the NDVI between the two dates
are between +0.5 and +0.15, which confirms that 2019 was a ‘greener’ year to 2003. To save this
histogram plot, click Save just below the graph.
92
Figure 95: Histogram Tab of Layer Properties Menu
As an exercise, check the NDVI histograms of the 2019 and 2003 images.
Close Qgis.
Albedo
Part of the AOI from which land cover classification and NDVI has been extracted so far also
covers Nakuru town. The town is located just to the North of the Lake. Albedo is the shortwave
reflectance from a surface, or the reflection of light intensity when incident rays from the sun hit
a surface. A portion of the solar radiation that hits a surface bounces off. This light that bounces
off is known as albedo. Shiny surfaces reflect more light intensity while darker surfaces reflect
less. Therefore, it is logical to assume that surfaces at/near urban areas will have greater albedo
than areas covered by vegetation. To find out the albedo of this AOI, browse to the
clipped_supervised folder containing the 2019 preprocessed clipped bands. Load bands 1-7 to
Qgis. Also load the 2019 stacked image from 2019_bandset folder. Go to the Processing menu
and type “albedo” in the search box. Click i.albedo found under Grass>Imagery.
93
Figure 96: The i.albedo tool from Processing Toolbox
Select the “RT_...” bands 1 to 7 as your input rasters, check for Landsat 8 and save your output
as “2019_albedo.tif”. Once the .tif result is loaded to the Qgis canvas, rename it to
“2019_albedo”. Set the colour ramp of your albedo image to “inferno”, interpolation as
“discrete”, mode as “Quantile” and classes to 5. Click Classify and apply the settings to your map.
The results vary somewhat contrary to our assumptions. With the 2019 true colour image as our
reference, the bareland areas have more albedo than the built-up urban areas. However, places
with dense vegetation and the lake itself have some of the lowest albedo values thus partly
confirming our assumptions. Remove the RT bands. Load the 2003 image from 2003_bandset
folder. Browse to the 2003 preprocessed clipped Landsat bands found in the
2003_preprocessed_bands folder. Select all bands except for bands 6 and 8. Load them into Qgis.
Using i.albedo, input the required bands and check for Landsat 5 + 7. Save your output as
“2003_albedo”. Rename it to “2003_albedo” in Qgis. Using the 2003 true colour image as a
reference layer, identify the areas that had the most and least albedo values and correlate this
94
with the 2019 albedo result. Do you notice the changes? Where? Use the Information and
Histogram tabs in the Properties box for each albedo output to analyse the differences in albedo
values between the two years. Save your Qgis session as “albedo_analysis” under Qgis_projects
in the Nakuru_manual folder.
Note: Sometimes the albedo from a satellite image can be influenced by the angle of solar
incidence from the sun. However, the MTL data of the satellites used to capture the AOI show
that both the sun azimuth and elevation for each of the two dates were almost coinciding. The
MTL data columns left-to-right are for Landsat 8 and Landsat 7 satellites respectively. Therefore,
the closeness of the sun azimuth and elevation for each of the two dates rules out any
discrepancy of the albedo results that may be attributed to a different positioning of the sun for
each of the two dates.
Emissivity
In remote sensing terms, emissivity is defined as the measure of longwave radiation returning to
the atmosphere from the earth’s surface. You will use the i.emissivity tool to calculate the
emissivity for the 2019 and 2003 NDVI images. This will help to find out which year between the
two images had greater longwave radiation returning to the atmosphere. Open your Qgis project
“NDVI_analysis”. Remove all other layers except the “2019_NDVI”, “2003_NDVI”, “2019_image”
and “2003_image” layers. Go to Processing>Toolbox, and type “emissivity” in the search box.
Click on the tool i.emissivity. For your input NDVI raster, select “2019_NDVI”. Save your output
in a new folder called “emissivity_analysis” as “2019_emissivity.tif”.
95
Figure 98: The Emissivity Tool
A new raster called “Emissivity” is loaded into the layer manager. Using the Symbology tab, select
RdYlBl colours and invert the colour ramp. Set interpolation to Linear and mode to continuous.
Click classify and Ok. Using the same procedure so far, create an emissivity raster using the
“2003_NDVI” image and apply the same symbology. Hover over the layers using the mouse to
find out their storage names and appropriately rename them in the Qgis layer manager.
The i.emissivity tools uses the NDVI range of 0.16 to 0.74 and classifies the emissivity values
between this NDVI range. As a result, the emissivity values of some objects appear exaggerated
when they are referenced with 2019 true colour image.
The table below shows the expected emissivity values for some objects. The table will be used to
assess the effectiveness of the i.emissivity tool.
96
Figure 99: Table for Emissivity Values
Go to Qgis menu, Layers>Create New Shapefile layer, create a new shapefile called
“2019_land_points” and set your settings as shown below:
Under New Field in the name box type “Land class” of type Text data and click Add to Fields List.
Use the Remove Field button to remove field name “ID”. Note that you have to change the CRS
97
from the default EPSG 4326 to EPSG: 32636. The reason for this is to make the points file be in
the same CRS as the raster from which to the emissivity attributes will be collected. Toggle editing
mode and create as many Land classes as you like, with the 2019 image as the reference layer.
Show the labels for your land classes in the Qgis canvas. Go to Qgis plugins and install the point
sampling tool. This tool collects attribute features from polygon layers and rasters to be probed.
With the “2019_land_points” and “2019_emissivity raster” checked, click the points
sampling tool to collect the values from the “2019_emissivity” raster. Select both
“2019_land_points” and “2019_emissivity” as the layers from which to get the values. Save your
98
output as “2019_point_emissivity” shapefile. Click ok.
Once the shapefile with emissivity values appended to land classes is loaded, open its attribute
table. Compare the emissivity values for each class with the table on page 97 to assess the
accuracy of the emissivity analysis. In my case, except for the iron sheets class, the rest of the
values are not too far off. Save your Qgis session as “emissivity_analysis” and quit.
99
Figure 103: Land Classes and their Emissivity
Building Models
Sometimes a need arises for the availability of a tool that automates a workflow procedure. This
eliminates the need for a step-by-step procedure when performing the same workflow for
different data. To do this, one has to create a tool that incorporates all the necessary processes
into one dialog box. In Qgis, tool making is done through the Models option found in
Processing>Toolbox. Once the Toolbox menu appears, select the models’ icon, and in the
dropdown, select Create new model option. This will open up a new interface shown below:
100
Before creating a model, it is imperative to identify the input(s) required, the specific processes
to be run, and the desired outputs. It is advisable to draft a schematic drawing of the model’s
structure before you start its creation. For this exercise, you will create a model that takes in the
NIR and Red band as inputs to produce two rasters of the NDVI and emissivity values.
Go to Inputs tab at the bottom and select Raster layer. Drag it to the canvas to the right. Double-
click it and in the Parameter name box, type “Near Infrared Band”. Ensure the Mandatory
checkbox is ticked which is the default setting and click Ok.
Select Raster Layer again from the Inputs tab and drag it to the canvas. Give the parameter name
“Red Band” and leave the mandatory checkbox ticked. Click Ok. At this point you should have
two yellow boxes on the canvas. Under Model Properties to your left, type “Models” as the
Group name and “Ndvi and Emissivity” as the name of the tool.
101
Figure 106: The Model Building Canvas
The next tool to be added will carry out NDVI analysis on the requisite bands. Click on the
Algorithms tab at the bottom, scroll down to the Grass menu, go to the imagery tab and search
for i.vi. Drag it to the canvas and immediately you let go of it using the mouse, a dialog box pops
up. Change the description of this tool from i.vi to “vegetation index analysis”. In the dropdown
for “input red surface channel reflectance map” select “Red band”. Leave type of vegetation
index as ndvi as the output the tool will create from the selected inputs. In the dropdown for
“input nir surface channel reflectance map” select Near infrared band. Notice from the options
that apart from “Not selected” the other choices are from the parameters you created earlier.
Leave the other options in their default settings. The Vegetation index box at the very bottom
requires a name for the final map result. Type in “NDVI” and click ok.
102
Figure 107: Customizing a Tool for Model Building
103
Figure 108: Building the Model Flow Schematic Diagram
To also add an emissivity raster as an output, drag i.emissivity to the canvas. In the description
box, change the name to “Emissivity”. In the name for NDVI raster map, select the option
Vegetation Index from algorithm 'Vegetation Index Analysis”. Vegetation Index Analysis is the
name of your customized tool while Vegetation Index is the result from the preceding analysis
that will be used as input in this case. Selecting this option will tell the emissivity tool to take the
NDVI result from the vegetation index tool and use it as an input to calculate for the emissivity
raster. In the box under emissivity, type in “Emissivity” which will be the name of the output from
this tool.
104
Figure 109: Adding the Emissivity Tool to the Model
105
Figure 110: A Complete Model Processing Schema with Inputs and Output
Scroll at the icons at the top, select and save the model as “ndvi_emissivity”. To test if the
model is successful click Run. This will take you to the main Qgis window and a dialog box
containing the input and output options for the “ndvi_emissivity” model will appear.
106
Figure 111: Running the Model
The Near Infrared Band option has a dropdown menu below it to select the NIR band if present
in the layer manager and an ellipsis to locate the band if in a different file directory. The same
applies for the Red band option. The “Emissivity” and the “NDVI” options have output options to
save the required outputs in various file formats. Click Close. In the main Qgis window, select the
Models icon again, in the dropdown select Add model to toolbox. Browse to the directory
you saved your model in and open it. The group name of your model, which was “Models” will
appear in the toolbox. The toolbox arranges modules in descending alphabetical order and your
Model will appear just above the SAGA tools. Click the dropdown arrow to the left which will
show the name given to the model in the model canvas, that is “Ndvi and emissivity” but not the
model’s name in the file directory. Experiment this model with the NDVI and Red bands for the
2019 and 2003 Landsat images. The metadata of the NDVI and Emissivity results should match
and if the symbology settings are copied from the earlier NDVI and Emissivity analysis, the results
should be identical.
With the model tool, the creation of new tools is limitless. Go ahead and create your own tools
to solve a problem!
107
FINIS
108
APPENDICES
109
Figure 112: An unsieved Nakuru 2003 Land Cover Classification Image
110
Figure 113: A Sieved Nakuru 2003 Land Cover Classification Image
111
Figure 114:An unsieved Nakuru 2019 Land Cover Classification Image
112
Figure 115: A sieved Nakuru 2019 Land Cover Classification Image
113
Table 6: Rating Criteria of Kappa Statistics
114
Glossary
Coordinate Reference System .................................................................................................................... 14
Geographic coordinate system ................................................................................................................... 15
Projected coordinate system ...................................................................................................................... 15
115
References
1. [Online] https://www.usgs.gov.
3. Accuracy Assessment of Land Use/Land Cover Classification using Remote Sensing and GIS. Rwanga,
Sophia S. and Ndambuki, J.M. s.l. : International Journal of Geosciences, 2017, pp. 611-622. 2156-
8359.
116