Skip to content
Permalink
Browse files

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.
  • Loading branch information
nyalldawson committed Apr 5, 2019
1 parent 2e11c34 commit af2286323a2ee70349b4ea55dd4569e64a30640b
Showing with 16 additions and 6 deletions.
  1. +3 −3 src/core/qgscoordinatetransform.cpp
  2. +13 −3 tests/src/core/testqgscoordinatetransform.cpp
@@ -648,16 +648,16 @@ 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,
!sourceAxisOrderSwapped ? y : x, sizeof( double ), numPoints,
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 );
@@ -260,18 +260,27 @@ void TestQgsCoordinateTransform::transform_data()
QTest::addColumn<QgsCoordinateReferenceSystem>( "destCrs" );
QTest::addColumn<double>( "x" );
QTest::addColumn<double>( "y" );
QTest::addColumn<int>( "direction" );
QTest::addColumn<double>( "outX" );
QTest::addColumn<double>( "outY" );
QTest::addColumn<double>( "precision" );

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,14 +289,15 @@ void TestQgsCoordinateTransform::transform()
QFETCH( QgsCoordinateReferenceSystem, destCrs );
QFETCH( double, x );
QFETCH( double, y );
QFETCH( int, direction );
QFETCH( double, outX );
QFETCH( double, outY );
QFETCH( double, precision );

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 );
}

0 comments on commit af22863

Please sign in to comment.
You can’t perform that action at this time.