Earth Engine 即將推出
非商業用途的配額級別,以便保護共用運算資源,並確保所有使用者都能享有穩固效能。所有非商業用途的專案都必須在
2026 年 4 月 27 日前選取配額級別,否則屆時會預設為「社群」級別。在
2026 年 4 月 27 日,所有專案 (無論選取級別的日期為何) 的級別配額都會生效。
瞭解詳情。
ee.Algorithms.If
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
根據條件選取其中一個輸入內容,類似於 if-then-else 建構。
| 用量 | 傳回 |
|---|
ee.Algorithms.If(condition, trueCase, falseCase) | 物件 |
| 引數 | 類型 | 詳細資料 |
|---|
condition | Object,預設值:null | 決定傳回哪個結果的條件。如果不是布林值,系統會依下列規則解讀為布林值: - 等於 0 或 NaN 的數字為 false。
- 空字串、清單和字典為 False。
- 空值為 false。
- 其他情況皆屬實。
|
trueCase | Object,預設值:null | 如果條件為 true,要傳回的結果。 |
falseCase | Object,預設值: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*"
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))
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2026-04-20 (世界標準時間)。
[null,null,["上次更新時間:2026-04-20 (世界標準時間)。"],[],["The `ee.Algorithms.If` function selects one of two inputs based on a condition. It takes a `condition`, `trueCase`, and `falseCase`. If the `condition` is true, it returns `trueCase`; otherwise, it returns `falseCase`. Non-boolean conditions are evaluated: 0, NaN, empty collections, and null are false; everything else is true. Examples show using boolean values and string comparisons as conditions to determine the returned value. The `remap` function is suggested as an alternative for class-numbering tasks.\n"]]