ee.Dictionary.rename
Rename elements in a dictionary.
Usage | Returns | Dictionary.rename(from, to, overwrite) | Dictionary |
Argument | Type | Details | this: dictionary | Dictionary | |
from | List | A list of keys to be renamed. |
to | List | A list of the new names for the keys listed in the 'from' parameter. Must have the same length as the 'from' list. |
overwrite | Boolean, default: false | Allow overwriting existing properties with the same name. |
Examples
Code Editor (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}));
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
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())
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-13 UTC.
[null,null,["Last updated 2024-07-13 UTC."],[[["The `rename()` method allows you to rename keys within an Earth Engine Dictionary object."],["It takes two required arguments: `from` (a list of keys to rename) and `to` (a list of new names corresponding to the `from` list)."],["The optional `overwrite` argument, set to `false` by default, controls whether existing keys can be overwritten during renaming."]]],[]]