diff --git a/src/core/qgscoordinatetransform.cpp b/src/core/qgscoordinatetransform.cpp index d58c8d112983..23c809019ef5 100644 --- a/src/core/qgscoordinatetransform.cpp +++ b/src/core/qgscoordinatetransform.cpp @@ -648,8 +648,7 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double * int projResult = 0; #if PROJ_VERSION_MAJOR>=6 - const bool sourceAxisOrderSwapped = d->mSourceAxisOrderSwapped; - const bool destinationAxisOrderSwapped = d->mDestAxisOrderSwapped; + const bool sourceAxisOrderSwapped = direction == ForwardTransform ? d->mSourceAxisOrderSwapped : d->mDestAxisOrderSwapped; proj_trans_generic( projData, direction == ForwardTransform ? PJ_FWD : PJ_INV, !sourceAxisOrderSwapped ? x : y, sizeof( double ), numPoints, @@ -657,7 +656,8 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double * z, sizeof( double ), numPoints, nullptr, sizeof( double ), 0 ); projResult = proj_errno( projData ); - if ( projResult == 0 && destinationAxisOrderSwapped ) + // ewww - this logic is gross. We should drop support for PROJ 6.0 as quickly as possible and dump this code (in favour of built in methods used for >=6.1 builds) + if ( projResult == 0 && ( d->mSourceAxisOrderSwapped != d->mDestAxisOrderSwapped ) ) { size_t size = sizeof( double ) * numPoints; void *tmp = malloc( size ); diff --git a/tests/src/core/testqgscoordinatetransform.cpp b/tests/src/core/testqgscoordinatetransform.cpp index 367c5d42fb30..6f171d92a156 100644 --- a/tests/src/core/testqgscoordinatetransform.cpp +++ b/tests/src/core/testqgscoordinatetransform.cpp @@ -260,6 +260,7 @@ void TestQgsCoordinateTransform::transform_data() QTest::addColumn( "destCrs" ); QTest::addColumn( "x" ); QTest::addColumn( "y" ); + QTest::addColumn( "direction" ); QTest::addColumn( "outX" ); QTest::addColumn( "outY" ); QTest::addColumn( "precision" ); @@ -267,11 +268,19 @@ void TestQgsCoordinateTransform::transform_data() QTest::newRow( "To geographic" ) << QgsCoordinateReferenceSystem::fromEpsgId( 3111 ) << QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) - << 2545059.0 << 2393190.0 << 145.512750 << -37.961375 << 0.000001; + << 2545059.0 << 2393190.0 << static_cast< int >( QgsCoordinateTransform::ForwardTransform ) << 145.512750 << -37.961375 << 0.000001; QTest::newRow( "From geographic" ) << QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) << QgsCoordinateReferenceSystem::fromEpsgId( 3111 ) - << 145.512750 << -37.961375 << 2545059.0 << 2393190.0 << 0.1; + << 145.512750 << -37.961375 << static_cast< int >( QgsCoordinateTransform::ForwardTransform ) << 2545059.0 << 2393190.0 << 0.1; + QTest::newRow( "To geographic (reverse)" ) + << QgsCoordinateReferenceSystem::fromEpsgId( 3111 ) + << QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) + << 145.512750 << -37.961375 << static_cast< int >( QgsCoordinateTransform::ReverseTransform ) << 2545059.0 << 2393190.0 << 0.1; + QTest::newRow( "From geographic (reverse)" ) + << QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) + << QgsCoordinateReferenceSystem::fromEpsgId( 3111 ) + << 2545058.9675128171 << 2393190.0509782173 << static_cast< int >( QgsCoordinateTransform::ReverseTransform ) << 145.512750 << -37.961375 << 0.000001; } void TestQgsCoordinateTransform::transform() @@ -280,6 +289,7 @@ void TestQgsCoordinateTransform::transform() QFETCH( QgsCoordinateReferenceSystem, destCrs ); QFETCH( double, x ); QFETCH( double, y ); + QFETCH( int, direction ); QFETCH( double, outX ); QFETCH( double, outY ); QFETCH( double, precision ); @@ -287,7 +297,7 @@ void TestQgsCoordinateTransform::transform() double z = 0; QgsCoordinateTransform ct( sourceCrs, destCrs, QgsProject::instance() ); - ct.transformInPlace( x, y, z ); + ct.transformInPlace( x, y, z, static_cast< QgsCoordinateTransform::TransformDirection >( direction ) ); QGSCOMPARENEAR( x, outX, precision ); QGSCOMPARENEAR( y, outY, precision ); }