From 42d87a21b5f3836bae62ada28d8226e71b508086 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 21 Nov 2023 23:45:19 +0100 Subject: [PATCH] GTiff SRS reader: include VertCRS name from EPSG in CompoundCRS name if there's no citation geokey --- .../gcore/data/gtiff/compdcrs_no_citation.tif | Bin 0 -> 694 bytes autotest/gcore/tiff_srs.py | 6 ++++++ frmts/gtiff/gt_wkt_srs.cpp | 17 +++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 autotest/gcore/data/gtiff/compdcrs_no_citation.tif diff --git a/autotest/gcore/data/gtiff/compdcrs_no_citation.tif b/autotest/gcore/data/gtiff/compdcrs_no_citation.tif new file mode 100644 index 0000000000000000000000000000000000000000..658d10fe6ea384ffca8de511a2beb6f286bf24c8 GIT binary patch literal 694 zcmah`F-smn5Z&_=vG`B}Q6c0PPaKr)bK5Q`}+mULGxR#$$d zo%l0Sr?WI~&J(Y5_l|it^XARly|c4V<)$lz)x^xrjIoVXY6wEeAkL~}iW*e`N0D(c z1y6*9!&K3%g3S^vC|XT15z){=joGShT8ofCpID`AdEmPi?gn)MJ%=;}BUuhDgFGpX z1V1K|MO7o@aj@K3K_w0qBPm7Y?}KZ)|2$eK>?RjM>v36{R+cgZGhqS`1D}x z8a51pt7PnPtWj$nEpI%R5bu@JtqOijd5^bS;H??&BEOn(@^%*ZUAH~;Cg*UGKbmoB z9?zU>G=E%hzAf-xWE4&!noA0 literal 0 HcmV?d00001 diff --git a/autotest/gcore/tiff_srs.py b/autotest/gcore/tiff_srs.py index 0e0dac65fc28..1596a5427842 100755 --- a/autotest/gcore/tiff_srs.py +++ b/autotest/gcore/tiff_srs.py @@ -1418,3 +1418,9 @@ def test_tiff_srs_projection_method_unknown_of_geotiff_without_crs_code(): assert got_srs.IsSame(srs), got_srs.ExportToWkt() ds = None gdal.Unlink(filename) + + +def test_tiff_srs_build_compd_crs_name_without_citation(): + + ds = gdal.Open("data/gtiff/compdcrs_no_citation.tif") + assert ds.GetSpatialRef().GetName() == "WGS 84 / UTM zone 17N + EGM2008 height" diff --git a/frmts/gtiff/gt_wkt_srs.cpp b/frmts/gtiff/gt_wkt_srs.cpp index 7895aaf6d2f0..6e31d12d9ecd 100644 --- a/frmts/gtiff/gt_wkt_srs.cpp +++ b/frmts/gtiff/gt_wkt_srs.cpp @@ -1659,6 +1659,7 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR(GTIF *hGTIF, GTIFDefn *psDefn) if ((verticalCSType != 0 || verticalDatum != 0 || verticalUnits != 0) && (oSRS.IsGeographic() || oSRS.IsProjected() || oSRS.IsLocal())) { + std::string osVertCRSName; if (GDALGTIFKeyGetASCII(hGTIF, VerticalCitationGeoKey, citation, sizeof(citation))) { @@ -1669,12 +1670,9 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR(GTIF *hGTIF, GTIFDefn *psDefn) char *pszPipeChar = strchr(citation, '|'); if (pszPipeChar) *pszPipeChar = '\0'; + osVertCRSName = citation; } } - else - { - strcpy(citation, "unknown"); - } OGRSpatialReference oVertSRS; bool bCanBuildCompoundCRS = oSRS.GetRoot() != nullptr; @@ -1685,7 +1683,13 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR(GTIF *hGTIF, GTIFDefn *psDefn) { bCanBuildCompoundCRS = false; } + else + { + osVertCRSName = oVertSRS.GetName(); + } } + if (osVertCRSName.empty()) + osVertCRSName = "unknown"; if (bCanBuildCompoundCRS) { @@ -1718,8 +1722,9 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR(GTIF *hGTIF, GTIFDefn *psDefn) } else { - oSRS.SetNode("COMPD_CS", - (osHorizontalName + " + " + citation).c_str()); + oSRS.SetNode( + "COMPD_CS", + (osHorizontalName + " + " + osVertCRSName).c_str()); } oSRS.GetRoot()->AddChild(poOldRoot);