[GIS] QGIS 2.18 Raster Calculator not working properly

qgisraster-calculator

enter image description hereI've been trying to make rasters of the area within a certain elevation band of some elevation rasters I have. Simple enough. But when I do the raster calculation, the output is not what it should be (like in a raster with values 1000-2000 if I do "raster">1500 there should be some some areas >1500 that are one color and other areas that are another color, but the resultant raster is one solid block of a single color)

I attached some pictures of what I did and the result to hopefully show the problem better. As you can see, the resultant vector should be a mix of black and white, because some of the original raster is <1525, but it is not

I'm just trying to figure out how to get these kinds of calculations to work


This was my result

nan is from divide by zero, right? Why would this pop up here? I'm not even dividing anything

enter image description here

Best Answer

Although I cannot see the raster value of 3110 maybe due to the min and max values in the raster statistics are not set properly, but anyway you can achieve what you want by applying the following expression:

("dblbnd@1" > 1525  AND  "dblbnd@1" < 3110)  *  "dblbnd@1"

Please note that the values below or equal to 1525 and above and equal to 3110 will assigned 0 because they don't meet the condition above.

Here is an example to extract the values above 800 and below 2000 from the image below:

enter image description here

Using raster calculator, I wrote the following expression:

("Test@1"  > 800  AND "Test@1" <2000) * "Test@1"

enter image description here

Here is the output:

enter image description here

You can set the zero value to null using r.null tool in GRASS and replace 0 with -9999 asfollows:

enter image description here

The final output raster will have values ranges from 801 to 1999 as extracted from raster calculator:

enter image description here

Related Question