ee.Dictionary.toImage

根据字典中的值创建常量映像。图像的波段会根据 names 实参进行排序和命名。如果未指定任何名称,则按字母数字顺序对频段进行排序。

用法返回
Dictionary.toImage(names)图片
参数类型详细信息
此:dictionary字典要转换的字典。
names列表,默认值: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
});

var selectedKeysImg = dict.toImage(['B1', 'B2']);
print('Selected keys image band names', selectedKeysImg.bandNames());

var allKeysImg = dict.toImage();
print('All keys image band names', allKeysImg.bandNames());

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

selected_keys_img = dic.toImage(['B1', 'B2'])
print('Selected keys image band names:',
      selected_keys_img.bandNames().getInfo())

all_keys_img = dic.toImage()
print('All keys image band names:', all_keys_img.bandNames().getInfo())