ประกาศ: โปรเจ็กต์ที่ไม่ใช่เชิงพาณิชย์ทั้งหมดที่ลงทะเบียนเพื่อใช้ Earth Engine ก่อนวันที่
15 เมษายน 2025 ต้อง
ยืนยันการมีสิทธิ์ที่ไม่ใช่เชิงพาณิชย์เพื่อรักษาสิทธิ์เข้าถึง หากคุณไม่ยืนยันภายในวันที่ 26 กันยายน 2025 ระบบอาจระงับสิทธิ์เข้าถึงของคุณ
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())
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[],["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"]]