ee.Dictionary.get

ดึงค่าที่มีชื่อจากพจนานุกรม หากพจนานุกรมไม่มีคีย์ที่ระบุ ระบบจะแสดงผล defaultValue เว้นแต่จะเป็น null

การใช้งานการคืนสินค้า
Dictionary.get(key, defaultValue)วัตถุ
อาร์กิวเมนต์ประเภทรายละเอียด
ดังนี้ dictionaryพจนานุกรม
keyสตริง
defaultValueออบเจ็กต์ ค่าเริ่มต้น: null

ตัวอย่าง

โปรแกรมแก้ไขโค้ด (JavaScript)

// A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
var dict = ee.Dictionary({
  B1: 182,
  B2: 219,
  B3: 443
});

print('Value for "B1" key', dict.get('B1'));

// Set a default value for the case where the key does not exist.
print('Value for nonexistent "Band_1" key',
      dict.get({key: 'Band_1', defaultValue: -9999}));

การตั้งค่า Python

ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap เพื่อการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

import ee
import geemap.core as geemap

Colab (Python)

# A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
dic = ee.Dictionary({
    'B1': 182,
    'B2': 219,
    'B3': 443
})

print('Value for "B1" key:', dic.get('B1').getInfo())

# Set a default value for the case where the key does not exist.
print('Value for nonexistent "Band_1" key:',
      dic.get(**{'key': 'Band_1', 'defaultValue': -9999}).getInfo())