公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.ImageCollection.sort
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
按指定属性对集合进行排序。
返回已排序的集合。
用法 | 返回 |
---|
ImageCollection.sort(property, ascending) | 集合 |
参数 | 类型 | 详细信息 |
---|
此:collection | 集合 | Collection 实例。 |
property | 字符串 | 要排序的属性。 |
ascending | 布尔值,可选 | 是按升序还是降序排序。默认值为 true(升序)。 |
示例
代码编辑器 (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');
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# A Landsat 8 TOA image collection (2 months of images at a specific point).
col = (
ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
.filterBounds(ee.Geometry.Point(-90.70, 34.71))
.filterDate('2020-07-01', '2020-09-01')
)
display('Collection', col)
# Sort the collection in ASCENDING order of image cloud cover.
col_cld_sort_asc = col.sort('CLOUD_COVER')
display('Cloud cover ascending', col_cld_sort_asc)
# Display the image with the least cloud cover.
vis_params = {'bands': ['B4', 'B3', 'B2'], 'min': 0.01, 'max': 0.25}
m = geemap.Map()
m.set_center(-90.70, 34.71, 9)
m.add_layer(col_cld_sort_asc.first(), vis_params, 'Least cloudy')
# Sort the collection in DESCENDING order of image cloud cover.
col_cld_sort_desc = col.sort('CLOUD_COVER', False)
display('Cloud cover descending', col_cld_sort_desc)
# Display the image with the most cloud cover.
m.add_layer(col_cld_sort_desc.first(), vis_params, 'Most cloudy')
m
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-29。
[null,null,["最后更新时间 (UTC):2025-07-29。"],[[["\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```"]]