ee.Dictionary.map

将算法映射到字典。该算法应接受 2 个实参,即现有字典中的键及其对应的值,并返回给定键的新值。如果算法返回 null,则会舍弃相应密钥。

用法返回
Dictionary.map(baseAlgorithm)字典
参数类型详细信息
此:dictionary字典
baseAlgorithm算法

示例

代码编辑器 (JavaScript)

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

/**
 * Convert S2 surface reflectance units to native scale.
 */
function scale(key, value) {
  return ee.Number(value).divide(1e4);
}

print('S2 surface reflectance in native units', dict.map(scale));

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


def scale(key, value):
  """Convert S2 surface reflectance units to native scale."""
  return ee.Number(value).divide(1e4)

print('S2 surface reflectance in native units:', dic.map(scale).getInfo())