公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Image.remap
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
从输入值到输出值的映射,由两个并行列表表示。如果输入值未包含在输入列表中,则会将其设置为 defaultValue(如果已提供),否则会将其屏蔽。请注意,由于浮点精度误差,包含浮点值的输入有时可能无法匹配。
用法 | 返回 |
---|
Image.remap(from, to, defaultValue, bandName) | 图片 |
参数 | 类型 | 详细信息 |
---|
此:image | 图片 | 应用重映射的图片。 |
from | 列表 | 源值(数字或 ee.Array)。此列表中的所有值都将映射到“to”中的相应值。 |
to | 列表 | 目标值(数字或 ee.Array)。用于替换“from”中的相应值。必须具有与“from”相同数量的值。 |
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
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\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```"]]