Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
Stay organized with collections
Save and categorize content based on your preferences.
Maps 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.
Usage
Returns
Image.remap(from, to, defaultValue, bandName)
Image
Argument
Type
Details
this: image
Image
The image to which the remapping is applied.
from
List
The source values (numbers or ee.Array). All values in this list will be mapped to the corresponding value in 'to'.
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'.
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.
bandName
String, default: null
The name of the band to remap. If not specified, the first band in the image is used.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-13 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,["Maps 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\nCode 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\nColab (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```"]]