ee.Image.remap

從輸入值對應至輸出值,以兩個平行清單表示。如果輸入清單中未包含任何輸入值,系統會將這些值設為 defaultValue (如有提供),否則會遮蓋這些值。請注意,如果輸入值包含浮點值,有時可能會因浮點精確度錯誤而無法比對。

用量傳回
Image.remap(from, to, defaultValue, bandName)圖片
引數類型詳細資料
這個:image圖片要套用重新對應的圖片。
from清單來源值 (數字或 ee.Array)。這個清單中的所有值都會對應至「to」中的相應值。
to清單目的地值 (數字或 ee.Array)。這些值會用於取代「from」中的對應值。必須與「from」的值數量相同。
defaultValue物件,預設值:null預設值,用於取代「from」中沒有相符的值。如未指定,系統會遮蓋不相符的值。
bandName字串,預設值為空值要重新對應的頻帶名稱。如未指定,系統會使用圖片中的第一個波段。

範例

程式碼編輯器 (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');

Python 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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