ee.Dictionary.get
Extracts a named value from a dictionary. If the dictionary does not contain the given key, then defaultValue is returned, unless it is null.
Usage | Returns |
---|
Dictionary.get(key, defaultValue) | Object |
Argument | Type | Details |
---|
this: dictionary | Dictionary | |
key | String | |
defaultValue | Object, default: null | |
Examples
// A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
var dict = ee.Dictionary({
B1: 182,
B2: 219,
B3: 443
});
print('Value for "B1" key', dict.get('B1'));
// Set a default value for the case where the key does not exist.
print('Value for nonexistent "Band_1" key',
dict.get({key: 'Band_1', defaultValue: -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
# A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
dic = ee.Dictionary({
'B1': 182,
'B2': 219,
'B3': 443
})
print('Value for "B1" key:', dic.get('B1').getInfo())
# Set a default value for the case where the key does not exist.
print('Value for nonexistent "Band_1" key:',
dic.get(**{'key': 'Band_1', 'defaultValue': -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 2024-07-13 UTC.
[null,null,["Last updated 2024-07-13 UTC."],[[["The `Dictionary.get()` method extracts the value associated with a specified key from a dictionary."],["If the key is not found in the dictionary, the method returns a user-defined default value."],["A null default value can be specified, resulting in a null return if the key is absent."],["This function is applicable across different Earth Engine environments, including JavaScript, Python, and Colab."]]],["The `get` method retrieves a value from a dictionary using a specified key. If the key exists, its corresponding value is returned. If the key is absent, a `defaultValue` is returned. The `defaultValue` can be customized, defaulting to `null` if not provided. Usage examples demonstrate retrieving existing values and setting default values for nonexistent keys, in both JavaScript and Python. The `get` method is applicable to dictionary objects.\n"]]