6

I'm trying to compare two rasters, and create an output based on a formula like:

if raster1 > 10 or raster2 < 20 then raster3 = 30

How can I specify the OR in the raster calculator's CON statement?

The pages Building expressions in Raster Calculator and Conditional evaluation with CON don't help, and "or" seems to be keyword that Google ignores....

1
  • please statement with me erosion map with mpeciac method thanks Commented May 30, 2017 at 13:03

2 Answers 2

5

For building complex statements, you can get more information here

It is important to know the precedence level of the operators. For example, Boolean (~, &, ^,|) operators have a higher precedence level than Relational (<, <=, >, >=, ==, !=) operators, which has an impact on how you construct your expressions. For more information on operator precedence, see the second table on this page

I copied the above-mentioned table at the end of my post, it goes from lowest to highest precedence(note that it is not the same precedence in C++). Operators with the highest precedence are grouped together first, this is why you need parentheses if you want to force evaluating ">" before "|".

Without parentheses, your parser is trying to read

Con(("Raster1" > (10 | "Raster2") < 20),30)

<, <=, >, >=, ==, != (Less Than, Less Than Equal, Greater Than, Greater Than Equal, Equal To, Not Equal)

| (Boolean Or)

^ (Boolean XOr)

& (Boolean And)

<<, >> (Bitwise Left Shift, Bitwise Right Shift)

+, - (Addition, Subtraction)

*, /, //, % (Multiplication, Division, Integer Division, Modulo)

+, -, ~ (Unary Plus, Negate, Boolean Not)

** (Power)

1
  • Thanks for the clarification on why the parentheses are required - that makes a lot of sense now Commented Sep 25, 2014 at 9:15
1

I've just spent ages on this, so to spare everyone else the trouble here's the cheat sheet:

It appears you need to surround each individual comparison in brackets, and use the | symbol as the "or":

Con(("Raster1" > 10) | ("Raster2" < 20),30)

(Please edit this answer, and post a link to the documentation which mentions this, if it exists)

2
  • 2
    resources.arcgis.com/en/help/main/10.1/index.html#//… it's in the table. The brackets around the statements aren't just nice they're absolutely essential - did my head in on that for a few minutes! Commented Sep 25, 2014 at 2:21
  • @MichaelMiles-Stimson yeah it's weird since it works without the brackets if you use a simple expression. Googling "boolean or" finds that page you linked, too. Commented Sep 25, 2014 at 2:23

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.