Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003eThe \u003ccode\u003esort()\u003c/code\u003e method allows you to order an ImageCollection based on a specified property, such as cloud cover.\u003c/p\u003e\n"],["\u003cp\u003eBy default, \u003ccode\u003esort()\u003c/code\u003e arranges the collection in ascending order; to sort in descending order, set the \u003ccode\u003eascending\u003c/code\u003e parameter to \u003ccode\u003efalse\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThis method is useful for tasks like identifying images with the least or most cloud cover within a collection.\u003c/p\u003e\n"],["\u003cp\u003eThe sorted collection is returned, enabling further processing or analysis.\u003c/p\u003e\n"]]],[],null,["# ee.ImageCollection.sort\n\n\u003cbr /\u003e\n\nSort a collection by the specified property.\n\n\u003cbr /\u003e\n\nReturns the sorted collection.\n\n| Usage | Returns |\n|-------------------------------------------------|------------|\n| ImageCollection.sort`(property, `*ascending*`)` | Collection |\n\n| Argument | Type | Details |\n|--------------------|-------------------|------------------------------------------------------------------------------------|\n| this: `collection` | Collection | The Collection instance. |\n| `property` | String | The property to sort by. |\n| `ascending` | Boolean, optional | Whether to sort in ascending or descending order. The default is true (ascending). |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A Landsat 8 TOA image collection (2 months of images at a specific point).\nvar col = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')\n .filterBounds(ee.Geometry.Point(-90.70, 34.71))\n .filterDate('2020-07-01', '2020-09-01');\nprint('Collection', col);\n\n// Sort the collection in ASCENDING order of image cloud cover.\nvar colCldSortAsc = col.sort('CLOUD_COVER');\nprint('Cloud cover ascending', colCldSortAsc);\n\n// Display the image with the least cloud cover.\nvar visParams = {\n bands: ['B4', 'B3', 'B2'],\n min: 0.01,\n max: 0.25\n};\nMap.setCenter(-90.70, 34.71, 9);\nMap.addLayer(colCldSortAsc.first(), visParams, 'Least cloudy');\n\n// Sort the collection in DESCENDING order of image cloud cover.\nvar colCldSortDesc = col.sort('CLOUD_COVER', false);\nprint('Cloud cover descending', colCldSortDesc);\n\n// Display the image with the most cloud cover.\nMap.addLayer(colCldSortDesc.first(), visParams, 'Most cloudy');\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 Landsat 8 TOA image collection (2 months of images at a specific point).\ncol = (\n ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')\n .filterBounds(ee.Geometry.Point(-90.70, 34.71))\n .filterDate('2020-07-01', '2020-09-01')\n)\ndisplay('Collection', col)\n\n# Sort the collection in ASCENDING order of image cloud cover.\ncol_cld_sort_asc = col.sort('CLOUD_COVER')\ndisplay('Cloud cover ascending', col_cld_sort_asc)\n\n# Display the image with the least cloud cover.\nvis_params = {'bands': ['B4', 'B3', 'B2'], 'min': 0.01, 'max': 0.25}\nm = geemap.Map()\nm.set_center(-90.70, 34.71, 9)\nm.add_layer(col_cld_sort_asc.first(), vis_params, 'Least cloudy')\n\n# Sort the collection in DESCENDING order of image cloud cover.\ncol_cld_sort_desc = col.sort('CLOUD_COVER', False)\ndisplay('Cloud cover descending', col_cld_sort_desc)\n\n# Display the image with the most cloud cover.\nm.add_layer(col_cld_sort_desc.first(), vis_params, 'Most cloudy')\nm\n```"]]