7

I want to process a raster with values 0-16. I want to set all values between 1 and 15 as 1, a value of 16 as 0 and cells with a value of 0 as 0.

How do I maintain a cell value of 0?

I have tried the following:

("raster_name@1" !=0 AND "raster_name@1" <= 15*1)+("raster_name@1" = 16*0)

Results in: Values of 16 as 0, values 1-15 as 1, values 0 also = 1

I also tried:

("raster_name@1" !=0 AND "raster_name@1" <= 15*1)+("raster_name@1" 16*0)+("raster_name@1" = 0*0)

Results in: Values of 16 as 0, values 1-15 as 1, values 0 = 2

Please, can you explain how to retain cells with a 0 value as 0?

  • 1
    Hi, and welcome to GIS.SE. Have you simply tried "raster_name@1" !=0 AND "raster_name@1" <= 15? – ArMoraer Mar 13 '18 at 14:41
  • What ArMoraer proposes, works. I added some - maybe unnecessary - stuff and came up with ("raster_name@1" != 0 AND "raster_name@1" < 16) = 1 AND ("raster_name@1" = 0 AND "raster_name@1" > 15) = 0 – Erik Mar 13 '18 at 14:53
  • @ArMoraer, the simple one works, I was over complicating it! Thank you! :) – Christine Mar 13 '18 at 15:00
8

Simply write "raster_name@1" != 0 AND "raster_name@1" <= 15 in order to set all values between 1 and 15 to 1, and everything else to 0.

  • One could also >= 1 or > 0. – jpmc26 Mar 13 '18 at 17:02

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.