Skip to content

Commit 3916628

Browse files
committed
Fix handling of transform-not-required in QgsCoordinateTransformContext
1 parent 40e551d commit 3916628

File tree

4 files changed

+150
-58
lines changed

4 files changed

+150
-58
lines changed

python/core/qgscoordinatetransformcontext.sip

+40-4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class QgsCoordinateTransformContext
6666
Returns the stored mapping for source CRS to associated datum transform to use.
6767
The map keys will be QgsCoordinateReferenceSystems.authid()s.
6868

69+
A datum transform of -1 indicates that no datum transform is required for the
70+
source CRS.
71+
6972
\warning This method should not be used to calculate the corresponding datum transforms
7073
to use for a coordinate transform. Instead, always use calculateDatumTransforms()
7174
to determine this.
@@ -80,7 +83,8 @@ class QgsCoordinateTransformContext
8083
Adds a new ``transform`` to use when projecting coordinates from the specified source
8184
``crs``.
8285

83-
If ``transform`` is -1, then any existing source transform for the ``crs`` will be removed.
86+
A datum ``transform`` of -1 indicates that no datum transform is required for the
87+
source CRS.
8488

8589
Returns true if the new transform was added successfully.
8690

@@ -89,14 +93,25 @@ class QgsCoordinateTransformContext
8993

9094
.. seealso:: sourceDatumTransforms()
9195
.. seealso:: addDestinationDatumTransform()
96+
.. seealso:: removeSourceDatumTransform()
9297
:rtype: bool
9398
%End
9499

100+
void removeSourceDatumTransform( const QgsCoordinateReferenceSystem &crs );
101+
%Docstring
102+
Removes the source datum transform for the specified ``crs``.
103+
.. seealso:: addSourceDatumTransform()
104+
.. seealso:: removeDestinationDatumTransform()
105+
%End
106+
95107
QMap< QString, int > destinationDatumTransforms() const;
96108
%Docstring
97109
Returns the stored mapping for destination CRS to associated datum transform to use.
98110
The map keys will be QgsCoordinateReferenceSystems.authid()s.
99111

112+
A datum transform of -1 indicates that no datum transform is required for the
113+
destination CRS.
114+
100115
\warning This method should not be used to calculate the corresponding datum transforms
101116
to use for a coordinate transform. Instead, always use calculateDatumTransforms()
102117
to determine this.
@@ -111,7 +126,8 @@ class QgsCoordinateTransformContext
111126
Adds a new ``transform`` to use when projecting coordinates to the specified destination
112127
``crs``.
113128

114-
If ``transform`` is -1, then any existing destination transform for the ``crs`` will be removed.
129+
A datum ``transform`` of -1 indicates that no datum transform is required for the
130+
destination CRS.
115131

116132
Returns true if the new transform was added successfully.
117133

@@ -120,14 +136,25 @@ class QgsCoordinateTransformContext
120136

121137
.. seealso:: destinationDatumTransforms()
122138
.. seealso:: addSourceDatumTransform()
139+
.. seealso:: removeDestinationDatumTransform()
123140
:rtype: bool
124141
%End
125142

143+
void removeDestinationDatumTransform( const QgsCoordinateReferenceSystem &crs );
144+
%Docstring
145+
Removes the destination datum transform for the specified ``crs``.
146+
.. seealso:: addDestinationDatumTransform()
147+
.. seealso:: removeSourceDatumTransform()
148+
%End
149+
126150
QMap< QPair< QString, QString>, QPair< int, int > > sourceDestinationDatumTransforms() const;
127151
%Docstring
128152
Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use.
129153
The map keys will be QgsCoordinateReferenceSystems.authid()s.
130154

155+
If either the source transform or destination transform is -1, then no datum transform is
156+
required for transformations for that source or destination.
157+
131158
\warning This method should not be used to calculate the corresponding datum transforms
132159
to use for a coordinate transform. Instead, always use calculateDatumTransforms()
133160
to determine this.
@@ -144,8 +171,8 @@ class QgsCoordinateTransformContext
144171
Adds a new ``sourceTransform`` and ``destinationTransform`` to use when projecting coordinates
145172
from the the specified ``sourceCrs`` to the specified ``destinationCrs``.
146173

147-
If either ``sourceTransform`` or ``destinationTransform`` is -1, then any existing source to destination
148-
transform for the crs pair will be removed.
174+
If either ``sourceTransform`` or ``destinationTransform`` is -1, then no datum transform is
175+
required for transformations for that source or destination.
149176

150177
Returns true if the new transform pair was added successfully.
151178

@@ -155,9 +182,18 @@ class QgsCoordinateTransformContext
155182
transforms set by addSourceDatumTransform() or addDestinationDatumTransform().
156183

