0

I have a land use layer which includes 36 different individual classes. Using the raster calculator I have been able to extract 1 of the different classes and make a new layer (landuse=[number of the land use class]). I want to put multiple of these classes together to create one layer e.g. a general forest layer, and tried using the AND function. This however is not working and only acknowledges the first number in the equation (e.g. landuse = 1 AND 2 AND 3) only the land use equivalent to 1 is produced. Does anyone have any ideas?

3
  • 1
    I'm almost sure you mean landuse = 1 OR landuse = 2 OR landuse = 3? Jul 22, 2022 at 11:37
  • Order of precedence is rough on beginners, especially with Boolean operators.. Look at the IN operator (field IN (1,2,3))
    – Vince
    Jul 22, 2022 at 11:41
  • @Vince I'm pretty sure the raster calculator can't handle IN?
    – Erik
    Jul 22, 2022 at 12:11

1 Answer 1

0

Currently your telling the calculator to include everything where landuse equals 1 and where 2 and where 3. Now your old math teacher comes around the corner and asks "Three what? Bananas? Apples? Gas stations?"

After showing him (nicely) out the door you provide more details to your algorithm, e.g. landuse = 1 AND landuse = 2 AND landuse = 3. While this might work out, your programming tutor strolls in and has a nervous breakdown, since basically you're looking for pixels where the landuse is 1, 2 and 3 at the same time.

You hand him a calming tea, seat him on the condo and return to your expression, replacing your ANDs by ORs, while also shortening it a bit: landuse = (1 OR 2 OR 3).

3
  • 2
    And then someone versed in Boolean logic points out that 1 or 2 or 3 resolves to True· and the expression to landuse == 1. This is the place for the IN operator..
    – Vince
    Jul 22, 2022 at 12:07
  • 1
    @Vince I noticed that too, but @Erik's high reputation makes me think the raster calculator interprets landuse = (1 OR 2 OR 3) correctly as the equivalent of SQL's landuse IN (1,2,3). The OP's original query parses as (landuse=1) OR 2 OR 3, effectively confirming that non-zero zero constant are truthy Jul 22, 2022 at 12:16
  • Gotta love non-standard syntax.
    – Vince
    Jul 22, 2022 at 12:21

Your Answer

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

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