ee.Dictionary.toImage

:從字典中的值建立常數映像檔。系統會根據名稱引數排序及命名圖片的波段。如未指定名稱,頻帶會依英數順序排序。

用量傳回
Dictionary.toImage(names)圖片
引數類型詳細資料
這個:dictionary字典要轉換的字典。
names清單,預設值為空值輸出頻帶的順序。

範例

程式碼編輯器 (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 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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