Skip to content

Commit af22863

Browse files
committed
Correctly handle inverse transforms with reversed axis CRS in proj 6.0 builds
This logic is too complex and fragile -- we should drop support for proj 6.0 as soon as we can, so that we can the inbuilt handling which is enabled for proj >= 6.1 only.
1 parent 2e11c34 commit af22863

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/core/qgscoordinatetransform.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -648,16 +648,16 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
648648

649649
int projResult = 0;
650650
#if PROJ_VERSION_MAJOR>=6
651-
const bool sourceAxisOrderSwapped = d->mSourceAxisOrderSwapped;
652-
const bool destinationAxisOrderSwapped = d->mDestAxisOrderSwapped;
651+
const bool sourceAxisOrderSwapped = direction == ForwardTransform ? d->mSourceAxisOrderSwapped : d->mDestAxisOrderSwapped;
653652

654653
proj_trans_generic( projData, direction == ForwardTransform ? PJ_FWD : PJ_INV,
655654
!sourceAxisOrderSwapped ? x : y, sizeof( double ), numPoints,
656655
!sourceAxisOrderSwapped ? y : x, sizeof( double ), numPoints,
657656
z, sizeof( double ), numPoints,
658657
nullptr, sizeof( double ), 0 );
659658
projResult = proj_errno( projData );
660-
if ( projResult == 0 && destinationAxisOrderSwapped )
659+
// 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)
660+
if ( projResult == 0 && ( d->mSourceAxisOrderSwapped != d->mDestAxisOrderSwapped ) )
661661
{
662662
size_t size = sizeof( double ) * numPoints;
663663
void *tmp = malloc( size );

tests/src/core/testqgscoordinatetransform.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,27 @@ void TestQgsCoordinateTransform::transform_data()
260260
QTest::addColumn<QgsCoordinateReferenceSystem>( "destCrs" );
261261
QTest::addColumn<double>( "x" );
262262
QTest::addColumn<double>( "y" );
263+
QTest::addColumn<int>( "direction" );
263264
QTest::addColumn<double>( "outX" );
264265
QTest::addColumn<double>( "outY" );
265266
QTest::addColumn<double>( "precision" );
266267

267268
QTest::newRow( "To geographic" )
268269
<< QgsCoordinateReferenceSystem::fromEpsgId( 3111 )
269270
<< QgsCoordinateReferenceSystem::fromEpsgId( 4326 )
270-
<< 2545059.0 << 2393190.0 << 145.512750 << -37.961375 << 0.000001;
271+
<< 2545059.0 << 2393190.0 << static_cast< int >( QgsCoordinateTransform::ForwardTransform ) << 145.512750 << -37.961375 << 0.000001;
271272
QTest::newRow( "From geographic" )
272273
<< QgsCoordinateReferenceSystem::fromEpsgId( 4326 )
273274
<< QgsCoordinateReferenceSystem::fromEpsgId( 3111 )
274-
<< 145.512750 << -37.961375 << 2545059.0 << 2393190.0 << 0.1;
275+
<< 145.512750 << -37.961375 << static_cast< int >( QgsCoordinateTransform::ForwardTransform ) << 2545059.0 << 2393190.0 << 0.1;
276+
QTest::newRow( "To geographic (reverse)" )
277+
<< QgsCoordinateReferenceSystem::fromEpsgId( 3111 )
278+
<< QgsCoordinateReferenceSystem::fromEpsgId( 4326 )
279+
<< 145.512750 << -37.961375 << static_cast< int >( QgsCoordinateTransform::ReverseTransform ) << 2545059.0 << 2393190.0 << 0.1;
280+
QTest::newRow( "From geographic (reverse)" )
281+
<< QgsCoordinateReferenceSystem::fromEpsgId( 4326 )
282+
<< QgsCoordinateReferenceSystem::fromEpsgId( 3111 )
283+
<< 2545058.9675128171 << 2393190.0509782173 << static_cast< int >( QgsCoordinateTransform::ReverseTransform ) << 145.512750 << -37.961375 << 0.000001;
275284
}
276285

277286
void TestQgsCoordinateTransform::transform()
@@ -280,14 +289,15 @@ void TestQgsCoordinateTransform::transform()
280289
QFETCH( QgsCoordinateReferenceSystem, destCrs );
281290
QFETCH( double, x );
282291
QFETCH( double, y );
292+
QFETCH( int, direction );
283293
QFETCH( double, outX );
284294
QFETCH( double, outY );
285295
QFETCH( double, precision );
286296

287297
double z = 0;
288298
QgsCoordinateTransform ct( sourceCrs, destCrs, QgsProject::instance() );
289299

290-
ct.transformInPlace( x, y, z );
300+
ct.transformInPlace( x, y, z, static_cast< QgsCoordinateTransform::TransformDirection >( direction ) );
291301
QGSCOMPARENEAR( x, outX, precision );
292302
QGSCOMPARENEAR( y, outY, precision );
293303
}

0 commit comments

Comments
 (0)