# Conditionally combine two raster with raster calculator

I can’t figure out how to do this in QGIS. I tried gdal and SAGA raster calculator in QGIS. Here is the situation: I have two raster for the same area in the same projection with the same extent and the same resolution.

Raster A (has integer values from 1 to 5)

Raster B (has values from 1 to 7)

The calculation should do the following: if a cell in raster B is >= 3, make the cell for raster A + 1. So the result should be the whole raster A, but cell values in raster A where raster B is bigger than 3 should be +1. My formula so far (for GDAL):

``````((A*(A>=3))+(B>=3))+(A*(A<3))
``````

But the result is missing all values lower then 3. Anyone any suggestions?

• is this along the lines of what you're looking for?gis.stackexchange.com/questions/141305/… – Zipper1365 Feb 2 '18 at 16:28
• Not tested but maybe something like: `(("RasterB@1" >= 3) * ("RasterA@1" + 1)) + (("RasterB@1" < 3) * "RasterA@1")` – Joseph Feb 2 '18 at 16:35

As to the SAGA Raster calculator (`QGIS Processing Toolbox | SAGA | Raster calculus | Raster calculator`).
``````ifelse(or(b > 3,  b = 3), a + 1, a)
A catch is that `b >= 3` becomes `OR(b>3, b=3)`. `OR(x,y)` returns true (1), if at least one of both x, y is true.