ee.Algorithms.If

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

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

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

דוגמאות

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

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

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