Map and Table Calculation

IFF( ) function

If a is true, then return b, else return c.

Syntax

IFF(a, b, c)

Input

a is the test condition: a boolean expression containing at least one map name or one column name.
b, c an expression containing at least one map name or one column name, or simply a value, class name, ID, etc.

Output

IFF returns: if a=true, b is returned;
if a=false, c is returned;
if a=undefined, undefined is returned.
Domain: system domain Value;

the class/ID domain returned by c;

if c returns a string or undefined value, the class/ID domain returned by b;

if both b and c return a string, no default output domain.

Notes:

Tip:

When the definition symbol = is used, a dependent output map or dependent output column is created; when the assignment symbol := is used, the dependency link is immediately broken after the output map/column has been calculated.

Usable in

MapCalc, TabCalc

Examples

MapCalc example using a value map:

OutMap = IFF(DEM > 20, 50, 10)

 

DEM

OutMap

45 40 30
? 15 10
10 15 30
50 50 50
? 10 10
10 10 50

If a pixel in a Digital Elevation Model (map DEM) has a value greater than 20, then assign 50 to this pixel in output map OutMap, else assign 10.

MapCalc example using a class map:

OutMap = IFF(Landuse="Coffee", 50, 10)

 

Landuse

OutMap

C C G
F F ?
G C C
50 50 10
10 10 ?
10 50 50

If in map Landuse a pixel belongs to class Coffee, then assign 50 to this pixel in output map OutMap, else assign 10.

Note:

Read in the Landuse map for C=Coffee, G=Grassland, and for F=Forest.

MapCalc example using a conditional IFF and a logical AND:

OutMap1 = IFF ((Landuse="Coffee") AND (DEM>=20), 50, 10)

OutMap2 = IFF ((Landuse="Coffee") AND (INRANGE(DEM,5,25), "True", "False")

The previous formula as above can also be written as:

OutMap2 = (Landuse="Coffee") AND (INRANGE(DEM,5,25)

 

Landuse

DEM

OutMap1

OutMap2

C C G
F F ?
G C C
45 40 30
? 15 10
10 15 30
50 50 10
10 10 10
10 10 50
False False False
False False ?
False True False

 

Note:

Read in the Landuse map for C=Coffee, G=Grassland, and for F=Forest.

TabCalc examples:

Suitability1 = IFF (SoilDepth > 0.20, "Suitable", "Not Suitable")

Suitability2 = IFF ((SoilDepth > 0.20) AND (Phosphate > 30), True, False)

The second formula can also be written as:

Suitability2 = (SoilDepth > 0.20) AND (Phosphate > 30)

 

SoilLevel=IFF(SoilDepth<0.20,1,IFF(SoilDepth<0.40,2,IFF(SoilDepth<0.80,3,IFF(SoilDepth<1.60,4,0))))

 

SoilDepth

Phosphate

Suitability1

Suitability2

SoilLevel

0.15

8

Not Suitable

False

1

0.45

34

Suitable

True

3

0.90

10

Suitable

False

4

0.20

25

Not Suitable

False

2

 

See also:

IFUNDEF
ISUNDEF
IFNOTUNDEF
Map and Table Calculation : Assigning undefined values
How to calculate with undefineds in maps and tables
Map and Table Calculation : Merging domains (workaround)