图片区域的统计信息

如需获取存储在 FeatureCollection 中的多个区域中的图片统计信息,您可以使用 image.reduceRegions() 一次缩减多个区域。reduceRegions() 的输入为 ImageFeatureCollection。输出是另一个 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