ee.Algorithms.If

เลือกอินพุตรายการใดรายการหนึ่งตามเงื่อนไข ซึ่งคล้ายกับโครงสร้าง if-then-else

การใช้งานการคืนสินค้า
ee.Algorithms.If(condition, trueCase, falseCase)วัตถุ
อาร์กิวเมนต์ประเภทรายละเอียด
conditionออบเจ็กต์ ค่าเริ่มต้น: nullเงื่อนไขที่กำหนดผลลัพธ์ที่จะแสดง หากไม่ใช่บูลีน ระบบจะตีความเป็นบูลีนตามกฎต่อไปนี้
  • ตัวเลขที่เท่ากับ 0 หรือ NaN จะเป็นเท็จ
  • สตริง รายการ และพจนานุกรมที่ว่างเปล่าเป็นเท็จ
  • Null เป็นเท็จ
  • ส่วนที่เหลือเป็นความจริง
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

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