ee.Algorithms.If

根據條件選取其中一個輸入內容,類似於 if-then-else 建構。

用量傳回
ee.Algorithms.If(condition, trueCase, falseCase)物件
引數類型詳細資料
condition物件,預設值:null決定傳回哪個結果的條件。如果這不是布林值,系統會根據下列規則將其解讀為布林值:
  • 等於 0 或 NaN 的數字為 false。
  • 空字串、清單和字典為 false。
  • 空值為 false。
  • 其他情況皆屬實。
trueCase物件,預設值:null如果條件為 true,要傳回的結果。
falseCase物件,預設值:null如果條件為 False,則傳回的結果。

範例

程式碼編輯器 (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*"
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())