I am trying to use the raster calculator in QGIS to combine a number of rasters. I want to calculate a mean, this is easy:

(raster_1@1 + raster_2@1 + raster_3@1) / 3

I then want to create a max. raster - i.e. for each pixel I want to compare raster_1, 2 & 3 and use whichever is the greatest of the three. According to the QGIS documentation I should be able to use the following code (modified from QGIS documentation example):

gt( raster_1@1, raster_2@1, raster_1@1 )

(All cells in raster_1 with value greater than (gt) the appropriate pixels in raster_2 will be replaced with the appropriate pixels from raster_1). I'd then have to repeat this for raster_3.

This doesn't work however as the raster calculator says the expression is invalid. What am I doing wrong? None of the examples of conditional statements provided in the QGIS documentation seem to work. I have tested this with .tif and .sgrd files and the same thing happens. I'm using QGIS 1.8 on a Linux machine. Thanks in advance.

  • There used to be two raster calculators at some point. Are you sure you are using the one covered in the documentation?
    – underdark
    Jan 22, 2013 at 19:48
  • @underdark - yes I'm pretty sure I'm using the right one. I can only see one raster calculator in QGIS 1.8 and the picture of the GUI in the documentation is the same. Most of the commands work just not the conditional statements.
    – Thomas
    Jan 24, 2013 at 15:06
  • I checked the documentation again. There are no conditional statements mentioned.
    – underdark
    Feb 6, 2013 at 16:16

3 Answers 3


I think gt() is a function that is only available in RasterCalc plugin but not in the normal Raster Calculator that is available by default.

But this functionality can still be achieved using logical operators:

(a>b AND a>c) * a + (b>a AND b>c) * b + (c>a AND c>b) * c

Only one of the three terms will evaluate to 1, the others will be zero.


So I managed to get this working in SAGA-GIS. The grid calculator (Modules > Grid > Calculus > Grid Calculator) works fine. I was able to make a raster consisting of the maximum values from all my polygons using the following code:


Refer to my post I think it is better to use the equation that is there (This coming a year later or so!)

Create A Maximum-Value Composite QGIS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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