Skip to content

Commit

Permalink
Merge pull request #8783 from rouault/gtiff_srs_compdcrs_name
Browse files Browse the repository at this point in the history
GTiff SRS reader: include VertCRS name from EPSG in CompoundCRS name if there's no citation geokey
  • Loading branch information
rouault authored Nov 22, 2023
2 parents 3968f9c + 42d87a2 commit fa9ff6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Binary file added autotest/gcore/data/gtiff/compdcrs_no_citation.tif
Binary file not shown.
6 changes: 6 additions & 0 deletions autotest/gcore/tiff_srs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
17 changes: 11 additions & 6 deletions frmts/gtiff/gt_wkt_srs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
{
Expand All @@ -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;
Expand All @@ -1685,7 +1683,13 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR(GTIF *hGTIF, GTIFDefn *psDefn)
{
bCanBuildCompoundCRS = false;
}
else
{
osVertCRSName = oVertSRS.GetName();
}
}
if (osVertCRSName.empty())
osVertCRSName = "unknown";

if (bCanBuildCompoundCRS)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fa9ff6f

Please sign in to comment.