ee.Algorithms.If

Selects one of its inputs based on a condition, similar to an if-then-else construct.

UsageReturns
ee.Algorithms.If(condition, trueCase, falseCase)Object
ArgumentTypeDetails
conditionObject, default: null

The condition that determines which result is returned. If this is not a boolean, it is interpreted as a boolean by the following rules:

  - Numbers that are equal to 0 or a NaN are false.

  - Empty strings, lists and dictionaries are false.

  - Null is false.

  - Everything else is true.

trueCaseObject, default: null

The result to return if the condition is true.

falseCaseObject, default: null

The result to return if the condition is false.

Examples

JavaScript

print(ee.Algorithms.If(false, '*true*', '*false*'));  // The string "*false*"
print(ee.Algorithms.If(true, '*true*', '*false*'));  // The string "*true*"

// Consider using remap rather than If for tasks like numbers for classes.
print(ee.Algorithms.If(ee.String('Tree').compareTo('Tree'), 0, 1));
print(ee.Algorithms.If(ee.String('NotTree').compareTo('Tree'), 0, 1));

Python

# Your example goes here!