Posted by & filed under QGIS.

The Raster Calculator in QGIS allows you to run any expression on a raster or collection of rasters. While it is definitely useful, exactly how to phrase your expression in order to reclassify a raster is not always clear. Let’s say you have a raster with values between 0 and 255, and you want everything between 100 and 150 set to 1 (and the rest to 0). If you’re like me, your first instinct would be to write an expression that looks somewhat like this:

((raster@1 > 100) AND (raster@1 < 150)) = 1 else = 0

However, this does not work. In fact, in my case it returned the opposite of what I wanted (and without the “else …”, it returned nothing at all). Instead, the proper way to do it turns out to be this:

((raster@1 < 100) OR (raster@1 > 150)) = 0

Whatever is not set to zero by this statement will be set to 1 instead.

2 Responses to “Simple binary raster reclassification in QGIS”

  1. viridio

    I need to reclassify a raster in ranges, how would be the expression? I need this:

    range value
    0-3 1
    3-10 2
    10-25 3
    25-50 4

    Appreciate any help. Keep up the good work.

    • Tim Sutton

      Hi

      I think the short answer is that you can’t do this yet with the raster calculator built into QGIS. You can probably do it using the mapcalc tool in the GRASS plugin easily enough.

      Regards

      Tim

Leave a Reply

You must be logged in to post a comment.