Arcpy.renameBand

920
3
Jump to solution
02-22-2022 09:46 PM
JohnHughson
New Contributor II

The function arcpy.renameBand is listed on the following article, however I have also seen mention elsewhere that the tool is not functional within ArcGIS Pro.

Raster—ArcGIS Pro | Documentation

 

Attempting to use the function yields the following:

AttributeError: module 'arcpy' has no attribute 'renameBand'

Might someone have some advice regarding the usage of this function, and if not, a viable arcpy alternative?

 

I am aware that the "Create Mosaic Dataset" can do this, however it cannot be effectively scaled as I would like the arcpy tool to do. 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor
import arcpy
im = r'C:\Data\rasters\2.png'
rast = arcpy.Raster(im)
rast.bandNames
['Band_1', 'Band_2', 'Band_3', 'Band_4']
# -- now...
rast.renameBand('Band_1', 'The_Band')
['The_Band', 'Band_2', 'Band_3', 'Band_4']

you need a raster object and renameBand is a method for that object

dir(rast)
['RAT',
snip
 'addDimension', 'appendSlices', 'bandCount', 'bandNames', 'bands', 
'blockSize', 'catalogPath', 'compressionType', 'exportImage', 'extent', 
'format', 'functions', 'getBandProperty', 'getColormap', 
'getDimensionAttributes', 'getDimensionNames', 'getDimensionValues', 
'getHistograms', 'getProperty', 'getRasterBands', 'getRasterInfo', 
'getStatistics', 'getVariableAttributes', 'hasRAT', 'hasTranspose', 'height',
 'isInteger', 'isMultidimensional', 'isTemporary', 'maximum', 'mdinfo', 
'mean', 'meanCellHeight', 'meanCellWidth', 'minimum', 'name', 'noDataValue', 
'noDataValues', 'path', 'pixelType', 'properties', 'read', 'readOnly', 
'removeVariables', 'renameBand', 'renameVariable', 'save', 'setBandProperty',
 'setColormap', 'setHistograms', 'setProperty', 'setStatistics', 
'setVariableAttributes', 'slices', 'spatialReference', 'standardDeviation', 
'uncompressedSize', 'variableNames', 'variables', 'vectorize', 'width', 
'write']

... sort of retired...

View solution in original post

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor
import arcpy
im = r'C:\Data\rasters\2.png'
rast = arcpy.Raster(im)
rast.bandNames
['Band_1', 'Band_2', 'Band_3', 'Band_4']
# -- now...
rast.renameBand('Band_1', 'The_Band')
['The_Band', 'Band_2', 'Band_3', 'Band_4']

you need a raster object and renameBand is a method for that object

dir(rast)
['RAT',
snip
 'addDimension', 'appendSlices', 'bandCount', 'bandNames', 'bands', 
'blockSize', 'catalogPath', 'compressionType', 'exportImage', 'extent', 
'format', 'functions', 'getBandProperty', 'getColormap', 
'getDimensionAttributes', 'getDimensionNames', 'getDimensionValues', 
'getHistograms', 'getProperty', 'getRasterBands', 'getRasterInfo', 
'getStatistics', 'getVariableAttributes', 'hasRAT', 'hasTranspose', 'height',
 'isInteger', 'isMultidimensional', 'isTemporary', 'maximum', 'mdinfo', 
'mean', 'meanCellHeight', 'meanCellWidth', 'minimum', 'name', 'noDataValue', 
'noDataValues', 'path', 'pixelType', 'properties', 'read', 'readOnly', 
'removeVariables', 'renameBand', 'renameVariable', 'save', 'setBandProperty',
 'setColormap', 'setHistograms', 'setProperty', 'setStatistics', 
'setVariableAttributes', 'slices', 'spatialReference', 'standardDeviation', 
'uncompressedSize', 'variableNames', 'variables', 'vectorize', 'width', 
'write']

... sort of retired...
0 Kudos
JohnHughson
New Contributor II

Thank you kindly Dan, that was very helpful!

0 Kudos
JohnHughson
New Contributor II

One side-note I will add for future users is that the script we ended up working with would not work in reference to rasters stored within a file geodatabase. When referring to a raster stored in a standard folder, it was successful.

See below the script used:

 

im = r"C:\Users\jhughson\Documents\ArcGIS\Projects\Multiband\Multi_Band.TIF"
rast = arcpy.Raster(im)
bandnames = [arcpy.Raster(b) for b in arcpy.ListRasters()]
rast.bandNames
['Band_1', 'Band_2', 'Band_3', 'Band_4']

rast = rast.renameBand('Band_1', 'The_Band')
rast = rast.renameBand('Band_2', 'The_Band2')
rast = rast.renameBand('Band_3', 'The_Band3')
rast = rast.renameBand('Band_4', 'The_Band4')
print(rast.bandNames)

0 Kudos