In the previous recipes, we saw how to change the values of a raster layer and create classes. When you have several layers, classifying might not be that easy, and defining the patterns to perform this classification might not be obvious. A different technique to be used in this case is to define zones that share a common characteristic and let the corresponding algorithm extract the statistical values that define them so that this can later be applied to perform the classification itself. This is known as Supervised classification, and this recipe explains how to do this in QGIS.
Open the classification.qgs project. It contains an RGB image and a vector layer with polygons.


The supervised classification needs a set of raster layers and a vector layer with polygons that define the different classes to create. The identifier of the class is defined in the Class field in the attributes table. If you open the attributes tables, you will see that it looks something like the following:

There are five different classes, each of them represented by a feature and with a text ID along with a numerical ID. The classification algorithms analyzes the pixels that fall within the polygons of each class and computes statistics for them. Using these statistics assigns a class to each pixel in the image, trying to assign the class that is statistically more similar among the ones defined in the vector layer. The numerical ID is used to identify the class in the resulting raster layer.
There are other ways of performing a supervised classification in QGIS. One of them, which allows more control over the different elements in the process, is to use the QGIS semi-automatic classification plugin.
Other more sophisticated classification methods can be used from the Processing Toolbox menu. They can be found in the Advanced interface of the toolbox, under the Orfeo Toolbox group, as shown in the following screenshot:
