Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTiff SRS reader: include VertCRS name from EPSG in CompoundCRS name if there's no citation geokey #8783

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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