Skip to content

Commit

Permalink
datum transforms have reversible source/dest
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored and nyalldawson committed Dec 15, 2017
1 parent d18dac0 commit 4eab13d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/core/qgscoordinatetransformcontext.sip
Expand Up @@ -115,6 +115,9 @@ class QgsCoordinateTransformContext
%Docstring
Returns true if the context has a valid datum transform to use
when transforming from the specified ``source`` CRS to ``destination`` CRS.
.. note::

source and destination are reversible.
:rtype: bool
%End

Expand All @@ -126,6 +129,10 @@ class QgsCoordinateTransformContext

Returns -1 if a datum transform should not be used for the source or
destination.

.. note::

source and destination are reversible.
:rtype: QPair< int, int >
%End

Expand Down
7 changes: 7 additions & 0 deletions src/core/qgscoordinatetransformcontext.cpp
Expand Up @@ -127,6 +127,7 @@ void QgsCoordinateTransformContext::removeSourceDestinationDatumTransform( const
bool QgsCoordinateTransformContext::hasTransform( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
{
QPair<int, int> t = calculateDatumTransforms( source, destination );
// calculateDatumTransforms already takes care of switching source and destination
return t.first != -1 || t.second != -1;
}

Expand All @@ -138,6 +139,12 @@ QPair<int, int> QgsCoordinateTransformContext::calculateDatumTransforms( const Q
d->mLock.lockForRead();
// highest priority is exact match for source/dest pair
QPair< int, int > res = d->mSourceDestDatumTransforms.value( qMakePair( srcKey, destKey ), qMakePair( -1, -1 ) );
if ( res == qMakePair( -1, -1 ) )
{
// try to reverse
QPair< int, int > res2 = d->mSourceDestDatumTransforms.value( qMakePair( destKey, srcKey ), qMakePair( -1, -1 ) );
res = qMakePair( res2.second, res2.first );
}
d->mLock.unlock();
return res;

Expand Down
3 changes: 3 additions & 0 deletions src/core/qgscoordinatetransformcontext.h
Expand Up @@ -212,6 +212,7 @@ class CORE_EXPORT QgsCoordinateTransformContext
/**
* Returns true if the context has a valid datum transform to use
* when transforming from the specified \a source CRS to \a destination CRS.
* \note source and destination are reversible.
*/
bool hasTransform( const QgsCoordinateReferenceSystem &source,
const QgsCoordinateReferenceSystem &destination ) const;
Expand All @@ -222,6 +223,8 @@ class CORE_EXPORT QgsCoordinateTransformContext
*
* Returns -1 if a datum transform should not be used for the source or
* destination.
*
* \note source and destination are reversible.
*/
QPair< int, int > calculateDatumTransforms( const QgsCoordinateReferenceSystem &source,
const QgsCoordinateReferenceSystem &destination ) const;
Expand Down

0 comments on commit 4eab13d

Please sign in to comment.