Sunday 21 January 2018

QGIS Raster Calculater Syntax


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.




Answer



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:


ifelse((a>b),a,b)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...