ee.Image.remap
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Ánh xạ từ các giá trị đầu vào đến các giá trị đầu ra, được biểu thị bằng hai danh sách song song. Mọi giá trị đầu vào không có trong danh sách đầu vào đều được đặt thành defaultValue nếu được cung cấp hoặc được che nếu không được cung cấp. Xin lưu ý rằng đôi khi, các đầu vào chứa giá trị dấu phẩy động có thể không khớp do lỗi về độ chính xác của dấu phẩy động.
Cách sử dụng | Giá trị trả về |
---|
Image.remap(from, to, defaultValue, bandName) | Hình ảnh |
Đối số | Loại | Thông tin chi tiết |
---|
this: image | Hình ảnh | Hình ảnh mà bạn áp dụng việc ánh xạ lại. |
from | Danh sách | Giá trị nguồn (số hoặc ee.Array). Tất cả các giá trị trong danh sách này sẽ được liên kết với giá trị tương ứng trong "to". |
to | Danh sách | Giá trị đích đến (số hoặc ee.Array). Các giá trị này được dùng để thay thế các giá trị tương ứng trong "from". Phải có cùng số lượng giá trị như "from". |
defaultValue | Đối tượng, mặc định: null | Giá trị mặc định để thay thế những giá trị không khớp với giá trị trong "from". Nếu bạn không chỉ định, các giá trị không khớp sẽ bị che khuất. |
bandName | Chuỗi, mặc định: null | Tên của dải tần cần ánh xạ lại. Nếu không chỉ định, hệ thống sẽ sử dụng dải tần đầu tiên trong hình ảnh. |
Ví dụ
Trình soạn thảo mã (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');
Thiết lập Python
Hãy xem trang
Môi trường Python để biết thông tin về API Python và cách sử dụng geemap
cho quá trình phát triển tương tác.
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
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eImage.remap()\u003c/code\u003e function transforms image pixel values by mapping values from an input list (\u003ccode\u003efrom\u003c/code\u003e) to a corresponding output list (\u003ccode\u003eto\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eUnmatched input values are either assigned a specified \u003ccode\u003edefaultValue\u003c/code\u003e or masked if no default is provided.\u003c/p\u003e\n"],["\u003cp\u003eRemapping can be applied to a specific band using the \u003ccode\u003ebandName\u003c/code\u003e parameter, otherwise, the first band is used by default.\u003c/p\u003e\n"],["\u003cp\u003ePotential floating-point precision errors might affect the matching of input values.\u003c/p\u003e\n"]]],["The `Image.remap` function replaces pixel values in an image based on two parallel lists: `from` and `to`. Values in `from` are mapped to corresponding values in `to`. Unmatched values are set to `defaultValue` if provided, otherwise they are masked. The function allows users to specify a `bandName`. It is designed to aggregate similar classes by mapping original values to new values, the remapped band name is \"remapped\".\n"],null,["# ee.Image.remap\n\nMaps from input values to output values, represented by two parallel lists. Any input values not included in the input list are either set to defaultValue if it is given or masked if it isn't. Note that inputs containing floating point values might sometimes fail to match due to floating point precision errors.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------------------------------------|---------|\n| Image.remap`(from, to, `*defaultValue* `, `*bandName*`)` | Image |\n\n| Argument | Type | Details |\n|----------------|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `image` | Image | The image to which the remapping is applied. |\n| `from` | List | The source values (numbers or ee.Array). All values in this list will be mapped to the corresponding value in 'to'. |\n| `to` | List | The destination values (numbers or ee.Array). These are used to replace the corresponding values in 'from'. Must have the same number of values as 'from'. |\n| `defaultValue` | Object, default: null | The default value to replace values that weren't matched by a value in 'from'. If not specified, unmatched values are masked out. |\n| `bandName` | String, default: null | The name of the band to remap. If not specified, the first band in the image is used. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A land cover image.\nvar img = ee.Image('ESA/WorldCover/v100/2020');\n\n// A list of pixel values to replace.\nvar fromList = [10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100];\n\n// A corresponding list of replacement values (10 becomes 1, 20 becomes 2, etc).\nvar toList = [ 1, 2, 2, 2, 3, 2, 4, 5, 6, 6, 2];\n\n// Replace pixel values in the image. If the image is multi-band, only the\n// remapped band will be returned. The returned band name is \"remapped\".\n// Input image properties are retained in the output image.\nvar imgRemap = img.remap({\n from: fromList,\n to: toList,\n defaultValue: 0,\n bandName: 'Map'\n});\n\n// Display the original and remapped images. Note that similar land cover\n// classes in the original image are grouped into aggregate classes by\n// from → to value mapping.\nMap.addLayer(img, null, 'Original image');\nMap.addLayer(imgRemap, {\n min: 1, max: 6,\n palette:'darkgreen, lightgreen, red, white, blue, lightblue'\n }, 'Remapped image');\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# A land cover image.\nimg = ee.Image('ESA/WorldCover/v100/2020')\n\n# A list of pixel values to replace.\nfrom_list = [10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100]\n\n# A corresponding list of replacement values (10 becomes 1, 20 becomes 2, etc).\nto_list = [1, 2, 2, 2, 3, 2, 4, 5, 6, 6, 2]\n\n# Replace pixel values in the image. If the image is multi-band, only the\n# remapped band will be returned. The returned band name is \"remapped\".\n# Input image properties are retained in the output image.\nimg_remap = img.remap(from_list, to_list, defaultValue=0, bandName='Map')\n\n# Display the original and remapped images. Note that similar land cover\n# classes in the original image are grouped into aggregate classes by\n# from → to value mapping.\nm = geemap.Map()\nm.add_layer(img, None, 'Original image')\nm.add_layer(\n img_remap,\n {\n 'min': 1,\n 'max': 6,\n 'palette': [\n 'darkgreen',\n 'lightgreen',\n 'red',\n 'white',\n 'blue',\n 'lightblue',\n ],\n },\n 'Remapped image',\n)\nm\n```"]]