Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

2 Answers 2

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).

Tim

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

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
1  
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

Your Answer

 
discard

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.