Tuesday 21 November 2017

spatial analyst - How to use OR in a CON statement, in the ArcGIS Raster Calculator?


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....



Answer




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)



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...