Skip to content

Commit

Permalink
Don't try to use a fallback transform when we've already established
Browse files Browse the repository at this point in the history
that only a single transform is possible between a CRS pair

(since we've already tried that transform, it's pointless to re-try
it and expect different results)

Avoids superious "fallback transform used" warnings when only one
operation is possible between a CRS pair
  • Loading branch information
nyalldawson committed Feb 21, 2020
1 parent 5f2660a commit 1c8aacf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/core/qgscoordinatetransform.cpp
Expand Up @@ -743,7 +743,9 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
#if PROJ_VERSION_MAJOR>=6

mFallbackOperationOccurred = false;
if ( actualRes != 0 && ( d->mAllowFallbackTransforms || mBallparkTransformsAreAppropriate ) )
if ( actualRes != 0
&& ( d->mAvailableOpCount > 1 || d->mAvailableOpCount == -1 ) // only use fallbacks if more than one operation is possible -- otherwise we've already tried it and it failed
&& ( d->mAllowFallbackTransforms || mBallparkTransformsAreAppropriate ) )
{
// fail #1 -- try with getting proj to auto-pick an appropriate coordinate operation for the points
if ( PJ *transform = d->threadLocalFallbackProjData() )
Expand Down
14 changes: 10 additions & 4 deletions src/core/qgscoordinatetransform_p.cpp
Expand Up @@ -99,6 +99,9 @@ QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinat

QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinateTransformPrivate &other )
: QSharedData( other )
#if PROJ_VERSION_MAJOR >= 6
, mAvailableOpCount( other.mAvailableOpCount )
#endif
, mIsValid( other.mIsValid )
, mShortCircuit( other.mShortCircuit )
, mSourceCRS( other.mSourceCRS )
Expand Down Expand Up @@ -139,6 +142,9 @@ void QgsCoordinateTransformPrivate::invalidate()
{
mShortCircuit = true;
mIsValid = false;
#if PROJ_VERSION_MAJOR >= 6
mAvailableOpCount = -1;
#endif
}

bool QgsCoordinateTransformPrivate::initialize()
Expand Down Expand Up @@ -387,8 +393,8 @@ ProjData QgsCoordinateTransformPrivate::threadLocalProjData()

if ( PJ_OBJ_LIST *ops = proj_create_operations( context, mSourceCRS.projObject(), mDestCRS.projObject(), operationContext ) )
{
int count = proj_list_get_count( ops );
if ( count < 1 )
mAvailableOpCount = proj_list_get_count( ops );
if ( mAvailableOpCount < 1 )
{
// huh?
int errNo = proj_context_errno( context );
Expand All @@ -401,7 +407,7 @@ ProjData QgsCoordinateTransformPrivate::threadLocalProjData()
nonAvailableError = QObject::tr( "No coordinate operations are available between these two reference systems" );
}
}
else if ( count == 1 )
else if ( mAvailableOpCount == 1 )
{
// only a single operation available. Can we use it?
transform.reset( proj_list_get( context, ops, 0 ) );
Expand Down Expand Up @@ -466,7 +472,7 @@ ProjData QgsCoordinateTransformPrivate::threadLocalProjData()
QgsDatumTransform::TransformDetails preferred;
bool missingPreferred = false;
bool stillLookingForPreferred = true;
for ( int i = 0; i < count; ++ i )
for ( int i = 0; i < mAvailableOpCount; ++ i )
{
transform.reset( proj_list_get( context, ops, i ) );
const bool isInstantiable = transform && proj_coordoperation_is_instantiable( context, transform.get() );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgscoordinatetransform_p.h
Expand Up @@ -103,6 +103,7 @@ class QgsCoordinateTransformPrivate : public QSharedData
ProjData threadLocalProjData();

#if PROJ_VERSION_MAJOR>=6
int mAvailableOpCount = -1;
ProjData threadLocalFallbackProjData();

// Only meant to be called by QgsCoordinateTransform::removeFromCacheObjectsBelongingToCurrentThread()
Expand Down

0 comments on commit 1c8aacf

Please sign in to comment.