''' Copy band description and color interpretation type from IN raster and BAND# to OUT raster and BAND#''' import os import sys from osgeo import gdal gdal.UseExceptions() if len(sys.argv) < 4: print(f"Usage: {sys.argv[0]} [in_file] [band#] [out_file] [band #]") sys.exit(1) infile = sys.argv[1] # source filename and path inband = int(sys.argv[2]) # source band number output = sys.argv[3] # destination file outband = int(sys.argv[4]) # destination band number data_in = gdal.Open(infile) band_in = data_in.GetRasterBand(inband) data_out = gdal.Open(output, gdal.GA_Update) band_out = data_out.GetRasterBand(outband) band_out.SetDescription(band_in.GetDescription()) band_out.SetColorInterpretation(band_in.GetColorInterpretation()) # de-reference the datasets, which triggers gdal to save data_in = None data_out = None