diff --git a/autotest/gcore/data/gtiff/epsg_2193_override.tif b/autotest/gcore/data/gtiff/epsg_2193_override.tif new file mode 100644 index 000000000000..a94c100728c4 Binary files /dev/null and b/autotest/gcore/data/gtiff/epsg_2193_override.tif differ diff --git a/autotest/gcore/tiff_srs.py b/autotest/gcore/tiff_srs.py index 4db2987945b3..a215ec07b9c6 100755 --- a/autotest/gcore/tiff_srs.py +++ b/autotest/gcore/tiff_srs.py @@ -1203,3 +1203,12 @@ def test_tiff_srs_try_write_derived_projected(): ds = None gdal.Unlink(tmpfile) + + +def test_tiff_srs_epsg_2193_override(): + + ds = gdal.Open("data/gtiff/epsg_2193_override.tif") + gdal.ErrorReset() + srs = ds.GetSpatialRef() + assert gdal.GetLastErrorMsg() == "", srs.ExportToWkt(["FORMAT=WKT2_2019"]) + assert srs.GetAuthorityCode(None) == "2193" diff --git a/frmts/gtiff/gt_wkt_srs.cpp b/frmts/gtiff/gt_wkt_srs.cpp index db40b085318d..853566923480 100644 --- a/frmts/gtiff/gt_wkt_srs.cpp +++ b/frmts/gtiff/gt_wkt_srs.cpp @@ -1518,9 +1518,16 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR( GTIF *hGTIF, GTIFDefn * psDefn ) if( psDefn->Model == ModelTypeProjected && psDefn->PCS != KvUserDefined && !bGotFromEPSG ) { + OGRSpatialReference oSRSTest(oSRS); OGRSpatialReference oSRSTmp; + const bool bPCSCodeValid = oSRSTmp.importFromEPSG(psDefn->PCS) == OGRERR_NONE; oSRSTmp.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); + + // Force axis to avoid issues with SRS with northing, easting order + oSRSTest.SetAxes(nullptr, "X", OAO_East, "Y", OAO_North); + oSRSTmp.SetAxes(nullptr, "X", OAO_East, "Y", OAO_North); + const std::string osGTiffSRSSource = CPLGetConfigOption("GTIFF_SRS_SOURCE", ""); const char* const apszOptions[] = { "IGNORE_DATA_AXIS_TO_SRS_AXIS_MAPPING=YES", nullptr }; if( !bHasWarnedInconsistentGeogCRSEPSG &&