Anúncio: todos os projetos não comerciais registrados para usar o Earth Engine antes de
15 de abril de 2025 precisam
verificar a qualificação não comercial para manter o acesso. Se você não fizer a verificação até 26 de setembro de 2025, seu acesso poderá ser suspenso.
ee.Image.sample
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Faz amostragem dos pixels de uma imagem, retornando-os como um FeatureCollection. Cada recurso terá uma propriedade por banda na imagem de entrada. O comportamento padrão é descartar recursos que se cruzam com pixels mascarados, resultando em propriedades com valor nulo (consulte o argumento "dropNulls").
Uso | Retorna |
---|
Image.sample(region, scale, projection, factor, numPixels, seed, dropNulls, tileScale, geometries) | FeatureCollection |
Argumento | Tipo | Detalhes |
---|
isso: image | Imagem | A imagem a ser amostrada. |
region | Geometria, padrão: nulo | A região de onde a amostra será coletada. Se não for especificado, usará toda a área da imagem. |
scale | Ponto flutuante, padrão: nulo | Uma escala nominal em metros da projeção para amostragem. |
projection | Projeção, padrão: nulo | A projeção em que a amostragem será feita. Se não for especificada, será usada a projeção da primeira banda da imagem. Se especificado além da escala, será redimensionado para a escala especificada. |
factor | Ponto flutuante, padrão: nulo | Um fator de subamostragem, dentro de (0, 1]. Se especificado, "numPixels" não poderá ser especificado. O padrão é sem subamostragem. |
numPixels | Long, padrão: null | O número aproximado de pixels a serem amostrados. Se especificado, o "fator" não poderá ser especificado. |
seed | Número inteiro, padrão: 0 | Uma semente de aleatorização a ser usada para subamostragem. |
dropNulls | Booleano, padrão: verdadeiro | Faça uma pós-filtragem do resultado para descartar atributos com propriedades de valor nulo. |
tileScale | Ponto flutuante, padrão: 1 | Um fator de escalonamento usado para reduzir o tamanho do bloco de agregação. Usar um tileScale maior (por exemplo, 2 ou 4) podem ativar cálculos que ficam sem memória com o padrão. |
geometries | Booleano, padrão: falso | Se for "true", adiciona o centro do pixel amostrado como a propriedade de geometria do recurso de saída. Caso contrário, as geometrias serão omitidas (economizando memória). |
Exemplos
Editor de código (JavaScript)
// 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());
Configuração do Python
Consulte a página
Ambiente Python para informações sobre a API Python e como usar
geemap
para desenvolvimento interativo.
import ee
import geemap.core as geemap
Colab (Python)
# 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())
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
Última atualização 2025-07-26 UTC.
[null,null,["Última atualização 2025-07-26 UTC."],[],[]]