ee.ImageCollection.toBands
Converts a collection to a single multi-band image containing all of the bands of every image in the collection. Output bands are named by prefixing the existing band names with the image id from which it came (e.g., 'image1_band1'). Note: The maximum number of bands is 5000.
Usage | Returns |
---|
ImageCollection.toBands() | Image |
Argument | Type | Details |
---|
this: collection | ImageCollection | The input collection. |
Examples
// A Landsat 8 TOA image collection (2 months of images at a specific point).
var col = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
.filterBounds(ee.Geometry.Point(-90.70, 34.71))
.filterDate('2020-07-01', '2020-09-01')
.select('B[4-5]'); // Get NIR and SWIR1 bands only.
print('Collection', col);
// Convert the image collection to a single multi-band image. Note that image ID
// ('system:index') is prepended to band names to delineate the source images.
var img = col.toBands();
print('Collection to bands', img);
// Band order is determined by collection order. Here, the collection is
// sorted in descending order of the date of observation (reverse of previous).
var bandOrder = col.sort('DATE_ACQUIRED', false).toBands();
print('Customized band order', bandOrder);
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
# A Landsat 8 TOA image collection (2 months of images at a specific point).
col = (
ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
.filterBounds(ee.Geometry.Point(-90.70, 34.71))
.filterDate('2020-07-01', '2020-09-01')
.select('B[4-5]')
) # Get NIR and SWIR1 bands only.
print('Collection:', col.getInfo())
# Convert the image collection to a single multi-band image. Note that image ID
# ('system:index') is prepended to band names to delineate the source images.
img = col.toBands()
print('Collection to bands:', img.getInfo())
# Band order is determined by collection order. Here, the collection is
# sorted in descending order of the date of observation (reverse of previous).
band_order = col.sort('DATE_ACQUIRED', False).toBands()
print('Customized band order:', band_order.getInfo())
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-13 UTC.
[null,null,["Last updated 2024-07-13 UTC."],[[["`toBands()` transforms an ImageCollection into a single multi-band image, combining all bands from each image within the collection."],["Band names in the output image are prefixed with the original image ID to identify their source."],["The band order in the output image reflects the order of images within the input collection, which can be controlled using `sort()`."],["There is a limit of 5000 bands for the output multi-band image."]]],["The `toBands()` method converts an ImageCollection into a single multi-band Image. Each band in the resulting image corresponds to a band from an image in the collection. The output band names are prefixed with the source image's ID. The order of bands in the output image matches the order of images in the collection. Users can sort the collection to customize the band order, however the maximum band limit is 5000.\n"]]