Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Preamble


Learning Objectives

By the end of this session, students will be able to:


Course Material

We use the same Sentinel-2 dataset as Session 2.

📂 Labworks data
📥 session_1_data.zip

If needed:

  1. Download the dataset

  2. Unzip the archive

  3. Place the folder in a known location on your computer


Tasks


Task 1 – Load the data

Open QGIS and load the spectral bands used previously.

Menu: Layer → Add Layer → Add Raster Layer


Task 2 – Computing NDVI

Vegetation indices exploit the spectral behaviour of vegetation.

Healthy vegetation:

The Normalized Difference Vegetation Index (NDVI) is defined as:

NDVI = (NIR - Red) / (NIR + Red)

For Sentinel-2:


Steps

Open the Raster Calculator: Raster → Raster Calculator

Enter the following expression:

(“B8@1” - “B4@1”) / (“B8@1” + “B4@1”)

Set:

Click Run.


Questions



Task 3 – Visualizing NDVI

Open Layer Properties → Symbology for the NDVI layer.

Select: Singleband pseudocolor

Choose a color ramp such as: Red → Yellow → Green

This visualization better highlights vegetation gradients.


Task 4 – Exploring NDVI values using the histogram

Open: Layer Properties → Histogram

Display the histogram of the NDVI layer.

Observe the distribution of NDVI values.


Questions


Task 5 – Pixel value inspection

Use the Identify Features tool and click on different land cover types:

Record the NDVI values.


Questions


Task 6 – NDVI classification using thresholds

NDVI values can be used to perform a simple land cover classification.

The idea is to assign a class number to each pixel depending on its NDVI value.

Each class corresponds to a type of land cover (water, soil, vegetation, etc.).


Step 1 – Open the Raster Calculator

Menu: Raster → Raster Calculator


Step 2 – Classification expression

Enter the following expression:

(“NDVI@1” < 0) * 1 + (“NDVI@1” >= 0 AND “NDVI@1” < 0.2 ) * 2 + (“NDVI@1” >= 0.2 AND “NDVI@1” < 0.5) * 3 + (“NDVI@1” >= 0.5) * 4

Save the output as: NDVI_classes.tif

The same logic is applied to all conditions, and the results are added together to produce the final classification raster. Since only one condition can be true for a pixel, the sum returns the corresponding class.

Output classes

The output raster contains integer class values:

ValueMeaning
1Water / negative NDVI
2Bare soil / urban areas
3Sparse vegetation
4Dense vegetation

Each pixel in the output image therefore represents a land cover class derived from NDVI thresholds.


Visualization

Open:

Layer Properties → Symbology

Select:

Paletted / Unique values

Assign colors to each class to visualize the classification map.

Questions


Task 7 – Cartographic layout

In this task, you will create a cartographic layout to produce a map of the NDVI classification.

A map layout allows you to prepare a map for presentation or export by adding elements such as a title, legend, scale bar and north arrow.


Step 1 – Open the Layout Manager

In QGIS, open:

Project → New Print Layout

Give a name to your layout (for example: NDVI_map) and click OK.

A new layout window will open.


Step 2 – Add the map

  1. Click Add Map in the toolbar.

  2. Draw a rectangle on the page.

The map from your QGIS project will appear in the layout.

You can adjust the extent and zoom level if needed.


Step 3 – Add a title

  1. Click Add Label

  2. Click on the page

  3. Enter a title, for example:

NDVI Classification – Casablanca study area

In the Item Properties panel you can adjust:


Step 4 – Add a legend

  1. Click Add Legend

  2. Click on the page

The legend will automatically display the NDVI classes.

You can edit the legend in the Item Properties panel:


Step 5 – Add a scale bar

  1. Click Add Scale Bar

  2. Click on the page

Select the map item associated with the scale bar.

You can adjust:


Step 6 – Add a north arrow

  1. Click Add Picture

  2. Click on the page

  3. In Item Properties, select a north arrow symbol

You can resize and reposition the arrow.


Step 7 – Add author and data source

Add a small text label with information about the map:

Example:

  • Author: Your Name

  • Data: Sentinel-2 imagery (ESA Copernicus programme)


Step 8 – Export the map

Export the final map:

Layout → Export as PDF

Save the file as:

NDVI_map_layout.pdf

Example of expected map layout

Example of a cartographic layout including title, legend, scale bar, north arrow and author information.

Example of a cartographic layout including title, legend, scale bar, north arrow and author information.