4

How can I write something like the sentence below in QGIS Raster Calculator?

Con(condition, true, false)

or, more precisely

Con(raster1 == x, raster1, raster2)
0
5

As suggested in the official QGIS documentation you can classify raster data by chaining (raster = pixelvalue1) * classvalue using a +. You also may check for disjoint values using !=.

A conditional test basically checks, whether data is equal to a parameter, and then gives an output based on the outcome of that check. The huge difference between the raster calc and the field calc is, that with the raster calc you don't have direct access to if and case when. The raster calc checks, whether a condition is true or not, and returns 1 or 0, and using this you need to emulate the if expression.

Thus, you may run

(raster1 = x) * raster1 + (raster1 != x) * raster2

and if raster 1 equals your value of interest, your output raster gets assigned that value, and where raster 1 isn't equal to that value of interest, the output gets assigned the spatial corresponding value from raster 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.