ee.Image.sample
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پیکسل های یک تصویر را نمونه برداری می کند و آنها را به عنوان FeatureCollection برمی گرداند. هر ویژگی 1 ویژگی در هر باند در تصویر ورودی خواهد داشت. توجه داشته باشید که رفتار پیشفرض حذف ویژگیهایی است که پیکسلهای پوشانده شده را قطع میکنند، که منجر به ویژگیهای با ارزش تهی میشود (به آرگومان dropNulls مراجعه کنید).
استفاده | برمی گرداند | Image. sample ( region , scale , projection , factor , numPixels , seed , dropNulls , tileScale , geometries ) | مجموعه ویژگی ها |
استدلال | تایپ کنید | جزئیات | این: image | تصویر | تصویر برای نمونه |
region | هندسه، پیش فرض: null | منطقه ای که باید از آن نمونه برداری کرد. اگر نامشخص باشد، از کل ردپای تصویر استفاده می کند. |
scale | شناور، پیش فرض: null | مقیاس اسمی بر حسب متر از برجستگی برای نمونه برداری. |
projection | Projection، پیش فرض: null | طرح ریزی که در آن نمونه برداری می شود. در صورت نامشخص، طرح ریزی اولین باند تصویر استفاده می شود. اگر علاوه بر مقیاس مشخص شده است، به مقیاس مشخص شده مجدداً مقیاس می شود. |
factor | شناور، پیش فرض: null | یک عامل نمونهبرداری فرعی، در (0، 1]. اگر مشخص شده باشد، «numPixels» نباید مشخص شود. پیشفرضها بدون نمونهگیری فرعی هستند. |
numPixels | طولانی، پیش فرض: null | تعداد تقریبی پیکسل های نمونه. در صورت مشخص شدن، «عامل» نباید مشخص شود. |
seed | عدد صحیح، پیش فرض: 0 | یک دانه تصادفی برای استفاده برای نمونه گیری فرعی. |
dropNulls | بولی، پیش فرض: درست است | برای حذف ویژگیهایی که دارای ویژگیهای تهی هستند، نتیجه را فیلتر کنید. |
tileScale | شناور، پیش فرض: 1 | یک عامل پوسته پوسته شدن مورد استفاده برای کاهش اندازه کاشی تجمع. استفاده از یک tileScale بزرگتر (مثلاً 2 یا 4) ممکن است محاسباتی را فعال کند که با پیش فرض حافظه آنها تمام می شود. |
geometries | بولی، پیش فرض: نادرست | اگر درست باشد، مرکز پیکسل نمونه برداری شده را به عنوان ویژگی هندسی ویژگی خروجی اضافه می کند. در غیر این صورت، هندسه ها حذف می شوند (صرفه جویی در حافظه). |
نمونه ها
ویرایشگر کد (جاوا اسکریپت)
// Demonstrate extracting pixels from an image as features with
// ee.Image.sample(), and show how the features are aligned with the pixels.
// An image with one band of elevation data.
var image = ee.Image('CGIAR/SRTM90_V4');
var VIS_MIN = 1620;
var VIS_MAX = 1650;
Map.addLayer(image, {min: VIS_MIN, max: VIS_MAX}, 'SRTM');
// Region to sample.
var region = ee.Geometry.Polygon(
[[[-110.006, 40.002],
[-110.006, 39.999],
[-109.995, 39.999],
[-109.995, 40.002]]], null, false);
// Show region on the map.
Map.setCenter(-110, 40, 16);
Map.addLayer(ee.FeatureCollection([region]).style({"color": "00FF0022"}));
// Perform sampling; convert image pixels to features.
var samples = image.sample({
region: region,
// Default (false) is no geometries in the output.
// When set to true, each feature has a Point geometry at the center of the
// image pixel.
geometries: true,
// The scale is not specified, so the resolution of the image will be used,
// and there is a feature for every pixel. If we give a scale parameter, the
// image will be resampled and there will be more or fewer features.
//
// scale: 200,
});
// Visualize sample data using ee.FeatureCollection.style().
var styled = samples
.map(function (feature) {
return feature.set('style', {
pointSize: feature.getNumber('elevation').unitScale(VIS_MIN, VIS_MAX)
.multiply(15),
});
})
.style({
color: '000000FF',
fillColor: '00000000',
styleProperty: 'style',
neighborhood: 6, // increase to correctly draw large points
});
Map.addLayer(styled);
// Each sample feature has a point geometry and a property named 'elevation'
// corresponding to the band named 'elevation' of the image. If there are
// multiple bands they will become multiple properties. This will print:
//
// geometry: Point (-110.01, 40.00)
// properties:
// elevation: 1639
print(samples.first());
راه اندازی پایتون
برای اطلاعات در مورد API پایتون و استفاده از geemap
برای توسعه تعاملی به صفحه محیط پایتون مراجعه کنید.
import ee
import geemap.core as geemap
کولب (پایتون)
# Demonstrate extracting pixels from an image as features with
# ee.Image.sample(), and show how the features are aligned with the pixels.
# An image with one band of elevation data.
image = ee.Image('CGIAR/SRTM90_V4')
vis_min = 1620
vis_max = 1650
m = geemap.Map()
m.add_layer(image, {'min': vis_min, 'max': vis_max}, 'SRTM')
# Region to sample.
region = ee.Geometry.Polygon(
[[
[-110.006, 40.002],
[-110.006, 39.999],
[-109.995, 39.999],
[-109.995, 40.002],
]],
None,
False,
)
# Show region on the map.
m.set_center(-110, 40, 16)
m.add_layer(ee.FeatureCollection([region]).style(color='00FF0022'))
# Perform sampling convert image pixels to features.
samples = image.sample(
region=region,
# Default (False) is no geometries in the output.
# When set to True, each feature has a Point geometry at the center of the
# image pixel.
geometries=True,
# The scale is not specified, so the resolution of the image will be used,
# and there is a feature for every pixel. If we give a scale parameter, the
# image will be resampled and there will be more or fewer features.
#
# scale=200,
)
def scale_point_size(feature):
elevation = feature.getNumber('elevation')
point_size = elevation.unitScale(vis_min, vis_max).multiply(15)
feature.set('style', {'pointSize': point_size})
return feature
# Visualize sample data using ee.FeatureCollection.style().
styled = samples.map(scale_point_size).style(
color='000000FF',
fillColor='00000000',
styleProperty='style',
neighborhood=6, # increase to correctly draw large points
)
m.add_layer(styled)
display(m)
# Each sample feature has a point geometry and a property named 'elevation'
# corresponding to the band named 'elevation' of the image. If there are
# multiple bands they will become multiple properties. This will print:
#
# geometry: Point (-110.01, 40.00)
# properties:
# elevation: 1639
display(samples.first())
،پیکسل های یک تصویر را نمونه برداری می کند و آنها را به عنوان FeatureCollection برمی گرداند. هر ویژگی 1 ویژگی در هر باند در تصویر ورودی خواهد داشت. توجه داشته باشید که رفتار پیشفرض حذف ویژگیهایی است که پیکسلهای پوشانده شده را قطع میکنند، که منجر به ویژگیهای با ارزش تهی میشود (به آرگومان dropNulls مراجعه کنید).
استفاده | برمی گرداند | Image. sample ( region , scale , projection , factor , numPixels , seed , dropNulls , tileScale , geometries ) | مجموعه ویژگی ها |
استدلال | تایپ کنید | جزئیات | این: image | تصویر | تصویر برای نمونه |
region | هندسه، پیش فرض: null | منطقه ای که باید از آن نمونه برداری کرد. اگر نامشخص باشد، از کل ردپای تصویر استفاده می کند. |
scale | شناور، پیش فرض: null | مقیاس اسمی بر حسب متر از برجستگی برای نمونه برداری. |
projection | Projection، پیش فرض: null | طرح ریزی که در آن نمونه برداری می شود. در صورت نامشخص، طرح ریزی اولین باند تصویر استفاده می شود. اگر علاوه بر مقیاس مشخص شده است، به مقیاس مشخص شده مجدداً مقیاس می شود. |
factor | شناور، پیش فرض: null | یک عامل نمونهبرداری فرعی، در (0، 1]. اگر مشخص شده باشد، «numPixels» نباید مشخص شود. پیشفرضها بدون نمونهگیری فرعی هستند. |
numPixels | طولانی، پیشفرض: null | تعداد تقریبی پیکسل های نمونه. در صورت مشخص شدن، «عامل» نباید مشخص شود. |
seed | عدد صحیح، پیش فرض: 0 | یک دانه تصادفی برای استفاده برای نمونه گیری فرعی. |
dropNulls | بولی، پیش فرض: درست است | برای حذف ویژگیهایی که دارای ویژگیهای تهی هستند، نتیجه را فیلتر کنید. |
tileScale | شناور، پیش فرض: 1 | یک عامل پوسته پوسته شدن مورد استفاده برای کاهش اندازه کاشی تجمع. استفاده از یک tileScale بزرگتر (مثلاً 2 یا 4) ممکن است محاسباتی را فعال کند که با پیش فرض حافظه آنها تمام می شود. |
geometries | بولی، پیش فرض: نادرست | اگر درست باشد، مرکز پیکسل نمونه برداری شده را به عنوان ویژگی هندسی ویژگی خروجی اضافه می کند. در غیر این صورت، هندسه ها حذف می شوند (صرفه جویی در حافظه). |
نمونه ها
ویرایشگر کد (جاوا اسکریپت)
// Demonstrate extracting pixels from an image as features with
// ee.Image.sample(), and show how the features are aligned with the pixels.
// An image with one band of elevation data.
var image = ee.Image('CGIAR/SRTM90_V4');
var VIS_MIN = 1620;
var VIS_MAX = 1650;
Map.addLayer(image, {min: VIS_MIN, max: VIS_MAX}, 'SRTM');
// Region to sample.
var region = ee.Geometry.Polygon(
[[[-110.006, 40.002],
[-110.006, 39.999],
[-109.995, 39.999],
[-109.995, 40.002]]], null, false);
// Show region on the map.
Map.setCenter(-110, 40, 16);
Map.addLayer(ee.FeatureCollection([region]).style({"color": "00FF0022"}));
// Perform sampling; convert image pixels to features.
var samples = image.sample({
region: region,
// Default (false) is no geometries in the output.
// When set to true, each feature has a Point geometry at the center of the
// image pixel.
geometries: true,
// The scale is not specified, so the resolution of the image will be used,
// and there is a feature for every pixel. If we give a scale parameter, the
// image will be resampled and there will be more or fewer features.
//
// scale: 200,
});
// Visualize sample data using ee.FeatureCollection.style().
var styled = samples
.map(function (feature) {
return feature.set('style', {
pointSize: feature.getNumber('elevation').unitScale(VIS_MIN, VIS_MAX)
.multiply(15),
});
})
.style({
color: '000000FF',
fillColor: '00000000',
styleProperty: 'style',
neighborhood: 6, // increase to correctly draw large points
});
Map.addLayer(styled);
// Each sample feature has a point geometry and a property named 'elevation'
// corresponding to the band named 'elevation' of the image. If there are
// multiple bands they will become multiple properties. This will print:
//
// geometry: Point (-110.01, 40.00)
// properties:
// elevation: 1639
print(samples.first());
راه اندازی پایتون
برای اطلاعات در مورد API پایتون و استفاده از geemap
برای توسعه تعاملی به صفحه محیط پایتون مراجعه کنید.
import ee
import geemap.core as geemap
کولب (پایتون)
# Demonstrate extracting pixels from an image as features with
# ee.Image.sample(), and show how the features are aligned with the pixels.
# An image with one band of elevation data.
image = ee.Image('CGIAR/SRTM90_V4')
vis_min = 1620
vis_max = 1650
m = geemap.Map()
m.add_layer(image, {'min': vis_min, 'max': vis_max}, 'SRTM')
# Region to sample.
region = ee.Geometry.Polygon(
[[
[-110.006, 40.002],
[-110.006, 39.999],
[-109.995, 39.999],
[-109.995, 40.002],
]],
None,
False,
)
# Show region on the map.
m.set_center(-110, 40, 16)
m.add_layer(ee.FeatureCollection([region]).style(color='00FF0022'))
# Perform sampling convert image pixels to features.
samples = image.sample(
region=region,
# Default (False) is no geometries in the output.
# When set to True, each feature has a Point geometry at the center of the
# image pixel.
geometries=True,
# The scale is not specified, so the resolution of the image will be used,
# and there is a feature for every pixel. If we give a scale parameter, the
# image will be resampled and there will be more or fewer features.
#
# scale=200,
)
def scale_point_size(feature):
elevation = feature.getNumber('elevation')
point_size = elevation.unitScale(vis_min, vis_max).multiply(15)
feature.set('style', {'pointSize': point_size})
return feature
# Visualize sample data using ee.FeatureCollection.style().
styled = samples.map(scale_point_size).style(
color='000000FF',
fillColor='00000000',
styleProperty='style',
neighborhood=6, # increase to correctly draw large points
)
m.add_layer(styled)
display(m)
# Each sample feature has a point geometry and a property named 'elevation'
# corresponding to the band named 'elevation' of the image. If there are
# multiple bands they will become multiple properties. This will print:
#
# geometry: Point (-110.01, 40.00)
# properties:
# elevation: 1639
display(samples.first())
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[],[]]