ee.Image.remap

แมปจากค่าอินพุตไปยังค่าเอาต์พุต ซึ่งแสดงด้วยรายการ 2 รายการที่ขนานกัน ค่าอินพุตที่ไม่ได้รวมอยู่ในรายการอินพุตจะได้รับการตั้งค่าเป็น defaultValue หากมีการระบุ หรือมาสก์หากไม่มีการระบุ โปรดทราบว่าอินพุตที่มีค่าจุดลอยตัวอาจไม่ตรงกันในบางครั้งเนื่องจากข้อผิดพลาดเกี่ยวกับความแม่นยำของจุดลอยตัว

การใช้งานการคืนสินค้า
Image.remap(from, to, defaultValue, bandName)รูปภาพ
อาร์กิวเมนต์ประเภทรายละเอียด
ดังนี้ imageรูปภาพรูปภาพที่จะใช้การแมปใหม่
fromรายการค่าแหล่งที่มา (ตัวเลขหรือ ee.Array) ระบบจะแมปค่าทั้งหมดในรายการนี้กับค่าที่สอดคล้องกันใน "to"
toรายการค่าปลายทาง (ตัวเลขหรือ ee.Array) ซึ่งใช้เพื่อแทนที่ค่าที่สอดคล้องกันใน "จาก" ต้องมีจำนวนค่าเท่ากับ "จาก"
defaultValueออบเจ็กต์ ค่าเริ่มต้น: nullค่าเริ่มต้นที่จะใช้แทนค่าที่ไม่ตรงกับค่าใน "from" หากไม่ได้ระบุ ระบบจะมาสก์ค่าที่ไม่ตรงกัน
bandNameสตริง ค่าเริ่มต้น: nullชื่อของแถบที่จะแมปใหม่ หากไม่ได้ระบุ ระบบจะใช้แถบแรกในรูปภาพ

ตัวอย่าง

โปรแกรมแก้ไขโค้ด (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 API และการใช้ geemap เพื่อการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

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