[GIS] QGIS Raster Calculater Syntax

qgisrasterraster-calculator

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.

Best Answer

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.

Related Question