ee.Dictionary.rename

Đổi tên các phần tử trong từ điển.

Cách sử dụngGiá trị trả về
Dictionary.rename(from, to, overwrite)Từ điển
Đối sốLoạiThông tin chi tiết
this: dictionaryTừ điển
fromDanh sáchDanh sách các khoá cần đổi tên.
toDanh sáchDanh sách tên mới cho các khoá có trong thông số "from". Phải có cùng độ dài với danh sách "from".
overwriteBoolean, mặc định: falseCho phép ghi đè các tài sản hiện có có cùng tên.

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

// Define from-to key name lists for selected keys.
var from = ['B2', 'B3'];
var to = ['Band_2', 'Band_3'];
print('Renamed keys', dict.rename(from, to));

print('Overwrite existing key names, e.g. B3 becomes B1',
      dict.rename({from: ['B3'], to: ['B1'], overwrite: true}));

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

# Define from-to key name lists for selected keys.
frm = ['B2', 'B3']
to = ['Band_2', 'Band_3']
print('Renamed keys:', dic.rename(frm, to).getInfo())

dic_overwrite = dic.rename(**{'from': ['B3'], 'to': ['B1'], 'overwrite': True})
print('Overwrite existing key names, e.g. B3 becomes B1:',
      dic_overwrite.getInfo())