Số liệu thống kê về vùng hình ảnh

Để lấy số liệu thống kê hình ảnh ở nhiều khu vực được lưu trữ trong FeatureCollection, bạn có thể sử dụng image.reduceRegions() để giảm nhiều khu vực cùng một lúc. Dữ liệu đầu vào cho reduceRegions()ImageFeatureCollection. Kết quả là một FeatureCollection khác với đầu ra reduceRegions() được đặt làm thuộc tính trên mỗi Feature. Trong ví dụ này, giá trị trung bình của các dải tổng hợp hằng năm của Landsat 7 trong mỗi hình học đặc điểm sẽ được thêm dưới dạng thuộc tính vào các đặc điểm đầu vào:

Trình soạn thảo mã (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()));

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap để phát triển tương tác.

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()))

Hãy quan sát rằng các thuộc tính mới, được khoá theo tên dải tần, đã được thêm vào FeatureCollection để lưu trữ giá trị trung bình của thành phần kết hợp trong mỗi hình học Feature. Do đó, kết quả của câu lệnh in sẽ có dạng như sau:

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