I have two rasters with values from 1 to 3 each. One is a current habitat suitability prediction and the other a future predicition. I want to visualize the changes. So which cell changed from 1 to 2, from 2 to 1, stayed the same and so on. How can that be accomplished in QGIS?
4 Answers
To complement the (good) answers already provided using simple arithmetic calculations, there are 2 functionality improvements in raster calculator in QGIS 3.22+ that may be helpful:
The first is that there is a new raster calculator function if(condition,thenoption,elseoption)
. So for instance if(future@1>current@1,1,0)
would create a raster with 1's where the future habitat suitability is greater than the current.
Second, there is now support for virtual rasters created with raster calculator that are saved as their formula and recalculated on the fly at display time. Just check the the "Create on-the-fly raster instead of writing layer to disk" checkbox in the raster calculator dialog. Apart from saving disk space, this has the benefit that your virtual "comparison raster" would automatically reflect any later changes written to the source rasters.
Finally, in all versions of QGIS, I'd suggest exploring different band rendering settings in Layer properties / Symbology
once you define it. For instance, using render type "Single band pseudocolor", exact interpolation, and a suitable custom colour palette (possibly with some entries 100% transparent), you can visualize your comparison raster in different ways.
If you want to analyze the change, in addition to visualizing it, then the CrossTabulation tool in the WhiteboxTools QGIS plugin would be able to provide the information you need. It will provide a contingency table that would allow you to determine the area associated with each from-to change in values.
I recently did something similar. I simply use rastercalculator:
(10× @raster1) + @raster2
The changes will be displayed as 11, 12, 13.
You can do it using the raster calculator.
The expression raster2 - raster1 you would get possitive values for those points that evolve and negative when decrease.
This way doesn't difference between a 2 that turn into a 3 and a 1 that do it in a 2. If you need to see a diference between this chases you must multiply each raster by different numbers, for example 5 * raster2 - raster1. (This must be "big numbers", greater than the raster values.)