Announcement: All noncommercial projects registered to use Earth Engine beforeApril 15, 2025 mustverify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.

ee.ImageCollection.aggregate_first

  • Theaggregate_first function is used to aggregate over a given property of objects in a collection and return the property value of the first object.

  • This function takes aFeatureCollection as the collection to aggregate over and aString representing the property to use from each element of the collection.

  • Examples demonstrate how to useaggregate_first in both JavaScript and Python Code Editors to get the property value of the first image in anImageCollection.

Aggregates over a given property of the objects in a collection, calculating the property value of the first object in the collection.

UsageReturns
ImageCollection.aggregate_first(property)
ArgumentTypeDetails
this:collectionFeatureCollectionThe collection to aggregate over.
propertyStringThe property to use from each element of the collection.

Examples

Code Editor (JavaScript)

// A Lansat 8 TOA image collection for a specific year and location.varcol=ee.ImageCollection("LANDSAT/LC08/C02/T1_TOA").filterBounds(ee.Geometry.Point([-122.073,37.188])).filterDate('2018','2019');// An image property of interest, percent cloud cover in this case.varprop='CLOUD_COVER';// Use ee.ImageCollection.aggregate_* functions to fetch information about// values of a selected property across all images in the collection. For// example, produce a list of all values, get counts, and calculate statistics.print('List of property values',col.aggregate_array(prop));print('Count of property values',col.aggregate_count(prop));print('Count of distinct property values',col.aggregate_count_distinct(prop));print('First collection element property value',col.aggregate_first(prop));print('Histogram of property values',col.aggregate_histogram(prop));print('Min of property values',col.aggregate_min(prop));print('Max of property values',col.aggregate_max(prop));// The following methods are applicable to numerical properties only.print('Mean of property values',col.aggregate_mean(prop));print('Sum of property values',col.aggregate_sum(prop));print('Product of property values',col.aggregate_product(prop));print('Std dev (sample) of property values',col.aggregate_sample_sd(prop));print('Variance (sample) of property values',col.aggregate_sample_var(prop));print('Std dev (total) of property values',col.aggregate_total_sd(prop));print('Variance (total) of property values',col.aggregate_total_var(prop));print('Summary stats of property values',col.aggregate_stats(prop));// Note that if the property is formatted as a string, min and max will// respectively return the first and last values according to alphanumeric// order of the property values.varpropString='LANDSAT_SCENE_ID';print('List of property values (string)',col.aggregate_array(propString));print('Min of property values (string)',col.aggregate_min(propString));print('Max of property values (string)',col.aggregate_max(propString));

Python setup

See the Python Environment page for information on the Python API and usinggeemap for interactive development.

importeeimportgeemap.coreasgeemap

Colab (Python)

# A Lansat 8 TOA image collection for a specific year and location.col=ee.ImageCollection("LANDSAT/LC08/C02/T1_TOA").filterBounds(ee.Geometry.Point([-122.073,37.188])).filterDate('2018','2019')# An image property of interest, percent cloud cover in this case.prop='CLOUD_COVER'# Use ee.ImageCollection.aggregate_* functions to fetch information about# values of a selected property across all images in the collection. For# example, produce a list of all values, get counts, and calculate statistics.display('List of property values:',col.aggregate_array(prop))display('Count of property values:',col.aggregate_count(prop))display('Count of distinct property values:',col.aggregate_count_distinct(prop))display('First collection element property value:',col.aggregate_first(prop))display('Histogram of property values:',col.aggregate_histogram(prop))display('Min of property values:',col.aggregate_min(prop))display('Max of property values:',col.aggregate_max(prop))# The following methods are applicable to numerical properties only.display('Mean of property values:',col.aggregate_mean(prop))display('Sum of property values:',col.aggregate_sum(prop))display('Product of property values:',col.aggregate_product(prop))display('Std dev (sample) of property values:',col.aggregate_sample_sd(prop))display('Variance (sample) of property values:',col.aggregate_sample_var(prop))display('Std dev (total) of property values:',col.aggregate_total_sd(prop))display('Variance (total) of property values:',col.aggregate_total_var(prop))display('Summary stats of property values',col.aggregate_stats(prop))# Note that if the property is formatted as a string, min and max will# respectively return the first and last values according to alphanumeric# order of the property values.prop_string='LANDSAT_SCENE_ID'display('List of property values (string):',col.aggregate_array(prop_string))display('Min of property values (string):',col.aggregate_min(prop_string))display('Max of property values (string):',col.aggregate_max(prop_string))

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2023-10-06 UTC.