ee.Image.select
Selects bands from an image.
Returns an image with the selected bands.
Usage | Returns |
---|
Image.select(var_args) | Image |
Argument | Type | Details |
---|
this: image | Image | The Image instance. |
var_args | VarArgs | One of two possibilities:
- Any number of non-list arguments. All of these will be interpreted as band selectors. These can be band names, regexes, or numeric indices. E.g. selected = image.select('a', 'b', 3, 'd');
- Two lists. The first will be used as band selectors and the second as new names for the selected bands. The number of new names must match the number of selected bands. E.g. selected = image.select(['a', 4], ['newA', 'newB']);
|
Examples
// A Sentinel-2 surface reflectance image.
var img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');
print('All band names', img.bandNames());
print('Select a band by name',
img.select('B11').bandNames());
print('Select a band by index',
img.select(10).bandNames());
print('Select bands using a list',
img.select(['B11', 'B8', 'B3']).bandNames());
print('Select bands by an argument series',
img.select('B11', 'B8', 'B3').bandNames());
print('Mixing string and integer selectors is valid',
img.select(10, 'B8', 2).bandNames());
print('Rename selected bands using two corresponding lists',
img.select(['B11', 'B8', 'B3'], ['SWIR1', 'NIR', 'Green']).bandNames());
// Use regular expressions to select bands.
print('Match "QA" followed by any two characters',
img.select('QA..').bandNames());
print('Match "B" followed by any character, any number of times',
img.select('B.*').bandNames());
print('Match "B" followed by any character, and any optional third character',
img.select('B..?').bandNames());
print('Match "B" followed by a character in the range 6-8',
img.select('B[6-8]').bandNames());
print('Match "B" followed by a character in the range 1-9 and then 1-2',
img.select('B[1-9][1-2]').bandNames());
print('Match "B" or "QA" each followed by any character, any number of times.',
img.select('B.*|QA.*').bandNames());
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 Sentinel-2 surface reflectance image.
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')
print('All band names:', img.bandNames().getInfo())
print('Select a band by name:', img.select('B11').bandNames().getInfo())
print('Select a band by index:', img.select(10).bandNames().getInfo())
print('Select bands using a list:',
img.select(['B11', 'B8', 'B3']).bandNames().getInfo())
print('Select bands by an argument series:',
img.select('B11', 'B8', 'B3').bandNames().getInfo())
print('Mixing string and integer selectors is valid:',
img.select(10, 'B8', 2).bandNames().getInfo())
print('Rename selected bands using two corresponding lists:',
img.select(['B11', 'B8', 'B3'], ['SWIR1', 'NIR', 'Green'])
.bandNames().getInfo())
# Use regular expressions to select bands.
print('Match "QA" followed by any two characters:',
img.select('QA..').bandNames().getInfo())
print('Match "B" followed by any character, any number of times:',
img.select('B.*').bandNames().getInfo())
print('Match "B" followed by any character, and any optional third character',
img.select('B..?').bandNames().getInfo())
print('Match "B" followed by a character in the range 6-8',
img.select('B[6-8]').bandNames().getInfo())
print('Match "B" followed by a character in the range 1-9 and then 1-2',
img.select('B[1-9][1-2]').bandNames().getInfo())
print('Match "B" or "QA" each followed by any character, any number of times.',
img.select('B.*|QA.*').bandNames().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-02-20 UTC.
[null,null,["Last updated 2024-02-20 UTC."],[[["`Image.select()` is used to select specific bands from an image by their name, index, or using regular expressions."],["You can provide band selectors as individual arguments, a single list, or two lists (one for selectors and one for new band names)."],["This method returns a new image containing only the selected bands, potentially with renamed bands if specified."],["Regular expressions provide a powerful way to select multiple bands matching a pattern."]]],[]]