Direct Editing of a Raster Using The Semi-Automatic Classification Plugin

This tutorial describes the SCP tool Edit raster that allows for the direct editing of pixel values in a raster. Direct editing is very convenient in case of large rasters, reducing the computational time and easing the process of updating a raster such as land cover classification.
In this tutorial we are going to edit a very large raster, which is the Corine Land Cover referred to year 2006 (but it is available also for 1990, 2000 and 2012). This raster is produced by the European Environment Agency (EEA), and covers the whole European Countries with a spatial resolution of 100m and a very detailed classification system. For more information read this page .

Following the video of this tutorial.

1. Edit Raster Using ROI Polygons

First, download the raster data from this link Corine Land Cover 2006 (Version 17) provided for free by the EEA .
After the download of the Corine Land Cover, extract the archive and load the file g100_06.tif in QGIS. The complete list of raster values corresponding to each land cover class is included in the file clc_legend.xls, which was downloaded along with the raster. For instance, value 1 corresponds to class Continuous urban fabric, value 2 corresponds to class Discontinuous urban fabric, value 23 corresponds to class Broad-leaved forest. We are going to update the classification by photo-interpretation and manual editing.
We can use a Sentinel-2 image acquired in 2016 (provided by the Copernicus Scientific Data Hub) for updating the land cover classification. See Data Download for the details about Sentinel-2 download. Of course, other plugins such as QuickMapServices or OpenStreetMap) can be used for displaying high resolution images.
Now open the tab Band set (for further instructions see Create the Band Set) and set the raster Corine Land Cover as the only input band. This is required for the creation of ROI polygons.

Band set creation
Also, we need to set the raster Corine Land Cover as input for the raster editing. Open the tab edit_raster Edit raster, and set the input raster in Select the input raster input_list (click the button reload for reloading the layer list).

Edit raster input

After loading a recent image in QGIS, zoom to an area where land cover changes occurred, and draw a temporary ROI (for further instructions see Create the ROIs).

Temporary ROI polygon

Now open the SCP Edit Toolbar, which is designed for the manual editing of rasters. There are three input_number values that can be modified according to the value that we want to apply to the raster. Click the button enter beside each of these values, and the raster is updated using the selected constant value for all the pixels intersecting the temporary ROI.
Attention: the input raster is directly edited; it is recommended to create a backup copy of the input raster before using this tool in order to prevent data loss.
Also, the button undo_edit_raster can undo the most recent editing.

Raster updated with the new value

Considering that we are editing a very large raster, the new value is applied almost instantaneously. We can repeat the ROI creation and update the raster values of other areas.
To ease the editing process, we can use conditional expressions with the structure where(condition, true, false). In the Edit raster, check the checkbox checkbox Use expression and enter a conditional expression.
The variable name raster is used for the input raster. For instance, the expression where(raster == 1, 2, raster) will change only the pixels of class 1 intersecting the temporary ROI, while other pixels will be unchanged. Of course we can change the expression according to our needs, always using the variable name raster. For instance the expression where(raster == 2, 1, where(raster == 20, 21, raster)) will change values to 1 for pixel values equal to 2, or change the value to 21 for pixel values equal to 20. If the expression text is green, then the structure of the expression is correct.

Edit with expression

2. Edit Raster Using a Vector file

We can use a vector file in order to change raster values for all the polygons at once. It is possible to select a vector field containing the new values that will be applied to the raster.
Add a vector file to the QGIS project (for instance download this shapefile ). Open the tab edit_raster Edit raster, check the checkbox checkbox Edit values using a vector and select the vector layer (click the button reload for reloading the layer list). Also, check the checkbox checkbox Use the value field of the vector and select the attribute field containing the values to be applied to the raster (in this example the field Class).

Vector input

Now click the button run and all the changes will be applied to the raster according to polygon values.
Attention: the input raster is directly edited; it is recommended to create a backup copy of the input raster before using this tool in order to prevent data loss.
This method is very rapid, especially if vector polygons have a small area (the larger are the polygons, the longer is the process).

For any comment or question, join the Facebook group and the Google+ Community about the Semi-Automatic Classification Plugin.

Newer posts Older posts