ee.Algorithms.If

Seleziona uno dei suoi input in base a una condizione, in modo simile a un costrutto if-then-else.

UtilizzoResi
ee.Algorithms.If(condition, trueCase, falseCase)Oggetto
ArgomentoTipoDettagli
conditionOggetto, valore predefinito: nullLa condizione che determina quale risultato viene restituito. Se non è un valore booleano, viene interpretato come tale in base alle seguenti regole:
  • I numeri uguali a 0 o NaN sono false.
  • Stringhe, elenchi e dizionari vuoti sono falsi.
  • Null è false.
  • Tutto il resto è vero.
trueCaseOggetto, valore predefinito: nullIl risultato da restituire se la condizione è true.
falseCaseOggetto, valore predefinito: nullIl risultato da restituire se la condizione è falsa.

Esempi

Editor di codice (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));

Configurazione di Python

Consulta la pagina Ambiente Python per informazioni sull'API Python e sull'utilizzo di geemap per lo sviluppo interattivo.

import ee
import geemap.core as geemap

Colab (Python)

# The string "*false*"
print(ee.Algorithms.If(False, '*true*', '*false*').getInfo())

# The string "*true*"
print(ee.Algorithms.If(True, '*true*', '*false*').getInfo())

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