157184
.. seealso:: sourceDestinationDatumTransforms()
185+
.. seealso:: removeSourceDestinationDatumTransform()
158186
:rtype: bool
159187
%End
160188

189+
void removeSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs,
190+
const QgsCoordinateReferenceSystem &destinationCrs );
191+
%Docstring
192+
Removes the source to destination datum transform pair for the specified ``sourceCrs`` and
193+
``destinationCrs``.
194+
.. seealso:: addSourceDestinationDatumTransform()
195+
%End
196+
161197
QPair< int, int > calculateDatumTransforms( const QgsCoordinateReferenceSystem &source,
162198
const QgsCoordinateReferenceSystem &destination ) const;
163199
%Docstring

src/core/qgscoordinatetransformcontext.cpp

+18-24
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,16 @@ bool QgsCoordinateTransformContext::addSourceDatumTransform( const QgsCoordinate
5858

5959
d.detach();
6060
d->mLock.lockForWrite();
61-
if ( transform == -1 )
62-
{
63-
d->mSourceDatumTransforms.remove( crs.authid() );
64-
}
65-
else
66-
{
67-
d->mSourceDatumTransforms.insert( crs.authid(), transform );
68-
}
61+
d->mSourceDatumTransforms.insert( crs.authid(), transform );
6962
d->mLock.unlock();
7063
return true;
7164
}
7265

