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 000000000000..658d10fe6ea3 Binary files /dev/null and b/autotest/gcore/data/gtiff/compdcrs_no_citation.tif differ 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);