ee.Image.sampleRegions

هر پیکسل از یک تصویر (در یک مقیاس معین) را که یک یا چند ناحیه را قطع می کند به یک ویژگی تبدیل می کند و آنها را به عنوان یک FeatureCollection برمی گرداند. هر ویژگی خروجی یک ویژگی در هر باند تصویر ورودی و همچنین هر ویژگی مشخص شده کپی شده از ویژگی ورودی خواهد داشت.

توجه داشته باشید که هندسه‌ها به مرکز پیکسل تغییر می‌کنند.

استفاده برمی گرداند
Image. sampleRegions (collection, properties , scale , projection , tileScale , geometries ) مجموعه ویژگی ها
استدلال تایپ کنید جزئیات
این: image تصویر تصویر برای نمونه
collection مجموعه ویژگی ها مناطقی که باید نمونه برداری شوند.
properties لیست، پیش فرض: null فهرست خواصی که باید از هر ویژگی ورودی کپی کنید. پیش‌فرض تمام خصوصیات غیر سیستمی.
scale شناور، پیش فرض: null یک مقیاس اسمی بر حسب متر از طرح ریزی برای نمونه. اگر مشخص نشده باشد، از مقیاس اولین باند تصویر استفاده می شود.
projection Projection، پیش فرض: null طرح ریزی که در آن نمونه برداری می شود. در صورت نامشخص، طرح ریزی اولین باند تصویر استفاده می شود. اگر علاوه بر مقیاس مشخص شده است، به مقیاس مشخص شده مجدداً مقیاس می شود.
tileScale شناور، پیش فرض: 1 یک عامل پوسته پوسته شدن مورد استفاده برای کاهش اندازه کاشی تجمع. استفاده از یک tileScale بزرگتر (مثلاً 2 یا 4) ممکن است محاسباتی را فعال کند که با پیش فرض حافظه آنها تمام می شود.
geometries بولی، پیش فرض: نادرست اگر درست باشد، نتایج شامل یک هندسه نقطه در هر پیکسل نمونه می شود. در غیر این صورت، هندسه ها حذف می شوند (صرفه جویی در حافظه).

نمونه ها

ویرایشگر کد (جاوا اسکریپت)

// 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);

راه اندازی پایتون

برای اطلاعات در مورد API پایتون و استفاده از geemap برای توسعه تعاملی به صفحه محیط پایتون مراجعه کنید.

import ee
import geemap.core as geemap

کولب (پایتون)

# 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)
،هر پیکسل از یک تصویر (در یک مقیاس معین) را که یک یا چند ناحیه را قطع می کند به یک ویژگی تبدیل می کند و آنها را به عنوان یک FeatureCollection برمی گرداند. هر ویژگی خروجی یک ویژگی در هر باند تصویر ورودی و همچنین هر ویژگی مشخص شده کپی شده از ویژگی ورودی خواهد داشت.

توجه داشته باشید که هندسه‌ها به مرکز پیکسل تغییر می‌کنند.

استفاده برمی گرداند
Image. sampleRegions (collection, properties , scale , projection , tileScale , geometries ) مجموعه ویژگی ها
استدلال تایپ کنید جزئیات
این: image تصویر تصویر برای نمونه
collection مجموعه ویژگی ها مناطقی که باید نمونه برداری شوند.
properties لیست، پیش فرض: null فهرست خواصی که باید از هر ویژگی ورودی کپی کنید. پیش‌فرض تمام خصوصیات غیر سیستمی.
scale شناور، پیش فرض: null یک مقیاس اسمی بر حسب متر از طرح ریزی برای نمونه. اگر مشخص نشده باشد، از مقیاس اولین باند تصویر استفاده می شود.
projection Projection، پیش فرض: null طرح ریزی که در آن نمونه برداری می شود. در صورت نامشخص، طرح ریزی اولین باند تصویر استفاده می شود. اگر علاوه بر مقیاس مشخص شده است، به مقیاس مشخص شده مجدداً مقیاس می شود.
tileScale شناور، پیش فرض: 1 یک عامل پوسته پوسته شدن مورد استفاده برای کاهش اندازه کاشی تجمع. استفاده از یک tileScale بزرگتر (مثلاً 2 یا 4) ممکن است محاسباتی را فعال کند که با پیش فرض حافظه آنها تمام می شود.
geometries بولی، پیش فرض: نادرست اگر درست باشد، نتایج شامل یک هندسه نقطه در هر پیکسل نمونه می شود. در غیر این صورت، هندسه ها حذف می شوند (صرفه جویی در حافظه).

نمونه ها

ویرایشگر کد (جاوا اسکریپت)

// 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);

راه اندازی پایتون

برای اطلاعات در مورد API پایتون و استفاده از geemap برای توسعه تعاملی به صفحه محیط پایتون مراجعه کنید.

import ee
import geemap.core as geemap

کولب (پایتون)

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