Skip to content
Permalink
Browse files

Avoid doing unnecessary work calculating coordinate transform when the

src and dest CRSes are equal
  • Loading branch information
nyalldawson committed Mar 13, 2020
1 parent b91bccc commit 96252f335d9367d77137a9212abb6702f1c86291
Showing with 13 additions and 17 deletions.
  1. +13 −17 src/core/qgscoordinatetransform_p.cpp
@@ -84,7 +84,8 @@ QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinat
: mSourceCRS( source )
, mDestCRS( destination )
{
calculateTransforms( context );
if ( mSourceCRS != mDestCRS )
calculateTransforms( context );
}
Q_NOWARN_DEPRECATED_POP

@@ -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();

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

0 comments on commit 96252f3

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