From 5def4c9ecc74316858389a742a3a7746fcf7e834 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 12 Dec 2022 22:59:04 +0100 Subject: [PATCH] GTiff: SRS reader: do not emit warning when reading a projected CRS with GeoTIFF keys override and northing, easting axis order (found when looking at #6905) --- autotest/gcore/data/gtiff/epsg_2193_override.tif | Bin 0 -> 443 bytes autotest/gcore/tiff_srs.py | 9 +++++++++ frmts/gtiff/gt_wkt_srs.cpp | 7 +++++++ 3 files changed, 16 insertions(+) create mode 100644 autotest/gcore/data/gtiff/epsg_2193_override.tif 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 0000000000000000000000000000000000000000..a94c100728c47c1180c6270d2a6feebe07754914 GIT binary patch literal 443 zcmebD)MDUbU|`5*5MW?nWM*IlvcVXM%>-q00OgpG#MzM8f{ZL+eIPZWNaA8hY;mX> zkohu5;=xF4zGfZc$PhCPH0qd(X)f_=loz`z1>3J^kRCYFuud?3X@k1{g23$TId zK4lItoh{ADv7sI06fQ8$$iNMznHU&=Mlmu>)aQk0liT$Wl?oEq<&T9lkvl3!HA004^- BFKPe) literal 0 HcmV?d00001 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 &&