ee.Algorithms.If

根据条件选择其中一个输入,类似于 if-then-else 结构。

用法返回
ee.Algorithms.If(condition, trueCase, falseCase)对象
参数类型详细信息
condition对象,默认值:null用于确定返回哪个结果的条件。如果此值不是布尔值,则会根据以下规则将其解读为布尔值:
  • 等于 0 或 NaN 的数字为 false。
  • 空字符串、列表和字典为 false。
  • Null 为 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 API 和如何使用 geemap 进行交互式开发,请参阅 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())