ee.Image.sampleRegions

하나 이상의 영역과 교차하는 이미지의 각 픽셀 (지정된 스케일)을 특성으로 변환하여 FeatureCollection으로 반환합니다. 각 출력 피처에는 입력 이미지의 밴드당 하나의 속성과 입력 피처에서 복사된 지정된 속성이 있습니다.

지오메트리가 픽셀 중심으로 스냅됩니다.

사용반환 값
Image.sampleRegions(collection, properties, scale, projection, tileScale, geometries)FeatureCollection
인수유형세부정보
다음과 같은 경우: image이미지샘플링할 이미지입니다.
collectionFeatureCollection샘플링할 리전입니다.
properties목록, 기본값: null각 입력 기능에서 복사할 속성의 목록입니다. 기본값은 모든 비시스템 속성입니다.
scale부동 소수점 수, 기본값: null샘플링할 투영의 명목상 스케일(미터)입니다. 지정하지 않으면 이미지의 첫 번째 밴드 스케일이 사용됩니다.
projection예상, 기본값: null샘플링할 투영입니다. 지정하지 않으면 이미지의 첫 번째 밴드의 투영이 사용됩니다. 크기 조정 외에 지정된 경우 지정된 크기로 다시 조정됩니다.
tileScale부동 소수점 수, 기본값: 1집계 타일 크기를 줄이는 데 사용되는 확장 요소입니다. 더 큰 tileScale (예: 2 또는 4)를 사용하면 기본값으로 메모리가 부족한 계산을 실행할 수 있습니다.
geometries불리언, 기본값: falsetrue인 경우 결과에는 샘플링된 픽셀당 포인트 지오메트리가 포함됩니다. 그렇지 않으면 지오메트리가 생략되어 메모리가 절약됩니다.

코드 편집기 (JavaScript)

// A Sentinel-2 surface reflectance image.
var img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');
Map.setCenter(-122.503881, 37.765588, 18);
Map.addLayer(img, {bands: ['B11', 'B8', 'B3'], min: 100, max: 4500}, 'img');

// A feature collection with two polygon regions each intersecting 36
// pixels at 10 m scale.
var fcPolygon = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Rectangle(
    -122.50620929, 37.76502806, -122.50552264, 37.76556663), {id: 0}),
  ee.Feature(ee.Geometry.Rectangle(
    -122.50530270, 37.76565568, -122.50460533, 37.76619425), {id: 1})
]);
Map.addLayer(fcPolygon, {color: 'yellow'}, 'fcPolygon');

var fcPolygonSamp = img.sampleRegions({
  collection: fcPolygon,
  scale: 10,
  geometries: true
});
// Note that 7 pixels are missing from the sample. If a pixel contains a masked
// band value it will be excluded from the sample. In this case, the TCI_B band
// is masked for each unsampled pixel.
print('A feature per pixel (at given scale) in each region', fcPolygonSamp);
Map.addLayer(fcPolygonSamp, {color: 'purple'}, 'fcPolygonSamp');

// A feature collection with two points intersecting two different pixels.
// This example is included to show the behavior for point geometries. In
// practice, if the feature collection is all points, ee.Image.reduceRegions
// should be used instead to save memory.
var fcPoint = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point([-122.50309256, 37.76605006]), {id: 0}),
  ee.Feature(ee.Geometry.Point([-122.50344661, 37.76560903]), {id: 1})
]);
Map.addLayer(fcPoint, {color: 'cyan'}, 'fcPoint');

var fcPointSamp = img.sampleRegions({
  collection: fcPoint,
  scale: 10
});
print('A feature per point', fcPointSamp);

Python 설정

Python API 및 geemap를 사용한 대화형 개발에 관한 자세한 내용은 Python 환경 페이지를 참고하세요.

import ee
import geemap.core as geemap

Colab (Python)

# A Sentinel-2 surface reflectance image.
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')
m = geemap.Map()
m.set_center(-122.503881, 37.765588, 18)
m.add_layer(
    img, {'bands': ['B11', 'B8', 'B3'], 'min': 100, 'max': 4500}, 'img'
)
display(m)

# A feature collection with two polygon regions each intersecting 36
# pixels at 10 m scale.
fc_polygon = ee.FeatureCollection([
    ee.Feature(
        ee.Geometry.Rectangle(
            -122.50620929, 37.76502806, -122.50552264, 37.76556663
        ),
        {'id': 0},
    ),
    ee.Feature(
        ee.Geometry.Rectangle(
            -122.50530270, 37.76565568, -122.50460533, 37.76619425
        ),
        {'id': 1},
    ),
])
m.add_layer(fc_polygon, {'color': 'yellow'}, 'fc_polygon')

fc_polygon_samp = img.sampleRegions(
    collection=fc_polygon, scale=10, geometries=True
)
# Note that 7 pixels are missing from the sample. If a pixel contains a masked
# band value it will be excluded from the sample. In this case, the TCI_B band
# is masked for each unsampled pixel.
display('A feature per pixel (at given scale) in each region', fc_polygon_samp)
m.add_layer(fc_polygon_samp, {'color': 'purple'}, 'fc_polygon_samp')

# A feature collection with two points intersecting two different pixels.
# This example is included to show the behavior for point geometries. In
# practice, if the feature collection is all points, ee.Image.reduceRegions
# should be used instead to save memory.
fc_point = ee.FeatureCollection([
    ee.Feature(ee.Geometry.Point([-122.50309256, 37.76605006]), {'id': 0}),
    ee.Feature(ee.Geometry.Point([-122.50344661, 37.76560903]), {'id': 1}),
])
m.add_layer(fc_point, {'color': 'cyan'}, 'fc_point')

fc_point_samp = img.sampleRegions(collection=fc_point, scale=10)
display('A feature per point', fc_point_samp)