Following the examples in the QGIS documentation I am able to classify a raster using the raster calculator, e.g. based on the aspect derived from a DEM:
((aspect@1 > 270) AND (aspect@1 <= 90)) * 1 + ((aspect@1 > 90) AND (aspect@1 <= 270)) * 2
This will classify all slightly northward facing slopes as 1
and all facing southward as 2
.
But when I try to mask/take into account areas with little to no slope (less than 3 degrees), the classification wont work properly – not all areas with a slope less than 3 degrees will be classified accordingly.
(((aspect@1 > 270) AND (aspect@1 <= 90)) * 1 + ((aspect@1 > 90) AND (aspect@1 <= 270)) * 2) + (slope@1 <= 3) * 3
Where am I going wrong? I can't see any logic why some areas are classified as 3
, and others, which should be, aren't. At least there's no wrong classification of areas above 3 degree slope as 3
.
Exemplary images of my problem:
Best Answer
In order not to make mistakes classifying in the raster calculator, it is best to explicitly write the conditions in all terms, taking into account that each term is mutually exclusive from the others :
Then, knowing that
True = 1
and thatFalse = 0
, we can begin to simplify the algebra of sets:Until you get to the simple form:
The algebraic operation is not intuitive, but it is useful to understand how it works.