ee.Image.remap

Mappe dai valori di input ai valori di output, rappresentati da due elenchi paralleli. Tutti i valori di input non inclusi nell'elenco di input vengono impostati su defaultValue se viene fornito o mascherati se non viene fornito. Tieni presente che a volte gli input contenenti valori in virgola mobile potrebbero non corrispondere a causa di errori di precisione della virgola mobile.

UtilizzoResi
Image.remap(from, to, defaultValue, bandName)Immagine
ArgomentoTipoDettagli
questo: imageImmagineL'immagine a cui viene applicata la rimappatura.
fromElencoI valori di origine (numeri o ee.Array). Tutti i valori di questo elenco verranno mappati al valore corrispondente in "a".
toElencoI valori di destinazione (numeri o ee.Array). Questi vengono utilizzati per sostituire i valori corrispondenti in "Da". Deve avere lo stesso numero di valori di "from".
defaultValueOggetto, valore predefinito: nullIl valore predefinito per sostituire i valori che non sono stati abbinati a un valore in "Da". Se non specificato, i valori non corrispondenti vengono mascherati.
bandNameStringa, valore predefinito: nullIl nome della banda da rimappare. Se non specificata, viene utilizzata la prima banda dell'immagine.

Esempi

Editor di codice (JavaScript)

// A land cover image.
var img = ee.Image('ESA/WorldCover/v100/2020');

// A list of pixel values to replace.
var fromList = [10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100];

// A corresponding list of replacement values (10 becomes 1, 20 becomes 2, etc).
var toList =   [ 1,  2,  2,  2,  3,  2,  4,  5,  6,  6,  2];

// Replace pixel values in the image. If the image is multi-band, only the
// remapped band will be returned. The returned band name is "remapped".
// Input image properties are retained in the output image.
var imgRemap = img.remap({
  from: fromList,
  to: toList,
  defaultValue: 0,
  bandName: 'Map'
});

// Display the original and remapped images. Note that similar land cover
// classes in the original image are grouped into aggregate classes by
// from → to value mapping.
Map.addLayer(img, null, 'Original image');
Map.addLayer(imgRemap, {
    min: 1, max: 6,
    palette:'darkgreen, lightgreen, red, white, blue, lightblue'
  }, 'Remapped image');

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)

# A land cover image.
img = ee.Image('ESA/WorldCover/v100/2020')

# A list of pixel values to replace.
from_list = [10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100]

# A corresponding list of replacement values (10 becomes 1, 20 becomes 2, etc).
to_list = [1, 2, 2, 2, 3, 2, 4, 5, 6, 6, 2]

# Replace pixel values in the image. If the image is multi-band, only the
# remapped band will be returned. The returned band name is "remapped".
# Input image properties are retained in the output image.
img_remap = img.remap(from_list, to_list, defaultValue=0, bandName='Map')

# Display the original and remapped images. Note that similar land cover
# classes in the original image are grouped into aggregate classes by
# from → to value mapping.
m = geemap.Map()
m.add_layer(img, None, 'Original image')
m.add_layer(
    img_remap,
    {
        'min': 1,
        'max': 6,
        'palette': [
            'darkgreen',
            'lightgreen',
            'red',
            'white',
            'blue',
            'lightblue',
        ],
    },
    'Remapped image',
)
m