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?

lambertj
  • 3,037
  • 3
  • 18
  • 37
  • 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

1 Answers1

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.

radouxju
  • 49,636
  • 2
  • 71
  • 144
ArMoraer
  • 5,649
  • 2
  • 26
  • 48