diff --git a/autotest/gcore/tiff_read.py b/autotest/gcore/tiff_read.py index de908a0b4657..48c6910ae2d8 100755 --- a/autotest/gcore/tiff_read.py +++ b/autotest/gcore/tiff_read.py @@ -2127,6 +2127,10 @@ def test_tiff_read_md1(): md["ACQUISITIONDATETIME"] == "2010-04-01 12:00:00" ), "bad value for IMAGERY[ACQUISITIONDATETIME]" + # Check that IMD metadata domain is not sorted (https://github.com/OSGeo/gdal/issues/11470) + md = ds.GetMetadata_List("IMD") + assert md[0] == 'version="24.06"' + ds = None assert not os.path.exists("data/md_dg.tif.aux.xml") diff --git a/gcore/gdalmultidomainmetadata.cpp b/gcore/gdalmultidomainmetadata.cpp index 92a02ae7513b..2df388f436ac 100644 --- a/gcore/gdalmultidomainmetadata.cpp +++ b/gcore/gdalmultidomainmetadata.cpp @@ -94,7 +94,11 @@ CPLErr GDALMultiDomainMetadata::SetMetadata(CSLConstList papszMetadata, // we want to mark name/value pair domains as being sorted for fast // access. if (!STARTS_WITH_CI(pszDomain, "xml:") && - !STARTS_WITH_CI(pszDomain, "json:") && !EQUAL(pszDomain, "SUBDATASETS")) + !STARTS_WITH_CI(pszDomain, "json:") && + !EQUAL(pszDomain, "SUBDATASETS") + // The IMD metadata domain should not be sorted, as order matters + // when writing it back. Cf https://github.com/OSGeo/gdal/issues/11470 + && !EQUAL(pszDomain, "IMD")) { oMDList.Sort(); }