Hi Lorenzo,

Attached is a short python script to copy band info from one file to another. 
It’s not a solution but might be helpful. Usage is

gdal-copy-band-info [in_file] [band #] [out_file] [band #]


cheers,

-Matt

From: gdal-dev <[email protected]> On Behalf Of Lorenzo Di 
Giacomo
Sent: July 9, 2021 7:30 AM
To: [email protected]
Subject: [gdal-dev] Lost band name during merge


*** External email: Do not click on links or attachments except from trusted 
senders. ***

******************************************************************************************



Hi, i have N netcdf OR N tiff.
I want merge them all in 1 tiff.
I do that using:
Either gdal_merge.py -separate -o ....
OR gdalbuildvrt AND gdal_translate ... Both approaches works but each band has 
a name like "band_1", "band_2" ecc. the original band name is lost.... Is there 
a way to at least keep the band name like "original_file_name_1"... Because the 
informations abouts the bands are lost and are impossibile to know which bands 
coming from which file.
Thanks!!
''' 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

_______________________________________________
gdal-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to