ee.ImageCollection.sort

Stay organized with collections Save and categorize content based on your preferences.

Sort a collection by the specified property.

Returns the sorted collection.

UsageReturns
ImageCollection.sort(property, ascending)Collection
ArgumentTypeDetails
this: collectionCollectionThe Collection instance.
propertyStringThe property to sort by.
ascendingBoolean, optionalWhether to sort in ascending or descending order. The default is true (ascending).

Examples

Code Editor (JavaScript)

// A Landsat 8 TOA image collection (2 months of images at a specific point).
var col = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
  .filterBounds(ee.Geometry.Point(-90.70, 34.71))
  .filterDate('2020-07-01', '2020-09-01');
print('Collection', col);

// Sort the collection in ASCENDING order of image cloud cover.
var colCldSortAsc = col.sort('CLOUD_COVER');
print('Cloud cover ascending', colCldSortAsc);

// Display the image with the least cloud cover.
var visParams = {
  bands: ['B4', 'B3', 'B2'],
  min: 0.01,
  max: 0.25
};
Map.setCenter(-90.70, 34.71, 9);
Map.addLayer(colCldSortAsc.first(), visParams, 'Least cloudy');

// Sort the collection in DESCENDING order of image cloud cover.
var colCldSortDesc = col.sort('CLOUD_COVER', false);
print('Cloud cover descending', colCldSortDesc);

// Display the image with the most cloud cover.
Map.addLayer(colCldSortDesc.first(), visParams, 'Most cloudy');