Skip to content

Commit

Permalink
GTiff: fix to not delete DIMAP XML files when cleaning overviews on a…
Browse files Browse the repository at this point in the history
… DIMAP2 GeoTIFF file with external overviews
  • Loading branch information
rouault committed Sep 24, 2024
1 parent 9f8fea1 commit 664799a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions autotest/gcore/tiff_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -5327,3 +5327,25 @@ def test_tiff_read_unrecognized_color_interpretation():
ds = gdal.Open("data/gtiff/unknown_colorinterp.tif")
assert ds.GetRasterBand(1).GetColorInterpretation() == gdal.GCI_Undefined
assert ds.GetRasterBand(1).GetMetadataItem("COLOR_INTERPRETATION") == "XXXX"


###############################################################################
# Check that cleaning overviews on a DIMAP2 GeoTIFF file with external overviews
# does not cause the DIMAP XML file to be cleaned


def test_tiff_read_ovr_dimap_pleiades(tmp_path):

shutil.copytree("../gdrivers/data/dimap2/bundle", tmp_path / "bundle")
filename = str(tmp_path / "bundle" / "IMG_foo_R1C1.TIF")
ds = gdal.Open(filename)
ds.BuildOverviews("NEAR", [2])
ds = None
ds = gdal.Open(filename + ".ovr")
assert ds.GetFileList() == [filename + ".ovr"]
ds = None
ds = gdal.Open(filename)
ds.BuildOverviews("", [])
ds = None
# Check that cleaning overviews did not suppress the DIMAP XML file
assert os.path.exists(tmp_path / "bundle" / "DIM_foo.XML")
12 changes: 12 additions & 0 deletions frmts/gtiff/gtiffdataset_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6653,6 +6653,18 @@ void GTiffDataset::LoadMetadata()
return;
m_bIMDRPCMetadataLoaded = true;

if (EQUAL(CPLGetExtension(GetDescription()), "ovr"))
{
// Do not attempt to retrieve metadata files on .tif.ovr files.
// For example the Pleiades metadata reader might wrongly associate a
// DIM_xxx.XML file that was meant to be associated with the main
// TIFF file. The consequence of that wrong association is that if
// one cleans overviews, then the Delete() method would then delete
// that DIM_xxx.XML file since it would be reported in the GetFileList()
// of the overview dataset.
return;
}

GDALMDReaderManager mdreadermanager;
GDALMDReaderBase *mdreader = mdreadermanager.GetReader(
m_pszFilename, oOvManager.GetSiblingFiles(), MDR_ANY);
Expand Down

0 comments on commit 664799a

Please sign in to comment.