2

I need to create a layer that contains all values between 6 and 9. <= 6 >9. All other values should be 0. How can I do this with using the raster calculator?

3

You could use something like the following expression which outputs a raster containing the values 6 and 9 (everything else is set to 0):

("raster@1" >= 6 AND "raster@1" <= 9) * "raster@1"

Edit:

If you want to output a raster only containing boolean values (1 for true; 0 for false), you could just use the expression inside the parentheses (credit to @mgri):

"raster@1" >= 6 AND "raster@1" <= 9
| improve this answer | |
  • 1
    Beaten by seconds... However, it should also work if you only use the expression between parentheses. – mgri May 3 '17 at 10:14
  • @mgri - Sorry :). For me, using only the expression inside the parentheses outputs a raster of only 1 and 0 (1 being True, 0 being False). Does it work for you? – Joseph May 3 '17 at 10:18
  • I get the same result as you and I didn't notice that the OP asked to maintain the values instead of assigning 1 to them. So, you are definitely right! :) – mgri May 3 '17 at 10:28
  • @mgri - Don't think the OP explicitly mentioned maintaining the values, I just assumed from the context so you could also be right ;) – Joseph May 3 '17 at 10:30
  • Thanks. It works great withe maintaining the values but how can I put the values between 6 and 9 to one and all others to 0? – Andreas May 3 '17 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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