ee.Algorithms.If

בוחר אחד מהקלטות שלו על סמך תנאי, בדומה למבנה if-then-else.

שימושהחזרות
ee.Algorithms.If(condition, trueCase, falseCase)אובייקט
ארגומנטסוגפרטים
conditionאובייקט, ברירת מחדל: nullהתנאי שקובע איזו תוצאה תוחזר. אם הערך לא בוליאני, הוא יפורש כבוליאני לפי הכללים הבאים:
  • מספרים ששווים ל-0 או ל-NaN הם false.
  • מחרוזות ריקות, רשימות ומילונים הם false.
  • הערך Null הוא False.
  • כל השאר נכון.
trueCaseאובייקט, ברירת מחדל: nullהתוצאה שמוחזרת אם התנאי מתקיים.
falseCaseאובייקט, ברירת מחדל: nullהתוצאה שמוחזרת אם התנאי לא מתקיים.

דוגמאות

עורך הקוד (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

מידע על Python API ועל שימוש ב-geemap לפיתוח אינטראקטיבי מופיע בדף Python Environment.

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