Skip to content

Commit 4eab13d

Browse files
3nidsnyalldawson
authored andcommitted
datum transforms have reversible source/dest
1 parent d18dac0 commit 4eab13d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

python/core/qgscoordinatetransformcontext.sip

+7
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ class QgsCoordinateTransformContext
115115
%Docstring
116116
Returns true if the context has a valid datum transform to use
117117
when transforming from the specified ``source`` CRS to ``destination`` CRS.
118+
.. note::
119+
120+
source and destination are reversible.
118121
:rtype: bool
119122
%End
120123

@@ -126,6 +129,10 @@ class QgsCoordinateTransformContext
126129

127130
Returns -1 if a datum transform should not be used for the source or
128131
destination.
132+
133+
.. note::
134+
135+
source and destination are reversible.
129136
:rtype: QPair< int, int >
130137
%End
131138

src/core/qgscoordinatetransformcontext.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void QgsCoordinateTransformContext::removeSourceDestinationDatumTransform( const
127127
bool QgsCoordinateTransformContext::hasTransform( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
128128
{
129129
QPair<int, int> t = calculateDatumTransforms( source, destination );
130+
// calculateDatumTransforms already takes care of switching source and destination
130131
return t.first != -1 || t.second != -1;
131132
}
132133

@@ -138,6 +139,12 @@ QPair<int, int> QgsCoordinateTransformContext::calculateDatumTransforms( const Q
138139
d->mLock.lockForRead();
139140
// highest priority is exact match for source/dest pair
140141
QPair< int, int > res = d->mSourceDestDatumTransforms.value( qMakePair( srcKey, destKey ), qMakePair( -1, -1 ) );
142+
if ( res == qMakePair( -1, -1 ) )
143+
{
144+
// try to reverse
145+
QPair< int, int > res2 = d->mSourceDestDatumTransforms.value( qMakePair( destKey, srcKey ), qMakePair( -1, -1 ) );
146+
res = qMakePair( res2.second, res2.first );
147+
}
141148
d->mLock.unlock();
142149
return res;
143150

src/core/qgscoordinatetransformcontext.h

+3
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class CORE_EXPORT QgsCoordinateTransformContext
212212
/**
213213
* Returns true if the context has a valid datum transform to use
214214
* when transforming from the specified \a source CRS to \a destination CRS.
215+
* \note source and destination are reversible.
215216
*/
216217
bool hasTransform( const QgsCoordinateReferenceSystem &source,
217218
const QgsCoordinateReferenceSystem &destination ) const;
@@ -222,6 +223,8 @@ class CORE_EXPORT QgsCoordinateTransformContext
222223
*
223224
* Returns -1 if a datum transform should not be used for the source or
224225
* destination.
226+
*
227+
* \note source and destination are reversible.
225228
*/
226229
QPair< int, int > calculateDatumTransforms( const QgsCoordinateReferenceSystem &source,
227230
const QgsCoordinateReferenceSystem &destination ) const;

0 commit comments

Comments
 (0)