24 : d( new QgsCoordinateTransformContextPrivate() )
44 d->mLock.lockForRead();
45 rhs.d->mLock.lockForRead();
46 bool equal = d->mSourceDestDatumTransforms == rhs.d->mSourceDestDatumTransforms;
48 rhs.d->mLock.unlock();
56 d->mLock.lockForWrite();
57 d->mSourceDestDatumTransforms.clear();
59 d->mSourceDatumTransforms.clear();
60 d->mDestDatumTransforms.clear();
65 #ifdef singlesourcedest 66 QMap<QString, int> QgsCoordinateTransformContext::sourceDatumTransforms()
const 68 d->mLock.lockForRead();
69 auto res = d->mSourceDatumTransforms;
81 d->mLock.lockForWrite();
82 d->mSourceDatumTransforms.insert( crs.
authid(), transform );
89 d->mSourceDatumTransforms.remove( crs.
authid() );
92 QMap<QString, int> QgsCoordinateTransformContext::destinationDatumTransforms()
const 94 d->mLock.lockForRead();
95 auto res = d->mDestDatumTransforms;
108 d->mLock.lockForWrite();
109 d->mDestDatumTransforms.insert( crs.
authid(), transform );
116 d->mDestDatumTransforms.remove( crs.
authid() );
123 d->mLock.lockForRead();
124 auto res = d->mSourceDestDatumTransforms;
136 d->mLock.lockForWrite();
144 d->mSourceDestDatumTransforms.remove( qMakePair( sourceCrs.
authid(), destinationCrs.
authid() ) );
156 QString srcKey = source.
authid();
157 QString destKey = destination.
authid();
159 d->mLock.lockForRead();
171 #ifdef singlesourcedest 173 int srcTransform = d->mSourceDatumTransforms.value( srcKey, -1 );
174 int destTransform = d->mDestDatumTransforms.value( destKey, -1 );
176 return qMakePair( srcTransform, destTransform );
183 d->mLock.lockForWrite();
185 d->mSourceDestDatumTransforms.clear();
187 d->mSourceDatumTransforms.clear();
188 d->mDestDatumTransforms.clear();
191 const QDomNodeList contextNodes = element.elementsByTagName( QStringLiteral(
"transformContext" ) );
192 if ( contextNodes.count() < 1 )
198 missingTransforms.clear();
201 const QDomElement contextElem = contextNodes.at( 0 ).toElement();
204 const QDomNodeList srcDestNodes = contextElem.elementsByTagName( QStringLiteral(
"srcDest" ) );
205 for (
int i = 0; i < srcDestNodes.size(); ++i )
207 const QDomElement transformElem = srcDestNodes.at( i ).toElement();
208 QString key1 = transformElem.attribute( QStringLiteral(
"source" ) );
209 QString key2 = transformElem.attribute( QStringLiteral(
"dest" ) );
211 QString value1 = transformElem.attribute( QStringLiteral(
"sourceTransform" ) );
212 QString value2 = transformElem.attribute( QStringLiteral(
"destTransform" ) );
217 if ( !value1.isEmpty() )
223 missingTransforms << value1;
226 if ( !value2.isEmpty() )
232 missingTransforms << value2;
241 const QDomNodeList srcNodes = contextElem.elementsByTagName( QStringLiteral(
"source" ) );
242 for (
int i = 0; i < srcNodes .size(); ++i )
244 const QDomElement transformElem = srcNodes.at( i ).toElement();
245 QString key = transformElem.attribute( QStringLiteral(
"crs" ) );
246 QString value = transformElem.attribute( QStringLiteral(
"transform" ) );
247 if ( value.isEmpty() )
250 int datumId = QgsCoordinateTransform::projStringToDatumTransformId( value );
252 d->mSourceDatumTransforms.insert( key, datumId );
256 const QDomNodeList destNodes = contextElem.elementsByTagName( QStringLiteral(
"dest" ) );
257 for (
int i = 0; i < destNodes.size(); ++i )
259 const QDomElement transformElem = destNodes.at( i ).toElement();
260 QString key = transformElem.attribute( QStringLiteral(
"crs" ) );
261 QString value = transformElem.attribute( QStringLiteral(
"transform" ) );
262 if ( value.isEmpty() )
265 int datumId = QgsCoordinateTransform::projStringToDatumTransformId( value );
267 d->mDestDatumTransforms.insert( key, datumId );
277 d->mLock.lockForRead();
279 QDomElement contextElem = element.ownerDocument().createElement( QStringLiteral(
"transformContext" ) );
282 for (
auto it = d->mSourceDestDatumTransforms.constBegin(); it != d->mSourceDestDatumTransforms.constEnd(); ++ it )
284 QDomElement transformElem = element.ownerDocument().createElement( QStringLiteral(
"srcDest" ) );
285 transformElem.setAttribute( QStringLiteral(
"source" ), it.key().first );
286 transformElem.setAttribute( QStringLiteral(
"dest" ), it.key().second );
288 transformElem.setAttribute( QStringLiteral(
"destTransform" ), it.value().destinationTransformId < 0 ? QString() :
QgsDatumTransform::datumTransformToProj( it.value().destinationTransformId ) );
289 contextElem.appendChild( transformElem );
294 for (
auto it = d->mSourceDatumTransforms.constBegin(); it != d->mSourceDatumTransforms.constEnd(); ++ it )
296 QDomElement transformElem = element.ownerDocument().createElement( QStringLiteral(
"source" ) );
297 transformElem.setAttribute( QStringLiteral(
"crs" ), it.key() );
298 transformElem.setAttribute( QStringLiteral(
"transform" ), it.value() < 0 ? QString() : it.value() );
299 contextElem.appendChild( transformElem );
303 for (
auto it = d->mDestDatumTransforms.constBegin(); it != d->mDestDatumTransforms.constEnd(); ++ it )
305 QDomElement transformElem = element.ownerDocument().createElement( QStringLiteral(
"dest" ) );
306 transformElem.setAttribute( QStringLiteral(
"crs" ), it.key() );
307 transformElem.setAttribute( QStringLiteral(
"transform" ), it.value() < 0 ? QString() : it.value() );
308 contextElem.appendChild( transformElem );
312 element.appendChild( contextElem );
319 d->mLock.lockForWrite();
321 d->mSourceDestDatumTransforms.clear();
323 d->mSourceDatumTransforms.clear();
324 d->mDestDatumTransforms.clear();
328 settings.
beginGroup( QStringLiteral(
"/Projections" ) );
329 QStringList projectionKeys = settings.
allKeys();
332 QMap< QPair< QString, QString >, QPair< int, int > > transforms;
333 QStringList::const_iterator pkeyIt = projectionKeys.constBegin();
334 for ( ; pkeyIt != projectionKeys.constEnd(); ++pkeyIt )
336 if ( pkeyIt->contains( QLatin1String(
"srcTransform" ) ) || pkeyIt->contains( QLatin1String(
"destTransform" ) ) )
338 QStringList split = pkeyIt->split(
'/' );
339 QString srcAuthId, destAuthId;
340 if ( ! split.isEmpty() )
342 srcAuthId = split.at( 0 );
344 if ( split.size() > 1 )
346 destAuthId = split.at( 1 ).split(
'_' ).at( 0 );
349 QString proj = settings.
value( *pkeyIt ).toString();
351 if ( pkeyIt->contains( QLatin1String(
"srcTransform" ) ) )
353 transforms[ qMakePair( srcAuthId, destAuthId )].first = datumId;
355 else if ( pkeyIt->contains( QLatin1String(
"destTransform" ) ) )
357 transforms[ qMakePair( srcAuthId, destAuthId )].second = datumId;
363 QMap< QPair< QString, QString >, QPair< int, int > >::const_iterator transformIt = transforms.constBegin();
364 for ( ; transformIt != transforms.constEnd(); ++transformIt )
376 settings.
beginGroup( QStringLiteral(
"/Projections" ) );
377 QStringList groupKeys = settings.
allKeys();
378 QStringList::const_iterator groupKeyIt = groupKeys.constBegin();
379 for ( ; groupKeyIt != groupKeys.constEnd(); ++groupKeyIt )
381 if ( groupKeyIt->contains( QLatin1String(
"srcTransform" ) ) || groupKeyIt->contains( QLatin1String(
"destTransform" ) ) )
383 settings.
remove( *groupKeyIt );
387 for (
auto transformIt = d->mSourceDestDatumTransforms.constBegin(); transformIt != d->mSourceDestDatumTransforms.constEnd(); ++transformIt )
389 QString srcAuthId = transformIt.key().first;
390 QString destAuthId = transformIt.key().second;
391 int sourceDatumTransform = transformIt.value().sourceTransformId;
392 QString sourceDatumProj;
393 if ( sourceDatumTransform >= 0 )
395 int destinationDatumTransform = transformIt.value().destinationTransformId;
396 QString destinationDatumProj;
397 if ( destinationDatumTransform >= 0 )
400 settings.
setValue( srcAuthId +
"//" + destAuthId +
"_srcTransform", sourceDatumProj );
401 settings.
setValue( srcAuthId +
"//" + destAuthId +
"_destTransform", destinationDatumProj );
The class is used as a container of context for various read/write operations on other objects...
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call.
QgsCoordinateTransformContext & operator=(const QgsCoordinateTransformContext &rhs)
Assignment operator.
QStringList allKeys() const
Returns a list of all keys, including subkeys, that can be read using the QSettings object...
This class is a composition of two QSettings instances:
void removeSourceDestinationDatumTransform(const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs)
Removes the source to destination datum transform pair for the specified sourceCrs and destinationCrs...
QMap< QPair< QString, QString >, QgsDatumTransform::TransformPair > sourceDestinationDatumTransforms() const
Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use...
~QgsCoordinateTransformContext()
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
const QgsCoordinateReferenceSystem & crs
bool hasTransform(const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination) const
Returns true if the context has a valid datum transform to use when transforming from the specified s...
bool operator==(const QgsCoordinateTransformContext &rhs) const
bool readXml(const QDomElement &element, const QgsReadWriteContext &context, QStringList &missingTransforms)
Reads the context's state from a DOM element.
void readSettings()
Reads the context's state from application settings.
void clear()
Clears all stored transform information from the context.
QgsDatumTransform::TransformPair calculateDatumTransforms(const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination) const
Returns the pair of source and destination datum transforms to use for a transform from the specified...
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes the context's state to a DOM element.
Contains information about the context in which a coordinate transform is executed.
bool addSourceDestinationDatumTransform(const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs, int sourceTransformId, int destinationTransformId)
Adds a new sourceTransform and destinationTransform to use when projecting coordinates from the speci...
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
This class represents a coordinate reference system (CRS).
QString authid() const
Returns the authority identifier for the CRS.
void writeSettings()
Write the context's state to application settings.
QgsCoordinateTransformContext()
Constructor for QgsCoordinateTransformContext.