Earth Engine ha introdotto
livelli di quota non commerciali per salvaguardare le risorse di calcolo condivise e garantire prestazioni affidabili per tutti. I progetti non commerciali utilizzano il livello Community per impostazione predefinita, anche se puoi modificare il livello di un progetto in qualsiasi momento.
Google utilizza la tecnologia AI per tradurre i contenuti nella tua lingua preferita. Le traduzioni generate dall'AI potrebbero contenere errori.
ee.Image.sample
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Campiona i pixel di un'immagine e li restituisce come FeatureCollection. Ogni funzionalità avrà una proprietà per banda nell'immagine di input. Tieni presente che il comportamento predefinito consiste nell'eliminare le funzionalità che intersecano i pixel mascherati, il che comporta proprietà con valori nulli (vedi l'argomento dropNulls).
| Utilizzo | Resi |
|---|
Image.sample(region, scale, projection, factor, numPixels, seed, dropNulls, tileScale, geometries) | FeatureCollection |
| Argomento | Tipo | Dettagli |
|---|
questo: image | Immagine | L'immagine da campionare. |
region | Geometria, valore predefinito: null | La regione da cui campionare. Se non specificato, utilizza l'intera impronta dell'immagine. |
scale | Float, valore predefinito: null | Una scala nominale in metri della proiezione da campionare. |
projection | Proiezione, valore predefinito: null | La proiezione in cui campionare. Se non specificata, viene utilizzata la proiezione della prima banda dell'immagine. Se specificato in aggiunta alla scala, viene ridimensionato alla scala specificata. |
factor | Float, valore predefinito: null | Un fattore di sottocampionamento compreso nell'intervallo (0, 1]. Se specificato, "numPixels" non deve essere specificato. Il valore predefinito è nessun sottocampionamento. |
numPixels | Long, default: null | Il numero approssimativo di pixel da campionare. Se specificato, "factor" non deve essere specificato. |
seed | Numero intero, valore predefinito: 0 | Un seme di randomizzazione da utilizzare per il sottocampionamento. |
dropNulls | Booleano, valore predefinito: true | Filtra il risultato per eliminare le funzionalità con proprietà con valori nulli. |
tileScale | Virgola mobile, valore predefinito: 1 | Un fattore di scalabilità utilizzato per ridurre le dimensioni del riquadro di aggregazione; se utilizzi un valore di tileScale più grande (ad es. 2 o 4) potrebbero consentire calcoli che esauriscono la memoria con il valore predefinito. |
geometries | Booleano, valore predefinito: false | Se true, aggiunge il centro del pixel campionato come proprietà di geometria della funzionalità di output. In caso contrario, le geometrie verranno omesse (risparmiando memoria). |
Esempi
Editor di codice (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());
Configurazione di Python
Consulta la pagina
Ambiente Python per informazioni sull'API Python e sull'utilizzo di
geemap per lo sviluppo interattivo.
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())
[null,null,["Ultimo aggiornamento 2025-07-26 UTC."],[],[]]