Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using qgis' raster calculator and wanted to make a new raster (oraster) from the values of an input raster (iraster). something like:

if iraster>2 then oraster=1; if iraster >4 then oraster=2; if iraster>6 then oraster=3

all in one operation.

Anyone can help?

share|improve this question

There IS a way to do it in the standard raster calculator ... but it's a kludge ...

(iraster@1 > 2) + (iraster@1 > 4) + (iraster@1 > 6)

This does a comparison test inside each set of parentheses, returning the value '1' for each true comparison, '0' otherwise. Thus, if the raster value of a cell is 5, (iraster@1 >2) returns 1, (iraster@1 > 4) returns 1, and (iraster@1 > 6) returns 0 - thus giving a 'classification' of 1 + 1 + 0 = 2.

Embarrassingly ugly.

share|improve this answer
Do you mind if you could comment the code above? I... fail to see the classes? – nickves Oct 1 '12 at 10:13
Edited with explanation. You could probably make this work for a number of cases, but only returning boolean 0/1 for each test thus your classifications would be integers limited to 0, 1, ... etc. – Simbamangu Oct 1 '12 at 10:29

Currently the build in QGIS raster calculator does not support this. Your best bet is to take the raster into grass and use the grass r.mapcalc (there is also a nice gui for doing this visually in the grass plugins toolbox).


share|improve this answer
(ASTGTM2_N37W026_dem@1<=30)*1 + (ASTGTM2_N37W026_dem@1>30)*2 + (ASTGTM2_N37W026_dem@1>200)*3 it is really a awful syntax to reclassify a raster... I will file a ticket on the QGIS bug tracker, this is a much needed feature (allow use conditional rules). – Giovanni Manghi Apr 11 '13 at 16:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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