Working with operators

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

Operators are generally placed between two inputs to perform a mathematical operation (for example, outVar = 3 + 7). In Map Algebra, operators have been overloaded, allowing operators to be used with Raster objects. To utilize an operator with a raster dataset, the dataset name must be cast as a Raster object, indicating that the Spatial Analyst implementation of the operator should be used.

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

Tools and operators can be nested to create complex statements.

TipTip:

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

Operator precedence

The precedence value determines the order in which operators are executed. The operator with the higher precedence will be processed first. 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 identifies the precedence value defining the priority order for processing each operator.

Map Algebra operator

Description

Precedence

Arithmetic

- (Subtraction)

Subtraction

11

- (Negate)

Unary minus

14

% (Modulo)

Modulus

13

* (Multiplication)

Multiplication

13

/ (Division)

Division

13

// (Integer Division)

Integer divide

13

+ (Addition)

Addition

12

+ (Unary Plus)

Unary plus

14

** (Power)

Power

16

Bitwise

>> (Bitwise Right Shift)

Bitwise right shift

11

<< (Bitwise Left Shift)

Bitwise left shift

11

Boolean

~ (Boolean Not)

Boolean complement

4

& (Boolean And)

Boolean and

3

^ (Boolean XOr)

Boolean exclusive

2

| (Boolean Or)

Boolean or

2

Relational

< (Less Than)

Less than

7

<= (Less Than Equal)

Less than or equal to

7

> (Greater Than)

Greater than

7

>= (Greater Than Equal)

Greater than or equal to

7

== (Equal To)

Equal to

7

!= (Not Equal)

Not equal to

7

Related Topics


Published 6/7/2010