Working with operators in Map Algebra

In Map Algebra, operators apply a mathematical operation on input rasters and numbers.

Operators are generally placed between two inputs (operands) to perform a mathematical operation (for example, outVar = 3 + 7). In Map Algebra, operands can be rasters or numbers. To use an operator with a raster, the raster must be a Raster object.

The table below provides a quick reference indicating how current Map Algebra operators have been implemented in relation to Python operators and previous 9.x Map Algebra operators.

Operation

Python operator

Map Algebra operator

9.x Map Algebra operator *

Spatial Analyst GP tool

Arithmetic

Addition

+

+

+

Plus

Division

/

/

/, div

Divide

Integer Division

//

//

N/A

N/A

Modulo

%

%

Mod

Mod

Multiplication

*

*

*

Times

Power

**

**

N/A

Power

Subtraction

-

-

-

Minus

Unary Minus

-

-

-

Negate

Unary Plus

+

+

N/A

N/A

Boolean

Boolean And

N/A

&

&, and

Boolean And

Boolean Complement

N/A

~

^, not

Boolean Not

Boolean Exclusive Or

N/A

^

!, xor

Boolean XOr

Boolean Or

N/A

|

|, or

Boolean Or

Relational

Equal To

==

==

==, eq

Equal To

Greater Than

>

>

>, gt

Greater Than

Greater Than And Equal To

>=

>=

>=, ge

Greater Than Equal

Less Than

<

<

<, lt

Less Than

Less Than And Equal To

<=

<=

<=, le

Less Than Equal

Not Equal To

!=

!=

^=, <>, ne

Not Equal

Bitwise

Bitwise And

&

N/A

&&

Bitwise And

Bitwise Complement

~

N/A

^^

Bitwise Not

Bitwise Exclusive Or

^

N/A

!!

Bitwise XOr

Bitwise Left Shift

<<

<<

<<

Bitwise Left Shift

Bitwise Or

|

N/A

||

Bitwise Or

Bitwise Right Shift

>>

>>

>>

Bitwise Right Shift

* 9.x Map Algebra operator refers to the operator symbol you would have used in the Single Output Map Algebra tool or the Raster Calculator in the Spatial Analyst toolbar in ArcGIS versions 9.x and prior.

Operator rules

TipTip:

Spaces are not necessary between operators but are recommended for readability.

Tools and operators can be nested to create complex statements.

Operator precedence

The precedence value determines the order in which operators are executed. The operator with the higher precedence will be processed first. If two operators have the same precedence value, then they will be processed in a left to right order in an expression.

You can use parentheses to override the precedence priority, with the operation in the deepest parentheses being processed first no matter what operator is specified.

The following table lists all the Map Algebra operators in order from lowest precedence to highest precedence. Each of the operators that are listed in the same row have the same precedence.

Related Topics


6/28/2013