Skip to content

Commit

Permalink
OGRCoordinateTransformation: when a WKT def contradicts its AUTHORITY…
Browse files Browse the repository at this point in the history
… node, use the WKT def (relates to OSGeo#4038)
  • Loading branch information
rouault committed Jun 29, 2021
1 parent 605d054 commit 705273f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
29 changes: 29 additions & 0 deletions autotest/osr/osr_ct.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,32 @@ def test_osr_ct_only_axis_order_different():
x, y, _ = ct.TransformPoint(2, 49, 0)
assert x == 49
assert y == 2

###############################################################################
# Test transformation for a CRS whose definition contradicts the one of the
# authority. NOTE: it is arguable that this is the correct behaviour. One
# could consider that the AUTHORITY would have precedence.

def test_osr_ct_wkt_non_consistent_with_epsg_definition():

s_wrong_axis_order = osr.SpatialReference()
s_wrong_axis_order.SetFromUserInput("""GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AXIS["Longitude",EAST],
AXIS["Latitude",NORTH],
AUTHORITY["EPSG","4326"]]""")

t = osr.SpatialReference()
t.ImportFromEPSG(4326)

ct = osr.CoordinateTransformation(s_wrong_axis_order, t)
x, y, _ = ct.TransformPoint(2, 49, 0)
assert x == 49
assert y == 2
3 changes: 2 additions & 1 deletion gdal/ogr/ogrct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,8 @@ int OGRProjCT::Initialize( const OGRSpatialReference * poSourceIn,
OGRSpatialReference oTmpSRS;
oTmpSRS.SetFromUserInput(osAuthCode);
oTmpSRS.SetDataAxisToSRSAxisMapping(poSRS->GetDataAxisToSRSAxisMapping());
if( oTmpSRS.IsSame(poSRS) )
const char* const apszOptionsIsSame[] = { "CRITERION=EQUIVALENT", nullptr };
if( oTmpSRS.IsSame(poSRS, apszOptionsIsSame) )
{
if( CanUseAuthorityDef(poSRS, &oTmpSRS, pszAuth) )
{
Expand Down

0 comments on commit 705273f

Please sign in to comment.