公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.ImageCollection.aggregate_sum
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
匯總集合中物件的指定屬性,並計算所選屬性的值總和。
用量 | 傳回 |
---|
ImageCollection.aggregate_sum(property) | 數字 |
引數 | 類型 | 詳細資料 |
---|
這個:collection | FeatureCollection | 要匯總的集合。 |
property | 字串 | 要從集合的每個元素使用的屬性。 |
範例
程式碼編輯器 (JavaScript)
// A Lansat 8 TOA image collection for a specific year and location.
var 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.
var 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.
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.
var propString = '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 設定
請參閱
Python 環境頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
import ee
import geemap.core as geemap
Colab (Python)
from pprint import pprint
# 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.
print('List of property values:', col.aggregate_array(prop).getInfo())
print('Count of property values:', col.aggregate_count(prop).getInfo())
print('Count of distinct property values:',
col.aggregate_count_distinct(prop).getInfo())
print('First collection element property value:',
col.aggregate_first(prop).getInfo())
print('Histogram of property values:')
pprint(col.aggregate_histogram(prop).getInfo())
print('Min of property values:', col.aggregate_min(prop).getInfo())
print('Max of property values:', col.aggregate_max(prop).getInfo())
# The following methods are applicable to numerical properties only.
print('Mean of property values:', col.aggregate_mean(prop).getInfo())
print('Sum of property values:', col.aggregate_sum(prop).getInfo())
print('Product of property values:', col.aggregate_product(prop).getInfo())
print('Std dev (sample) of property values:',
col.aggregate_sample_sd(prop).getInfo())
print('Variance (sample) of property values:',
col.aggregate_sample_var(prop).getInfo())
print('Std dev (total) of property values:',
col.aggregate_total_sd(prop).getInfo())
print('Variance (total) of property values:',
col.aggregate_total_var(prop).getInfo())
print('Summary stats of property values:')
pprint(col.aggregate_stats(prop).getInfo())
# 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'
print('List of property values (string):',
col.aggregate_array(prop_string).getInfo())
print('Min of property values (string):',
col.aggregate_min(prop_string).getInfo())
print('Max of property values (string):',
col.aggregate_max(prop_string).getInfo())
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003eaggregate_sum\u003c/code\u003e calculates the sum of a specified property across all elements in an ImageCollection.\u003c/p\u003e\n"],["\u003cp\u003eIt takes the ImageCollection and the property name as inputs.\u003c/p\u003e\n"],["\u003cp\u003eThe property should contain numerical values for the calculation to be meaningful.\u003c/p\u003e\n"],["\u003cp\u003eThis function is useful for summarizing data across a collection, such as total cloud cover over a time period.\u003c/p\u003e\n"]]],[],null,["# ee.ImageCollection.aggregate_sum\n\nAggregates over a given property of the objects in a collection, calculating the sum of the values of the selected property.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-------------------------------------------|---------|\n| ImageCollection.aggregate_sum`(property)` | Number |\n\n| Argument | Type | Details |\n|--------------------|-------------------|----------------------------------------------------------|\n| this: `collection` | FeatureCollection | The collection to aggregate over. |\n| `property` | String | The property to use from each element of the collection. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A Lansat 8 TOA image collection for a specific year and location.\nvar col = ee.ImageCollection(\"LANDSAT/LC08/C02/T1_TOA\")\n .filterBounds(ee.Geometry.Point([-122.073, 37.188]))\n .filterDate('2018', '2019');\n\n// An image property of interest, percent cloud cover in this case.\nvar prop = 'CLOUD_COVER';\n\n// Use ee.ImageCollection.aggregate_* functions to fetch information about\n// values of a selected property across all images in the collection. For\n// example, produce a list of all values, get counts, and calculate statistics.\nprint('List of property values', col.aggregate_array(prop));\nprint('Count of property values', col.aggregate_count(prop));\nprint('Count of distinct property values', col.aggregate_count_distinct(prop));\nprint('First collection element property value', col.aggregate_first(prop));\nprint('Histogram of property values', col.aggregate_histogram(prop));\nprint('Min of property values', col.aggregate_min(prop));\nprint('Max of property values', col.aggregate_max(prop));\n\n// The following methods are applicable to numerical properties only.\nprint('Mean of property values', col.aggregate_mean(prop));\nprint('Sum of property values', col.aggregate_sum(prop));\nprint('Product of property values', col.aggregate_product(prop));\nprint('Std dev (sample) of property values', col.aggregate_sample_sd(prop));\nprint('Variance (sample) of property values', col.aggregate_sample_var(prop));\nprint('Std dev (total) of property values', col.aggregate_total_sd(prop));\nprint('Variance (total) of property values', col.aggregate_total_var(prop));\nprint('Summary stats of property values', col.aggregate_stats(prop));\n\n// Note that if the property is formatted as a string, min and max will\n// respectively return the first and last values according to alphanumeric\n// order of the property values.\nvar propString = 'LANDSAT_SCENE_ID';\nprint('List of property values (string)', col.aggregate_array(propString));\nprint('Min of property values (string)', col.aggregate_min(propString));\nprint('Max of property values (string)', col.aggregate_max(propString));\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\nfrom pprint import pprint\n\n# A Lansat 8 TOA image collection for a specific year and location.\ncol = ee.ImageCollection(\"LANDSAT/LC08/C02/T1_TOA\").filterBounds(\n ee.Geometry.Point([-122.073, 37.188])).filterDate('2018', '2019')\n\n# An image property of interest, percent cloud cover in this case.\nprop = 'CLOUD_COVER'\n\n# Use ee.ImageCollection.aggregate_* functions to fetch information about\n# values of a selected property across all images in the collection. For\n# example, produce a list of all values, get counts, and calculate statistics.\nprint('List of property values:', col.aggregate_array(prop).getInfo())\nprint('Count of property values:', col.aggregate_count(prop).getInfo())\nprint('Count of distinct property values:',\n col.aggregate_count_distinct(prop).getInfo())\nprint('First collection element property value:',\n col.aggregate_first(prop).getInfo())\nprint('Histogram of property values:')\npprint(col.aggregate_histogram(prop).getInfo())\nprint('Min of property values:', col.aggregate_min(prop).getInfo())\nprint('Max of property values:', col.aggregate_max(prop).getInfo())\n\n# The following methods are applicable to numerical properties only.\nprint('Mean of property values:', col.aggregate_mean(prop).getInfo())\nprint('Sum of property values:', col.aggregate_sum(prop).getInfo())\nprint('Product of property values:', col.aggregate_product(prop).getInfo())\nprint('Std dev (sample) of property values:',\n col.aggregate_sample_sd(prop).getInfo())\nprint('Variance (sample) of property values:',\n col.aggregate_sample_var(prop).getInfo())\nprint('Std dev (total) of property values:',\n col.aggregate_total_sd(prop).getInfo())\nprint('Variance (total) of property values:',\n col.aggregate_total_var(prop).getInfo())\nprint('Summary stats of property values:')\npprint(col.aggregate_stats(prop).getInfo())\n\n# Note that if the property is formatted as a string, min and max will\n# respectively return the first and last values according to alphanumeric\n# order of the property values.\nprop_string = 'LANDSAT_SCENE_ID'\nprint('List of property values (string):',\n col.aggregate_array(prop_string).getInfo())\nprint('Min of property values (string):',\n col.aggregate_min(prop_string).getInfo())\nprint('Max of property values (string):',\n col.aggregate_max(prop_string).getInfo())\n```"]]