gdal Unable to replace a RAT in GTiff C++
Failing test case on current master:
in autotest/gcore/rat.py
def test_rat_4():
ds = gdal.GetDriverByName('GTiff').Create('/tmp/rat_4.tif', 1, 1)
rat = gdal.RasterAttributeTable()
rat.CreateColumn('VALUE', gdal.GFT_Integer, gdal.GFU_MinMax)
rat.CreateColumn('CLASS', gdal.GFT_String, gdal.GFU_Name)
rat.SetValueAsInt(0, 0, 123)
rat.SetValueAsString(0, 1, 'Class1')
ds.GetRasterBand(1).SetDefaultRAT(rat)
ds = None
ds = gdal.OpenEx('/tmp/rat_4.tif')
gdal_band = ds.GetRasterBand(1)
rat = gdal_band.GetDefaultRAT()
assert rat is not None
assert rat.GetValueAsInt(0, 0) == 456
ds = None
# Replace existing RAT
rat = gdal.RasterAttributeTable()
rat.CreateColumn('VALUE', gdal.GFT_Integer, gdal.GFU_MinMax)
rat.CreateColumn('CLASS', gdal.GFT_String, gdal.GFU_Name)
rat.SetValueAsInt(0, 0, 789)
rat.SetValueAsString(0, 1, 'Class1')
ds = gdal.OpenEx('/tmp/rat_4.tif', gdal.OF_RASTER | gdal.OF_UPDATE)
ds.GetRasterBand(1).SetDefaultRAT(rat)
ds = None
ds = gdal.OpenEx('/tmp/rat_4.tif')
gdal_band = ds.GetRasterBand(1)
rat = gdal_band.GetDefaultRAT()
assert rat is not None
assert rat.GetValueAsInt(0, 0) == 789
ds = None
4 Answer:
Might be just a usage issue. You didn't open the file in update mode
==> ds = gdal.OpenEx('/tmp/rat4.tif', gdal.OFRASTER | gdal.OF_UPDATE)
Thanks, I tried that but the test still fails, I've updated the code above to reflect the changes.
I can confirm that with GDAL 3.1.4, released 2020/10/20
from OSGeo4W, the value of GetValueAsInt(0, 0)
is still 123
after running your code. I also tried to remove RAT by copying a line ds.GetRasterBand(1).SetDefaultRAT(gdal.RasterAttributeTable())
from https://github.com/OSGeo/gdal/blob/master/autotest/gcore/rat.py but that does not delete the rat4.tif.aux.xml file and RAT is still there when rat4.tif is opened next time.
Thanks, I tried that but the test still fails, I've updated the code above to reflect the changes.
actually that was a bad suggestion of mine. RAT in TIFF is handled by the PAM / .aux.xml code and updates in .aux.xml files can be done, for good or worse, even when the dataset is opened in read-only mode
Read next
- Crash when combined with react-native-picker/picker and problems in navigation in 3.0.0 and 3.0.1 - react-native-tab-view
- Add content object in @ApiBody - TypeScript swagger
- Feature request: [Strato] set custom MX Record - Go ddns-updater
- usingFastIndex: indexes may be created while restore is in progress - C mydumper
- PDFObject Support for setting title attribute on embed element - JavaScript
- getblocktemplate doesn't return 'vbavailable' and 'vbrequired' fields for BIP9 voting - bitcoin-abc
- Can't access sogo - PHP mailcow-dockerized
- Started getting crash on ios after updating to latest version. - Java react-native-track-player