ee.ImageCollection.toDictionary
Extract properties from a feature as a dictionary.
Usage | Returns |
---|
ImageCollection.toDictionary(properties) | Dictionary |
Argument | Type | Details |
---|
this: element | Element | The feature to extract the property from. |
properties | List, default: null | The list of properties to extract. Defaults to all non-system properties. |
Examples
// A contrived, empty image collection for simple demonstration.
var col = ee.ImageCollection([]);
print('Collection without properties', col);
// Set collection properties using a dictionary.
col = col.set({
project_name: 'biomass_tracking',
project_id: 3,
plot_ids: ee.Array([7, 11, 20])
});
// Set collection properties using a series of key-value pairs.
col = col.set('project_year', 2018,
'rgb_vis', 'false_color');
print('Collection with properties', col);
// Get a dictionary of collection property keys and values.
print('Property keys and values (ee.Dictionary)', col.toDictionary());
// Get the value of a collection property. To use the result of
// ee.ImageCollection.get in further computation, you need to cast it to the
// appropriate class, for example, ee.Number(result) or ee.String(result).
print('Project ID (ambiguous object)', col.get('project_id'));
// Get the value of a string collection property as an ee.String object.
print('Project name (ee.String)', col.getString('project_name'));
// Get the value of a numeric collection property as an ee.Number object.
print('Project year (ee.Number)', col.getNumber('project_year'));
// Get the value of an ee.Array collection property as an ee.Array object.
print('Plot IDs (ee.Array)', col.getArray('plot_ids'));
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 contrived, empty image collection for simple demonstration.
col = ee.ImageCollection([])
print('Collection without properties:', col.getInfo())
# Set collection properties using a dictionary.
col = col.set({
'project_name': 'biomass_tracking',
'project_id': 3,
'plot_ids': ee.Array([7, 11, 20])
})
# Set collection properties using a series of key-value pairs.
col = col.set('project_year', 2018,
'rgb_vis', 'false_color')
print('Collection with properties:', col.getInfo())
# Get a dictionary of collection property keys and values.
print('Property keys and values (ee.Dictionary):', col.toDictionary().getInfo())
# Get the value of a collection property. To use the result of
# ee.ImageCollection.get in further computation, you need to cast it to the
# appropriate class, for example, ee.Number(result) or ee.String(result).
print('Project ID (ambiguous object):', col.get('project_id').getInfo())
# Get the value of a string collection property as an ee.String object.
print('Project name (ee.String):', col.getString('project_name').getInfo())
# Get the value of a numeric collection property as an ee.Number object.
print('Project year (ee.Number):', col.getNumber('project_year').getInfo())
# Get the value of an ee.Array collection property as an ee.Array object.
print('Plot IDs (ee.Array):', col.getArray('plot_ids').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."],[[["`ImageCollection.toDictionary()` extracts properties from an ImageCollection and returns them as an ee.Dictionary object."],["You can specify a list of properties to extract, or by default, it extracts all non-system properties."],["The returned dictionary contains property keys and their corresponding values."],["Further processing might require casting values to specific data types using methods like `getString()`, `getNumber()`, or `getArray()`."]]],["The `ImageCollection.toDictionary()` method extracts properties from a feature, returning them as a dictionary. You must provide a list of `properties`; otherwise, it will default to all non-system properties. Properties can be added to an image collection with `set()`. Individual property values can be retrieved using `get()`, `getString()`, `getNumber()`, or `getArray()`, and then must be cast into the appropriate data type.\n"]]