From 43efaa5042f25d3ba284cc0cd937853e45624f76 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 5 Oct 2024 12:55:07 +0200 Subject: [PATCH] NITF: fix parsing of CSCSDB DES --- autotest/gdrivers/nitf.py | 380 ++++++++++++++++++++++++++++++++++++++ frmts/nitf/nitffile.c | 3 + 2 files changed, 383 insertions(+) diff --git a/autotest/gdrivers/nitf.py b/autotest/gdrivers/nitf.py index 608e00fb8299..e1f7491d81bf 100755 --- a/autotest/gdrivers/nitf.py +++ b/autotest/gdrivers/nitf.py @@ -4133,6 +4133,386 @@ def test_nitf_86(): assert data == expected_data +############################################################################### +# Test parsing CSCSDB DES (STDI-0002-1-v5.0 App M) + + +def test_nitf_CSCSDB(tmp_vsimem): + tre_data = "DES=CSCSDB=01U 008517261ee9-2175-4ff2-86ad-dddda1f8270c001002001824ecf8e-1041-4cce-9edb-bc92d88624ca000020050407132420050407072409.88900000031231+2.50000000000000E+03+0.00000000000000E+00+0.00000000000000E+00+2.50000000000000E+03+0.00000000000000E+00+2.50000000000000E+0300101020050407072409.8890000002451+2.01640000000000E-08+0.00000000000000E+00+2.01640000000000E-080010312005040726649.889000000001.8750000000081+7.22500000000000E-09+0.00000000000000E+00+7.22500000000000E-09100104020050407072409.889000000161+2.01640000000000E-0800105020050407072409.889000000171+1.96000000000000E-0400107000100303+4.00000000000000E+00+0.00000000000000E+00+4.00000000000000E+00+4.00000000000000E+00+0.00000000000000E+00+4.00000000000000E+00+4.00000000000000E+00+0.00000000000000E+00+4.00000000000000E+00+4.00000000000000E+00+0.00000000000000E+00+4.00000000000000E+00+4.00000000000000E+00+0.00000000000000E+00+4.00000000000000E+00+4.00000000000000E+00+0.00000000000000E+00+4.00000000000000E+00+4.00000000000000E+00+0.00000000000000E+00+4.00000000000000E+00+4.00000000000000E+00+0.00000000000000E+00+4.00000000000000E+00+4.00000000000000E+00+0.00000000000000E+00+4.00000000000000E+000910107010101.0001.0000000.00000000.000000+1.00000000000000E+03020101.0001.0000000.00000000.000000+5.00000000000000E+02030101.0001.0000000.00000000.000000+5.00000000000000E+02040101.0001.0000000.00000000.000000+5.00000000000000E+02050101.0001.0000000.00000000.000000+5.00000000000000E+02060101.0001.0000000.00000000.000000+5.00000000000000E+02070101.0001.0000000.00000000.000000+1.00000000000000E+020000000000" + + filename = str(tmp_vsimem / "test.ntf") + ds = gdal.GetDriverByName("NITF").Create(filename, 1, 1, options=[tre_data]) + ds = None + + ds = gdal.Open(filename) + data = ds.GetMetadata("xml:DES")[0] + ds = None + + expected_data = """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +""" + assert data == expected_data + + ############################################################################### # Test parsing ILLUMB TRE (STDI-0002-1-v5.0 App AL) diff --git a/frmts/nitf/nitffile.c b/frmts/nitf/nitffile.c index 4ecd78a74810..6998b77e262f 100644 --- a/frmts/nitf/nitffile.c +++ b/frmts/nitf/nitffile.c @@ -2477,6 +2477,9 @@ static const char *NITFFindValRecursive(char **papszMD, int nMDSize, pszLastUnderscore = strrchr(pszMDPrefixShortened, '_'); } CPLFree(pszMDPrefixShortened); + + if (!pszCondVal) + pszCondVal = NITFFindValFromEnd(papszMD, nMDSize, pszVar, NULL); } CPLFree(pszMDItemName);