ee.Algorithms.If

  • The ee.Algorithms.If function selects one of its inputs based on a condition, similar to an if-then-else construct.

  • It takes three arguments: condition , trueCase , and falseCase .

  • The condition argument determines which result is returned, and is interpreted as a boolean with specific rules for non-boolean types.

  • The function returns the trueCase object if the condition is true and the falseCase object if the condition is false.

Selects one of its inputs based on a condition, similar to an if-then-else construct.
Usage Returns
ee.Algorithms.If( condition , trueCase , falseCase ) Object
Argument
Type
Details
condition
Object, 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.
trueCase
Object, default: null
The result to return if the condition is true.
falseCase
Object, default: null
The result to return if the condition is false.

Examples

Code Editor (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 setup

See the Python Environment page for information on the Python API and using geemap for interactive development.

 import 
  
 ee 
 import 
  
 geemap.core 
  
 as 
  
 geemap 

Colab (Python)

 # The string "*false*" 
 display 
 ( 
 ee 
 . 
 Algorithms 
 . 
 If 
 ( 
 False 
 , 
 '*true*' 
 , 
 '*false*' 
 )) 
 # The string "*true*" 
 display 
 ( 
 ee 
 . 
 Algorithms 
 . 
 If 
 ( 
 True 
 , 
 '*true*' 
 , 
 '*false*' 
 )) 
 # Consider using remap rather than If for tasks like numbers for classes. 
 display 
 ( 
 ee 
 . 
 Algorithms 
 . 
 If 
 ( 
 ee 
 . 
 String 
 ( 
 'Tree' 
 ) 
 . 
 compareTo 
 ( 
 'Tree' 
 ), 
 0 
 , 
 1 
 )) 
 display 
 ( 
 ee 
 . 
 Algorithms 
 . 
 If 
 ( 
 ee 
 . 
 String 
 ( 
 'NotTree' 
 ) 
 . 
 compareTo 
 ( 
 'Tree' 
 ), 
 0 
 , 
 1 
 )) 
Design a Mobile Site
View Site in Mobile | Classic
Share by: