[QGIS-Developer] Running into error 'Cannot modify tag "PhotometricInterpretation" while writing'

afernandez afernandez at odyhpc.com
Sat Feb 1 15:51:18 PST 2025


Hello,The following snippet band = gdal_ds.GetRasterBand(1) 
band.SetNoDataValue(no_data) ... band.WriteArray(data_scaled2) self.colors 
= gdal.ColorTable() self.colors.CreateColorRamp(0, (0, 0, 0), 255, (0, 0, 
0)) # or a more complex color ramp band.SetRasterColorTable(self.colors) 
band.SetRasterColorInterpretation(gdal.GCI_PaletteIndex) 
gdal_ds.FlushCache()generates the RuntimeError 'TIFFSetField?tmp/.../tif: 
Cannot modify tag "PhotometricInterpretation" while writing' when executing 
the line 'band.SetRasterColorTable(self.colors)' [it traces back to line 
5133 in gdal.py]. The confounding thing is that this error has only come up 
when upgrading to QGISv3.40 (and its corresponding updated GDAL) as I have 
run this code dozens of times with v3.34 (and previously with v3.30) 
without any issue. Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250201/e29ac2cd/attachment.htm>


More information about the QGIS-Developer mailing list