公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Image.addBands
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
返回一个包含以下内容的映像:从第一个输入源复制的所有波段,以及从第二个输入源中选择的波段,还可以选择性地覆盖第一个映像中具有相同名称的波段。新映像具有第一个输入映像的元数据和足迹。
用法 | 返回 |
---|
Image.addBands(srcImg, names, overwrite) | 图片 |
参数 | 类型 | 详细信息 |
---|
此:dstImg | 图片 | 要将波段复制到的图片。 |
srcImg | 图片 | 包含要复制的频段的映像。 |
names | 列表,默认值:null | 要复制的频段名称的可选列表。如果省略了 names,系统会复制 srcImg 中的所有波段。 |
overwrite | 布尔值,默认值:false | 如果为 true,则 `srcImg` 中的波段将替换 `dstImg` 中具有相同名称的波段。否则,新波段将重命名为带有数字后缀的名称(例如,`foo` 重命名为 `foo_1`,除非 `foo_1` 已存在,否则重命名为 `foo_2`,以此类推)。 |
示例
代码编辑器 (JavaScript)
// A Sentinel-2 surface reflectance image.
var img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');
print('Original image', img);
// Scale reflectance bands and overwrite the original bands.
var reflBands = img.select('B.*').divide(10000);
img = img.addBands({
srcImg: reflBands,
overwrite: true
});
// Compute and add a single band (NDVI).
var ndvi = img.normalizedDifference(['B8', 'B4']).rename('NDVI');
img = img.addBands(ndvi);
// Compute and add multiple bands (NDWI and NBR).
var ndwi = img.normalizedDifference(['B3', 'B8']).rename('NDWI');
var nbr = img.normalizedDifference(['B8', 'B12']).rename('NBR');
var newBands = ee.Image([ndwi, nbr]);
img = img.addBands(newBands);
print('Image with added/modified bands', img);
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# A Sentinel-2 surface reflectance image.
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')
print('Original image:', img.getInfo())
# Scale reflectance bands and overwrite the original bands.
refl_bands = img.select('B.*').divide(10000)
img = img.addBands(srcImg=refl_bands, overwrite=True)
# Compute and add a single band (NDVI).
ndvi = img.normalizedDifference(['B8', 'B4']).rename('NDVI')
img = img.addBands(ndvi)
# Compute and add multiple bands (NDWI and NBR).
ndwi = img.normalizedDifference(['B3', 'B8']).rename('NDWI')
nbr = img.normalizedDifference(['B8', 'B12']).rename('NBR')
new_bands = ee.Image([ndwi, nbr])
img = img.addBands(new_bands)
print('Image with added/modified bands:', img.getInfo())
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eImage.addBands()\u003c/code\u003e returns a new image with bands copied from a source image added to a destination image.\u003c/p\u003e\n"],["\u003cp\u003eYou can select specific bands to copy using the \u003ccode\u003enames\u003c/code\u003e parameter, or copy all bands by default.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eoverwrite\u003c/code\u003e parameter controls whether bands with the same name in the destination image are replaced or renamed.\u003c/p\u003e\n"],["\u003cp\u003eThe new image retains the metadata and footprint of the destination image.\u003c/p\u003e\n"]]],["The `addBands` function combines bands from two images. It copies all bands from the first image and specified or all bands from the second. The user can select specific bands from the second image to add. If band names overlap, the `overwrite` parameter determines if bands from the second image replace those in the first; otherwise, they're renamed with a numerical suffix. The resulting image retains the first image's metadata and footprint.\n"],null,["# ee.Image.addBands\n\nReturns an image containing all bands copied from the first input and selected bands from the second input, optionally overwriting bands in the first image with the same name. The new image has the metadata and footprint from the first input image.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-----------------------------------------------------|---------|\n| Image.addBands`(srcImg, `*names* `, `*overwrite*`)` | Image |\n\n| Argument | Type | Details |\n|----------------|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `dstImg` | Image | An image into which to copy bands. |\n| `srcImg` | Image | An image containing bands to copy. |\n| `names` | List, default: null | Optional list of band names to copy. If names is omitted, all bands from srcImg will be copied over. |\n| `overwrite` | Boolean, default: false | If true, bands from \\`srcImg\\` will override bands with the same names in \\`dstImg\\`. Otherwise the new band will be renamed with a numerical suffix (\\`foo\\` to \\`foo_1\\` unless \\`foo_1\\` exists, then \\`foo_2\\` unless it exists, etc). |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A Sentinel-2 surface reflectance image.\nvar img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');\nprint('Original image', img);\n\n// Scale reflectance bands and overwrite the original bands.\nvar reflBands = img.select('B.*').divide(10000);\nimg = img.addBands({\n srcImg: reflBands,\n overwrite: true\n});\n\n// Compute and add a single band (NDVI).\nvar ndvi = img.normalizedDifference(['B8', 'B4']).rename('NDVI');\nimg = img.addBands(ndvi);\n\n// Compute and add multiple bands (NDWI and NBR).\nvar ndwi = img.normalizedDifference(['B3', 'B8']).rename('NDWI');\nvar nbr = img.normalizedDifference(['B8', 'B12']).rename('NBR');\nvar newBands = ee.Image([ndwi, nbr]);\nimg = img.addBands(newBands);\n\nprint('Image with added/modified bands', img);\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 Sentinel-2 surface reflectance image.\nimg = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')\nprint('Original image:', img.getInfo())\n\n# Scale reflectance bands and overwrite the original bands.\nrefl_bands = img.select('B.*').divide(10000)\nimg = img.addBands(srcImg=refl_bands, overwrite=True)\n\n# Compute and add a single band (NDVI).\nndvi = img.normalizedDifference(['B8', 'B4']).rename('NDVI')\nimg = img.addBands(ndvi)\n\n# Compute and add multiple bands (NDWI and NBR).\nndwi = img.normalizedDifference(['B3', 'B8']).rename('NDWI')\nnbr = img.normalizedDifference(['B8', 'B12']).rename('NBR')\nnew_bands = ee.Image([ndwi, nbr])\nimg = img.addBands(new_bands)\n\nprint('Image with added/modified bands:', img.getInfo())\n```"]]