Announcement: All noncommercial projects registered to use Earth Engine before
April 15, 2025 must
verify noncommercial eligibility to maintain Earth Engine access.
ee.Dictionary.set
Stay organized with collections
Save and categorize content based on your preferences.
Set a value in a dictionary.
Usage | Returns | Dictionary.set(key, value) | Dictionary |
Argument | Type | Details | this: dictionary | Dictionary | |
key | String | |
value | Object | |
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
});
print('Set value for B3 key as -9999', dict.set('B3', -9999));
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
})
print('Set value for B3 key as -9999:', dic.set('B3', -9999).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 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eDictionary.set\u003c/code\u003e method is used to assign a new value to a specified key within an existing Earth Engine dictionary.\u003c/p\u003e\n"],["\u003cp\u003eIt accepts the dictionary, the key to be updated, and the new value as arguments.\u003c/p\u003e\n"],["\u003cp\u003eThe method returns a new dictionary with the updated key-value pair, leaving the original dictionary unchanged.\u003c/p\u003e\n"],["\u003cp\u003eThis functionality is useful for modifying data within Earth Engine dictionaries, like those containing image band values or other geospatial information.\u003c/p\u003e\n"]]],["The `Dictionary.set(key, value)` method modifies a dictionary by assigning a new value to a specified key. It takes a dictionary, a string `key`, and an `object` value as arguments, and returns the modified dictionary. The examples demonstrate setting the value of the 'B3' key to -9999 within dictionaries, using both JavaScript and Python. The key should be a String, and the value can be any object.\n"],null,["# ee.Dictionary.set\n\nSet a value in a dictionary.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|------------------------------|------------|\n| Dictionary.set`(key, value)` | Dictionary |\n\n| Argument | Type | Details |\n|--------------------|------------|---------|\n| this: `dictionary` | Dictionary | |\n| `key` | String | |\n| `value` | Object | |\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\nprint('Set value for B3 key as -9999', dict.set('B3', -9999));\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\nprint('Set value for B3 key as -9999:', dic.set('B3', -9999).getInfo())\n```"]]