66+
void QgsCoordinateTransformContext::removeSourceDatumTransform( const QgsCoordinateReferenceSystem &crs )
67+
{
68+
d->mSourceDatumTransforms.remove( crs.authid() );
69+
}
70+
7371
QMap<QString, int> QgsCoordinateTransformContext::destinationDatumTransforms() const
7472
{
7573
d->mLock.lockForRead();
@@ -87,18 +85,16 @@ bool QgsCoordinateTransformContext::addDestinationDatumTransform( const QgsCoord
8785
d.detach();
8886

8987
d->mLock.lockForWrite();
90-
if ( transform == -1 )
91-
{
92-
d->mDestDatumTransforms.remove( crs.authid() );
93-
}
94-
else
95-
{
96-
d->mDestDatumTransforms.insert( crs.authid(), transform );
97-
}
88+
d->mDestDatumTransforms.insert( crs.authid(), transform );
9889
d->mLock.unlock();
9990
return true;
10091
}
10192

93+
void QgsCoordinateTransformContext::removeDestinationDatumTransform( const QgsCoordinateReferenceSystem &crs )
94+
{
95+
d->mDestDatumTransforms.remove( crs.authid() );
96+
}
97+
10298
QMap<QPair<QString, QString>, QPair<int, int> > QgsCoordinateTransformContext::sourceDestinationDatumTransforms() const
10399
{
104100
d->mLock.lockForRead();
@@ -115,18 +111,16 @@ bool QgsCoordinateTransformContext::addSourceDestinationDatumTransform( const Qg
115111

116112
d.detach();
117113
d->mLock.lockForWrite();
118-
if ( sourceTransform == -1 && destinationTransform == -1 )
119-
{
120-
d->mSourceDestDatumTransforms.remove( qMakePair( sourceCrs.authid(), destinationCrs.authid() ) );
121-
}
122-
else
123-
{
124-
d->mSourceDestDatumTransforms.insert( qMakePair( sourceCrs.authid(), destinationCrs.authid() ), qMakePair( sourceTransform, destinationTransform ) );
125-
}
114+
d->mSourceDestDatumTransforms.insert( qMakePair( sourceCrs.authid(), destinationCrs.authid() ), qMakePair( sourceTransform, destinationTransform ) );
126115
d->mLock.unlock();
127116
return true;
128117
}
129118

119+
void QgsCoordinateTransformContext::removeSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs )
120+
{
121+
d->mSourceDestDatumTransforms.remove( qMakePair( sourceCrs.authid(), destinationCrs.authid() ) );
122+
}
123+
130124
QPair<int, int> QgsCoordinateTransformContext::calculateDatumTransforms( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
131125
{
132126
QString srcKey = source.authid();

src/core/qgscoordinatetransformcontext.h

+40-4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class CORE_EXPORT QgsCoordinateTransformContext
8282
* Returns the stored mapping for source CRS to associated datum transform to use.
8383
* The map keys will be QgsCoordinateReferenceSystems::authid()s.
8484
*
85+
* A datum transform of -1 indicates that no datum transform is required for the
86+
* source CRS.
87+
*
8588
* \warning This method should not be used to calculate the corresponding datum transforms
8689
* to use for a coordinate transform. Instead, always use calculateDatumTransforms()
8790
* to determine this.
@@ -95,7 +98,8 @@ class CORE_EXPORT QgsCoordinateTransformContext
9598
* Adds a new \a transform to use when projecting coordinates from the specified source
9699
* \a crs.
97100
*
98-
* If \a transform is -1, then any existing source transform for the \a crs will be removed.
101+
* A datum \a transform of -1 indicates that no datum transform is required for the
102+
* source CRS.
99103
*
100104
* Returns true if the new transform was added successfully.
101105
*
@@ -104,13 +108,24 @@ class CORE_EXPORT QgsCoordinateTransformContext
104108
*
105109
* \see sourceDatumTransforms()
106110
* \see addDestinationDatumTransform()
111+
* \see removeSourceDatumTransform()
107112
*/
108113
bool addSourceDatumTransform( const QgsCoordinateReferenceSystem &crs, int transform );
109114

115+
/**
116+
* Removes the source datum transform for the specified \a crs.
117+
* \see addSourceDatumTransform()
118+
* \see removeDestinationDatumTransform()
119+
*/
120+
void removeSourceDatumTransform( const QgsCoordinateReferenceSystem &crs );
121+
110122
/**
111123
* Returns the stored mapping for destination CRS to associated datum transform to use.
112124
* The map keys will be QgsCoordinateReferenceSystems::authid()s.
113125
*
126+
* A datum transform of -1 indicates that no datum transform is required for the
127+
* destination CRS.
128+
*
114129
* \warning This method should not be used to calculate the corresponding datum transforms
115130
* to use for a coordinate transform. Instead, always use calculateDatumTransforms()
116131
* to determine this.
@@ -124,7 +139,8 @@ class CORE_EXPORT QgsCoordinateTransformContext
124139
* Adds a new \a transform to use when projecting coordinates to the specified destination
125140
* \a crs.
126141
*
127-
* If \a transform is -1, then any existing destination transform for the \a crs will be removed.
142+
* A datum \a transform of -1 indicates that no datum transform is required for the
143+
* destination CRS.
128144
*
129145
* Returns true if the new transform was added successfully.
130146
*
@@ -133,13 +149,24 @@ class CORE_EXPORT QgsCoordinateTransformContext
133149
*
134150
* \see destinationDatumTransforms()
135151
* \see addSourceDatumTransform()
152+
* \see removeDestinationDatumTransform()
136153
*/
137154
bool addDestinationDatumTransform( const QgsCoordinateReferenceSystem &crs, int transform );
138155

156+
/**
157+
* Removes the destination datum transform for the specified \a crs.
158+
* \see addDestinationDatumTransform()
159+
* \see removeSourceDatumTransform()
160+
*/
161+
void removeDestinationDatumTransform( const QgsCoordinateReferenceSystem &crs );
162+
139163
/**
140164
* Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use.
141165
* The map keys will be QgsCoordinateReferenceSystems::authid()s.
142166
*
167+
* If either the source transform or destination transform is -1, then no datum transform is
168+
* required for transformations for that source or destination.
169+
*
143170
* \warning This method should not be used to calculate the corresponding datum transforms
144171
* to use for a coordinate transform. Instead, always use calculateDatumTransforms()
145172
* to determine this.
@@ -152,21 +179,30 @@ class CORE_EXPORT QgsCoordinateTransformContext
152179
* Adds a new \a sourceTransform and \a destinationTransform to use when projecting coordinates
153180
* from the the specified \a sourceCrs to the specified \a destinationCrs.
154181
*
155-
* If either \a sourceTransform or \a destinationTransform is -1, then any existing source to destination
156-
* transform for the crs pair will be removed.
182+
* If either \a sourceTransform or \a destinationTransform is -1, then no datum transform is
183+
* required for transformations for that source or destination.
157184
*
158185
* Returns true if the new transform pair was added successfully.
159186
*
160187
* \note Transforms set using this method will override any specific source or destination
161188
* transforms set by addSourceDatumTransform() or addDestinationDatumTransform().
162189
*
163190
* \see sourceDestinationDatumTransforms()
191+
* \see removeSourceDestinationDatumTransform()
164192
*/
165193
bool addSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs,
166194
const QgsCoordinateReferenceSystem &destinationCrs,
167195
int sourceTransform,
168196
int destinationTransform );
169197

198+
/**
199+
* Removes the source to destination datum transform pair for the specified \a sourceCrs and
200+
* \a destinationCrs.
201+
* \see addSourceDestinationDatumTransform()
202+
*/
203+
void removeSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs,
204+
const QgsCoordinateReferenceSystem &destinationCrs );
205+
170206
/**
171207
* Returns the pair of source and destination datum transforms to use
172208
* for a transform from the specified \a source CRS to \a destination CRS.

0 commit comments

Comments
 (0)