[gdal-dev] SetColorInterpretation() for a GeoTiff using GDAL not working

philwilkes phil.wilkes at rmit.edu.au
Fri Nov 29 02:25:18 PST 2013


I have also posted this on http://gis.stackexchange.com/ but had no joy so
thought I'd try my luck here!

I have a single band image which I would like to copy to a 3 bands of a new
image and set the ColorInterpretation to red, green and blue respectively. I
have tried two approaches, one using the GTiff driver, explained below, and
the other using the VRT driver. 

My code is; 

############################################## 

from osgeo import gdal 
import os 

IM = "path/to/image.tif" # single band image 

### read image ### 
ds = gdal.Open(IM) 
X = ds.RasterXSize 
Y = ds.RasterYSize 
band = ds.GetRasterBand(1).ReadAsArray() 

### write to 3 bands ### 
driver = gdal.GetDriverByName("GTiff") 
outPath = os.path.join(os.path.split(IM)[0], "test_image.tif") 
outIM = driver.Create(outPath, X, Y, 3, gdal.GDT_Int16) 
for i in range(1, 4): 
    outIM.GetRasterBand(i).SetRasterColorInterpretation(2 + i) 
    outIM.GetRasterBand(i).WriteArray(band) 
    print outIM.GetRasterBand(i).GetRasterColorInterpretation() 
outIM = None 

############################################## 

The output is: 

1 
0 
0 

I have also tried using the SetColorInterpretation(). 

My question is, how do I set the ColorInterpretation metatag using the GTiff
driver?



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/SetColorInterpretation-for-a-GeoTiff-using-GDAL-not-working-tp5091839.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list