公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
图片区域的统计信息
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如需获取存储在 FeatureCollection
中的多个区域中的图片统计信息,您可以使用 image.reduceRegions()
一次缩减多个区域。reduceRegions()
的输入为 Image
和 FeatureCollection
。输出是另一个 FeatureCollection
,其中 reduceRegions()
输出被设置为每个 Feature
的属性。
在本例中,系统会将每个地图项几何图形中 Landsat 7 年度复合波段的均值添加为输入地图项的属性:
Code Editor (JavaScript)
// Load input imagery: Landsat 7 5-year composite.
var image = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012');
// Load a FeatureCollection of counties in Maine.
var maineCounties = ee.FeatureCollection('TIGER/2016/Counties')
.filter(ee.Filter.eq('STATEFP', '23'));
// Add reducer output to the Features in the collection.
var maineMeansFeatures = image.reduceRegions({
collection: maineCounties,
reducer: ee.Reducer.mean(),
scale: 30,
});
// Print the first feature, to illustrate the result.
print(ee.Feature(maineMeansFeatures.first()).select(image.bandNames()));
Python 设置
如需了解 Python API 以及如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# Load input imagery: Landsat 7 5-year composite.
image = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012')
# Load a FeatureCollection of counties in Maine.
maine_counties = ee.FeatureCollection('TIGER/2016/Counties').filter(
ee.Filter.eq('STATEFP', '23')
)
# Add reducer output to the Features in the collection.
maine_means_features = image.reduceRegions(
collection=maine_counties, reducer=ee.Reducer.mean(), scale=30
)
# Print the first feature, to illustrate the result.
display(ee.Feature(maine_means_features.first()).select(image.bandNames()))
请注意,系统已向 FeatureCollection
添加了按波段名称键控的新属性,以便在每个 Feature
几何图形中存储复合体的均值。因此,print 语句的输出应如下所示:
Feature (Polygon, 7 properties)
type: Feature
geometry: Polygon, 7864 vertices
properties: Object (7 properties)
B1: 24.034822192925134
B2: 19.40202233717122
B3: 13.568454303016292
B4: 63.00423784301736
B5: 29.142707062821305
B6_VCID_2: 186.18172376827042
B7: 12.064469664746415
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003e\u003ccode\u003eimage.reduceRegions()\u003c/code\u003e can be used to calculate statistics for an image within multiple regions defined by a \u003ccode\u003eFeatureCollection\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe output is a new \u003ccode\u003eFeatureCollection\u003c/code\u003e where each feature has new properties containing the calculated statistics.\u003c/p\u003e\n"],["\u003cp\u003eThis example demonstrates calculating the mean of Landsat 7 bands for each county in Maine.\u003c/p\u003e\n"],["\u003cp\u003eThe calculated statistics are added as properties to the original features, with band names as keys.\u003c/p\u003e\n"]]],["The core content explains how to use `image.reduceRegions()` to calculate image statistics across multiple regions. This method takes an `Image` and a `FeatureCollection` as input. It then outputs a new `FeatureCollection`, where each feature has the results of the reduction (e.g., mean) as properties. The example uses Landsat 7 data and Maine counties, calculating the mean of each band within each county's geometry and adding them as properties in the resulting feature.\n"],null,["# Statistics of Image Regions\n\nTo get image statistics in multiple regions stored in a `FeatureCollection`,\nyou can use `image.reduceRegions()` to reduce multiple regions at once.\nThe input to `reduceRegions()` is an `Image` and a\n`FeatureCollection`. The output is another `FeatureCollection`\nwith the `reduceRegions()` output set as properties on each `Feature`.\nIn this example, means of the Landsat 7 annual composite bands in each feature geometry\nwill be added as properties to the input features:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load input imagery: Landsat 7 5-year composite.\nvar image = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012');\n\n// Load a FeatureCollection of counties in Maine.\nvar maineCounties = ee.FeatureCollection('TIGER/2016/Counties')\n .filter(ee.Filter.eq('STATEFP', '23'));\n\n// Add reducer output to the Features in the collection.\nvar maineMeansFeatures = image.reduceRegions({\n collection: maineCounties,\n reducer: ee.Reducer.mean(),\n scale: 30,\n});\n\n// Print the first feature, to illustrate the result.\nprint(ee.Feature(maineMeansFeatures.first()).select(image.bandNames()));\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# Load input imagery: Landsat 7 5-year composite.\nimage = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012')\n\n# Load a FeatureCollection of counties in Maine.\nmaine_counties = ee.FeatureCollection('TIGER/2016/Counties').filter(\n ee.Filter.eq('STATEFP', '23')\n)\n\n# Add reducer output to the Features in the collection.\nmaine_means_features = image.reduceRegions(\n collection=maine_counties, reducer=ee.Reducer.mean(), scale=30\n)\n\n# Print the first feature, to illustrate the result.\ndisplay(ee.Feature(maine_means_features.first()).select(image.bandNames()))\n```\n\nObserve that new properties, keyed by band name, have been added to the\n`FeatureCollection` to store the mean of the composite in each\n`Feature` geometry. As a result, the output of the print statement should\nlook something like: \n\n```\nFeature (Polygon, 7 properties)\n type: Feature\n geometry: Polygon, 7864 vertices\n properties: Object (7 properties)\n B1: 24.034822192925134\n B2: 19.40202233717122\n B3: 13.568454303016292\n B4: 63.00423784301736\n B5: 29.142707062821305\n B6_VCID_2: 186.18172376827042\n B7: 12.064469664746415\n \n```"]]