FeatureCollection
에 저장된 여러 리전의 이미지 통계를 가져오려면 image.reduceRegions()
를 사용하여 여러 리전을 한 번에 줄이면 됩니다.
reduceRegions()
의 입력은 Image
및 FeatureCollection
입니다. 출력은 각 Feature
의 속성으로 설정된 reduceRegions()
출력이 있는 다른 FeatureCollection
입니다.
이 예에서는 각 지형지물 도형의 Landsat 7 연간 합성 밴드의 평균이 입력 지형지물에 속성으로 추가됩니다.
코드 편집기 (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()));
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