Earth Engine 推出了
非商业配额层级 ,以保护共享计算资源并确保为所有人提供可靠的性能。非商业项目默认使用 Community
层级,但您可以随时更改项目的层级。
Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
发送反馈
ee.Image.sampleRegions
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
将与一个或多个区域相交的图片(按给定比例)的每个像素转换为特征,并以 FeatureCollection 的形式返回这些特征。每个输出特征将具有输入图片每个波段的一个属性,以及从输入特征复制的任何指定属性。
请注意,几何图形将对齐到像素中心。
用法 返回 Image. sampleRegions (collection, properties , scale , projection , tileScale , geometries )FeatureCollection
实参 类型 详细信息 this:image 图片 要采样的图片。 collectionFeatureCollection 要采样的区域。 properties列表,默认值:null 要从每个输入特征复制的属性列表。默认值为所有非系统属性。 scale浮点数,默认值:null 要采样的投影的标称比例(以米为单位)。如果未指定,则使用图片第一个波段的比例。 projection投影,默认值:null 要采样的投影。如果未指定,则使用图片第一个波段的投影。如果除了比例之外还指定了投影,则会重新缩放为指定的比例。 tileScale浮点数,默认值:1 用于减小聚合图块大小的缩放比例;使用较大的 tileScale(例如 2 或 4)可能会启用在默认情况下内存不足的计算。 geometries布尔值,默认值:false 如果为 true,则结果将包含每个采样像素的点几何图形。否则,系统将省略几何图形(节省内存)。
示例
代码编辑器 (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 )
发送反馈
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-04-20。
需要向我们提供更多信息?
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2026-04-20。"],[],["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"]]