ee.Dictionary

构造新的字典。

用法返回
ee.Dictionary(dict)字典
参数类型详细信息
dictComputedObject|Object,可选要转换为字典的对象。此构造函数接受以下类型:1) 另一个字典。2) 键值对列表。3) null 或无实参(生成空字典)

示例

代码编辑器 (JavaScript)

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

// A list of key/value pairs (from previous dictionary).
var list = [
  'B1', 182,
  'B2', 219,
  'B3', 443
];
print('ee.Dictionary from list input', ee.Dictionary(list));

// To create an ee.Dictionary from two corresponding lists of keys and values,
// use the ee.Dictionary.fromLists constructor.
var keys = ['B1', 'B2', 'B3'];
var values = [182, 219, 443];
print('Dictionary from lists of keys and values',
      ee.Dictionary.fromLists(keys, values));

Python 设置

如需了解 Python API 和如何使用 geemap 进行交互式开发,请参阅 Python 环境页面。

import ee
import geemap.core as geemap

Colab (Python)

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

# A list of key/value pairs (from previous dictionary).
lst = [
    'B1', 182,
    'B2', 219,
    'B3', 443
]
print('ee.Dictionary from list input', ee.Dictionary(lst).getInfo())