ee.Algorithms.If

Wybiera jedno z wejść na podstawie warunku, podobnie jak konstrukcja if-then-else.

WykorzystanieZwroty
ee.Algorithms.If(condition, trueCase, falseCase)Obiekt
ArgumentTypSzczegóły
conditionObiekt, domyślnie: nullWarunek, który określa, który wynik jest zwracany. Jeśli nie jest to wartość logiczna, jest ona interpretowana jako wartość logiczna zgodnie z tymi regułami:
  • Liczby równe 0 lub NaN są fałszywe.
  • Puste ciągi, listy i słowniki mają wartość fałsz.
  • Wartość null to false.
  • Wszystkie pozostałe informacje są prawdziwe.
trueCaseObiekt, domyślnie: nullWynik do zwrócenia, jeśli warunek jest prawdziwy.
falseCaseObiekt, domyślnie: nullWynik, który ma zostać zwrócony, jeśli warunek jest fałszywy.

Przykłady

Edytor kodu (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));

Konfiguracja Pythona

Informacje o interfejsie Python API i używaniu geemap do interaktywnego programowania znajdziesz na stronie Środowisko Python.

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())