Announcement: All noncommercial projects registered to use Earth Engine before
April 15, 2025 must
verify noncommercial eligibility to maintain Earth Engine access.
ee.Dictionary.rename
Stay organized with collections
Save and categorize content based on your preferences.
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."],[[["\u003cp\u003eThe \u003ccode\u003erename()\u003c/code\u003e method allows you to rename keys within an Earth Engine Dictionary object.\u003c/p\u003e\n"],["\u003cp\u003eIt takes two required arguments: \u003ccode\u003efrom\u003c/code\u003e (a list of keys to rename) and \u003ccode\u003eto\u003c/code\u003e (a list of new names corresponding to the \u003ccode\u003efrom\u003c/code\u003e list).\u003c/p\u003e\n"],["\u003cp\u003eThe optional \u003ccode\u003eoverwrite\u003c/code\u003e argument, set to \u003ccode\u003efalse\u003c/code\u003e by default, controls whether existing keys can be overwritten during renaming.\u003c/p\u003e\n"]]],["The content describes how to rename keys within a dictionary using the `Dictionary.rename()` method. This method takes two lists: `from` (keys to be renamed) and `to` (new key names), which must have the same length. The optional `overwrite` parameter (default: `false`) allows replacing existing keys. The function returns the modified dictionary. Examples in JavaScript and Python showcase renaming specific keys and overwriting existing ones.\n"],null,["# ee.Dictionary.rename\n\nRename elements in a dictionary.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------------------------|------------|\n| Dictionary.rename`(from, to, `*overwrite*`)` | Dictionary |\n\n| Argument | Type | Details |\n|--------------------|-------------------------|--------------------------------------------------------------------------------------------------------------------|\n| this: `dictionary` | Dictionary | |\n| `from` | List | A list of keys to be renamed. |\n| `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. |\n| `overwrite` | Boolean, default: false | Allow overwriting existing properties with the same name. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).\nvar dict = ee.Dictionary({\n B1: 182,\n B2: 219,\n B3: 443\n});\n\n// Define from-to key name lists for selected keys.\nvar from = ['B2', 'B3'];\nvar to = ['Band_2', 'Band_3'];\nprint('Renamed keys', dict.rename(from, to));\n\nprint('Overwrite existing key names, e.g. B3 becomes B1',\n dict.rename({from: ['B3'], to: ['B1'], overwrite: true}));\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).\ndic = ee.Dictionary({\n 'B1': 182,\n 'B2': 219,\n 'B3': 443\n})\n\n# Define from-to key name lists for selected keys.\nfrm = ['B2', 'B3']\nto = ['Band_2', 'Band_3']\nprint('Renamed keys:', dic.rename(frm, to).getInfo())\n\ndic_overwrite = dic.rename(**{'from': ['B3'], 'to': ['B1'], 'overwrite': True})\nprint('Overwrite existing key names, e.g. B3 becomes B1:',\n dic_overwrite.getInfo())\n```"]]