I have tried this several different ways and get lots of NaN.

I need to specify that in my raster 'test1', I want a certain set of values to equal 1 and the rest to equal zero. For instance, I want 1, 42, and 102 to equal 1 and the rest to equal zero.

I have tried:

"test1@1" = 1 OR "test1@1" = 42 OR "test1@1" = 102

as well a few other options.

Unfortunately, there seem to be no existing syntax guidelines for the raster calculator (if you know of some, please send me a link).

How do I make this work?

  • Have you tried putting your logical statements in brackets (e.g. "("test1@1= 1”) OR..."). Additionally, you could also try just multiplying your statements by 1 and adding them instead of using logical OR. Commented Feb 1, 2016 at 6:24
  • Yes, I have tried all of those options. All result in a new layer with all values = NaN. Commented Feb 2, 2016 at 14:41

1 Answer 1


I have tried an equivalent syntax for my raster (200 x 200 and random values between 1 and 102):

"random_raster@1" = 1 OR "random_raster@1" = 42 OR "random_raster@1" = 102

and it works; as it could be see at the next image ('Zoom In' in a reduced area of output raster out3.tif to verify, with 'Value Tool' plugin, the values obtained).

enter image description here

In your case, it should work too.

  • The created raster on mine only has undefined values, so nothing shows up. It might be an issue of versions. I have the latest version (Wien) and it looks like you are running Lyon. I can't find any bug reports of this particular issue online though. Commented Feb 2, 2016 at 14:34
  • I should also clarify that having just the first one alone "test1@1" = 1 works just fine. Commented Feb 2, 2016 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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