ee.Dictionary.toImage

Tạo hình ảnh hằng số từ các giá trị trong một từ điển. Các dải của hình ảnh được sắp xếp và đặt tên theo đối số tên. Nếu bạn không chỉ định tên, các dải tần sẽ được sắp xếp theo thứ tự chữ và số.

Cách sử dụngGiá trị trả về
Dictionary.toImage(names)Hình ảnh
Đối sốLoạiThông tin chi tiết
this: dictionaryTừ điểnTừ điển cần chuyển đổi.
namesDanh sách, mặc định: nullThứ tự của các dải đầu ra.

Ví dụ

Trình soạn thảo mã (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());

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.

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