Skip to content

Commit

Permalink
Avoid doing unnecessary work calculating coordinate transform when the
Browse files Browse the repository at this point in the history
src and dest CRSes are equal
  • Loading branch information
nyalldawson committed Mar 13, 2020
1 parent b91bccc commit 96252f3
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/core/qgscoordinatetransform_p.cpp
Expand Up @@ -84,7 +84,8 @@ QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinat
: mSourceCRS( source )
, mDestCRS( destination )
{
calculateTransforms( context );
if ( mSourceCRS != mDestCRS )
calculateTransforms( context );
}
Q_NOWARN_DEPRECATED_POP

Expand Down Expand Up @@ -169,6 +170,14 @@ bool QgsCoordinateTransformPrivate::initialize()

mIsValid = true;

if ( mSourceCRS == mDestCRS )
{
// If the source and destination projection are the same, set the short
// circuit flag (no transform takes place)
mShortCircuit = true;
return true;
}

// init the projections (destination and source)
freeProj();

Expand Down Expand Up @@ -245,22 +254,9 @@ bool QgsCoordinateTransformPrivate::initialize()
}
#endif

//XXX todo overload == operator for QgsCoordinateReferenceSystem
//at the moment srs.parameters contains the whole proj def...soon it won't...
//if (mSourceCRS->toProj() == mDestCRS->toProj())
if ( mSourceCRS == mDestCRS )
{
// If the source and destination projection are the same, set the short
// circuit flag (no transform takes place)
mShortCircuit = true;
QgsDebugMsgLevel( QStringLiteral( "Source/Dest CRS equal, shortcircuit is set." ), 3 );
}
else
{
// Transform must take place
mShortCircuit = false;
QgsDebugMsgLevel( QStringLiteral( "Source/Dest CRS not equal, shortcircuit is not set." ), 3 );
}
// Transform must take place
mShortCircuit = false;

return mIsValid;
}

Expand Down

0 comments on commit 96252f3

Please sign in to comment.