ee.Dictionary.get

从字典中提取指定名称的值。如果字典不包含给定的键,则返回 defaultValue,除非 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())