Earth Engine
سطوح سهمیه غیرتجاری را برای محافظت از منابع محاسباتی مشترک و تضمین عملکرد قابلاعتماد برای همه معرفی کرده است. پروژههای غیرتجاری بهطور پیشفرض از «سطح انجمن» استفاده میکنند، اما هرزمان بخواهید میتوانید سطح پروژه را تغییر دهید.
Google برای ترجمه محتوا به زبان ترجیحی شما از فناوری هوشواره استفاده میکند. ترجمههای هوشوارهای ممکن است اشتباه داشته باشند.
ee.Image.sampleRegions
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
هر پیکسل تصویر (در مقیاس مشخص) را که با یک یا چند منطقه تلاقی دارد به «ویژگی» تبدیل میکند و آنها را بهعنوان FeatureCollection برمیگرداند. هر عارضه خروجی یک ویژگی برای هر باند تصویر ورودی خواهد داشت، و همچنین هر ویژگی مشخصشدهای که از عارضه ورودی کپی شده باشد.
توجه داشته باشید که هندسهها به مرکز پیکسلها چسبانده خواهند شد.
| کاربرد | بازگشتیها |
|---|
Image.sampleRegions(collection, properties, scale, projection, tileScale, geometries) | FeatureCollection |
| متغیر مستقل | نوع | جزئیات |
|---|
این: image | تصویر | تصویر برای نمونهبرداری. |
collection | FeatureCollection | مناطقی که باید از آنها نمونهبرداری شود. |
properties | فهرست، پیشفرض: تهی | فهرست ویژگیهایی که باید از هر ویژگی ورودی کپی شود. بهطور پیشفرض روی همه داراییهای غیرسیستمی تنظیم شده است. |
scale | شناور، پیشفرض: خالی | مقیاس اسمی به متر از تصویر برای نمونهبرداری. اگر مشخص نشده باشد، از مقیاس اولین باند تصویر استفاده میشود. |
projection | پیشبینی، پیشفرض: تهی | تصویرسازیای که باید نمونهبرداری شود. اگر مشخص نشده باشد، از تصویرسازی اولین باند تصویر استفاده میشود. اگر علاوهبر مقیاس مشخص شده باشد، به مقیاس مشخصشده تغییر مقیاس داده میشود. |
tileScale | اعشاری، پیشفرض: ۱ | ضریب مقیاس مورداستفاده برای کاهش اندازه کاشی انبوهش؛ استفاده از tileScale بزرگتر (مثلاً ۲ یا ۴) ممکن است محاسباتی را که با مقدار پیشفرض با کمبود حافظه مواجه میشوند فعال کند. |
geometries | بولی، پیشفرض: نادرست | اگر درست باشد، نتایج شامل یک هندسه نقطهای بهازای هر پیکسل نمونهبرداریشده خواهد بود. درغیراینصورت، هندسهها حذف خواهند شد (صرفهجویی در حافظه). |
مثالها
ویرایشگر کد (جاوا اسکریپت)
// A Sentinel-2 surface reflectance image.
var img = ee.Image('COPERNICUS/S2_SR_HARMONIZED/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_HARMONIZED/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)
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2026-11-02 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2026-11-02 بهوقت ساعت هماهنگ جهانی."],[],["The `Image.sampleRegions` method converts image pixels intersecting specified regions into a `FeatureCollection`. Each output feature contains properties from the input image bands and any designated input feature properties. Geometries are snapped to pixel centers. The sampling scale and projection can be specified; otherwise, the image's first band defaults are used. Optionally, geometries of the sampled pixels can be included, and tile scaling can be used for memory management.\n"]]