26 : d( new QgsCoordinateTransformContextPrivate() )
46 d->mLock.lockForRead();
47 rhs.d->mLock.lockForRead();
48 bool equal = d->mSourceDestDatumTransforms == rhs.d->mSourceDestDatumTransforms;
50 rhs.d->mLock.unlock();
58 d->mLock.lockForWrite();
59 d->mSourceDestDatumTransforms.clear();
65 #if PROJ_VERSION_MAJOR>=6 68 d->mLock.lockForRead();
69 auto res = d->mSourceDestDatumTransforms;
78 #if PROJ_VERSION_MAJOR>=6 79 d->mLock.lockForRead();
80 auto res = d->mSourceDestDatumTransforms;
85 return QMap<QPair<QString, QString>, QString>();
93 #if PROJ_VERSION_MAJOR>=6 94 Q_UNUSED( sourceTransform )
95 Q_UNUSED( destinationTransform )
99 d->mLock.lockForWrite();
110 #if PROJ_VERSION_MAJOR>=6 112 d->mLock.lockForWrite();
113 d->mSourceDestDatumTransforms.insert( qMakePair( sourceCrs.
authid(), destinationCrs.
authid() ), coordinateOperationProjString );
117 Q_UNUSED( coordinateOperationProjString )
129 d->mSourceDestDatumTransforms.remove( qMakePair( sourceCrs.
authid(), destinationCrs.
authid() ) );
134 #if PROJ_VERSION_MAJOR>=6 142 return t.sourceTransformId != -1 || t.destinationTransformId != -1;
148 #if PROJ_VERSION_MAJOR>=6 150 Q_UNUSED( destination )
153 QString srcKey = source.
authid();
154 QString destKey = destination.
authid();
156 d->mLock.lockForRead();
172 #if PROJ_VERSION_MAJOR>=6 173 const QString srcKey = source.
authid();
174 const QString destKey = destination.
authid();
176 d->mLock.lockForRead();
177 QString res = d->mSourceDestDatumTransforms.value( qMakePair( srcKey, destKey ), QString() );
181 res = d->mSourceDestDatumTransforms.value( qMakePair( destKey, srcKey ), QString() );
187 Q_UNUSED( destination )
195 d->mLock.lockForWrite();
197 d->mSourceDestDatumTransforms.clear();
199 const QDomNodeList contextNodes = element.elementsByTagName( QStringLiteral(
"transformContext" ) );
200 if ( contextNodes.count() < 1 )
206 missingTransforms.clear();
209 const QDomElement contextElem = contextNodes.at( 0 ).toElement();
212 const QDomNodeList srcDestNodes = contextElem.elementsByTagName( QStringLiteral(
"srcDest" ) );
213 for (
int i = 0; i < srcDestNodes.size(); ++i )
215 const QDomElement transformElem = srcDestNodes.at( i ).toElement();
216 const QString key1 = transformElem.attribute( QStringLiteral(
"source" ) );
217 const QString key2 = transformElem.attribute( QStringLiteral(
"dest" ) );
219 #if PROJ_VERSION_MAJOR>=6 220 const QString coordinateOp = transformElem.attribute( QStringLiteral(
"coordinateOp" ) );
223 if ( !QgsProjUtils::coordinateOperationIsAvailable( coordinateOp ) )
230 d->mSourceDestDatumTransforms.insert( qMakePair( key1, key2 ), coordinateOp );
232 QString value1 = transformElem.attribute( QStringLiteral(
"sourceTransform" ) );
233 QString value2 = transformElem.attribute( QStringLiteral(
"destTransform" ) );
239 if ( !value1.isEmpty() )
245 missingTransforms << value1;
248 if ( !value2.isEmpty() )
254 missingTransforms << value2;
269 d->mLock.lockForRead();
271 QDomElement contextElem = element.ownerDocument().createElement( QStringLiteral(
"transformContext" ) );
274 for (
auto it = d->mSourceDestDatumTransforms.constBegin(); it != d->mSourceDestDatumTransforms.constEnd(); ++ it )
276 QDomElement transformElem = element.ownerDocument().createElement( QStringLiteral(
"srcDest" ) );
277 transformElem.setAttribute( QStringLiteral(
"source" ), it.key().first );
278 transformElem.setAttribute( QStringLiteral(
"dest" ), it.key().second );
279 #if PROJ_VERSION_MAJOR>=6 280 transformElem.setAttribute( QStringLiteral(
"coordinateOp" ), it.value() );
284 transformElem.setAttribute( QStringLiteral(
"destTransform" ), it.value().destinationTransformId < 0 ? QString() :
QgsDatumTransform::datumTransformToProj( it.value().destinationTransformId ) );
287 contextElem.appendChild( transformElem );
290 element.appendChild( contextElem );
297 d->mLock.lockForWrite();
299 d->mSourceDestDatumTransforms.clear();
302 settings.
beginGroup( QStringLiteral(
"/Projections" ) );
303 QStringList projectionKeys = settings.
allKeys();
306 #if PROJ_VERSION_MAJOR>=6 307 QMap< QPair< QString, QString >, QString > transforms;
309 QMap< QPair< QString, QString >, QPair< int, int > > transforms;
311 QStringList::const_iterator pkeyIt = projectionKeys.constBegin();
312 for ( ; pkeyIt != projectionKeys.constEnd(); ++pkeyIt )
314 #if PROJ_VERSION_MAJOR>=6 315 if ( pkeyIt->contains( QLatin1String(
"coordinateOp" ) ) )
317 QStringList split = pkeyIt->split(
'/' );
318 QString srcAuthId, destAuthId;
319 if ( ! split.isEmpty() )
321 srcAuthId = split.at( 0 );
323 if ( split.size() > 1 )
325 destAuthId = split.at( 1 ).split(
'_' ).at( 0 );
328 const QString proj = settings.
value( *pkeyIt ).toString();
329 transforms[ qMakePair( srcAuthId, destAuthId )] = proj;
332 if ( pkeyIt->contains( QLatin1String(
"srcTransform" ) ) || pkeyIt->contains( QLatin1String(
"destTransform" ) ) )
334 QStringList split = pkeyIt->split(
'/' );
335 QString srcAuthId, destAuthId;
336 if ( ! split.isEmpty() )
338 srcAuthId = split.at( 0 );
340 if ( split.size() > 1 )
342 destAuthId = split.at( 1 ).split(
'_' ).at( 0 );
345 QString proj = settings.
value( *pkeyIt ).toString();
349 if ( pkeyIt->contains( QLatin1String(
"srcTransform" ) ) )
351 transforms[ qMakePair( srcAuthId, destAuthId )].first = datumId;
353 else if ( pkeyIt->contains( QLatin1String(
"destTransform" ) ) )
355 transforms[ qMakePair( srcAuthId, destAuthId )].second = datumId;
362 auto transformIt = transforms.constBegin();
363 for ( ; transformIt != transforms.constEnd(); ++transformIt )
365 #if PROJ_VERSION_MAJOR>=6 366 d->mSourceDestDatumTransforms.insert( transformIt.key(), transformIt.value() );
379 settings.
beginGroup( QStringLiteral(
"/Projections" ) );
380 QStringList groupKeys = settings.
allKeys();
381 QStringList::const_iterator groupKeyIt = groupKeys.constBegin();
382 for ( ; groupKeyIt != groupKeys.constEnd(); ++groupKeyIt )
384 if ( groupKeyIt->contains( QLatin1String(
"srcTransform" ) ) || groupKeyIt->contains( QLatin1String(
"destTransform" ) ) || groupKeyIt->contains( QLatin1String(
"coordinateOp" ) ) )
386 settings.
remove( *groupKeyIt );
390 for (
auto transformIt = d->mSourceDestDatumTransforms.constBegin(); transformIt != d->mSourceDestDatumTransforms.constEnd(); ++transformIt )
392 const QString srcAuthId = transformIt.key().first;
393 const QString destAuthId = transformIt.key().second;
395 #if PROJ_VERSION_MAJOR>=6 396 const QString proj = transformIt.value();
397 settings.
setValue( srcAuthId +
"//" + destAuthId +
"_coordinateOp", proj );
399 int sourceDatumTransform = transformIt.value().sourceTransformId;
400 QString sourceDatumProj;
402 if ( sourceDatumTransform >= 0 )
404 int destinationDatumTransform = transformIt.value().destinationTransformId;
405 QString destinationDatumProj;
406 if ( destinationDatumTransform >= 0 )
410 settings.
setValue( srcAuthId +
"//" + destAuthId +
"_srcTransform", sourceDatumProj );
411 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.
void removeCoordinateOperation(const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs)
Removes the coordinate operation for the specified sourceCrs and destinationCrs.
QgsCoordinateTransformContext & operator=(const QgsCoordinateTransformContext &rhs)
Assignment operator.
This class is a composition of two QSettings instances:
Q_DECL_DEPRECATED void removeSourceDestinationDatumTransform(const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs)
Removes the source to destination datum transform pair for the specified sourceCrs and destinationCrs...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
~QgsCoordinateTransformContext()
#define Q_NOWARN_DEPRECATED_PUSH
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
QStringList allKeys() const
Returns a list of all keys, including subkeys, that can be read using the QSettings object...
bool operator==(const QgsCoordinateTransformContext &rhs) const
bool addCoordinateOperation(const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs, const QString &coordinateOperationProjString)
Adds a new coordinateOperationProjString to use when projecting coordinates from the specified source...
bool readXml(const QDomElement &element, const QgsReadWriteContext &context, QStringList &missingTransforms)
Reads the context's state from a DOM element.
QMap< QPair< QString, QString >, QString > coordinateOperations() const
Returns the stored mapping for source to destination CRS pairs to associated coordinate operation to ...
void readSettings()
Reads the context's state from application settings.
void clear()
Clears all stored transform information from the context.
Contains information about the context in which a coordinate transform is executed.
Q_DECL_DEPRECATED QMap< QPair< QString, QString >, QgsDatumTransform::TransformPair > sourceDestinationDatumTransforms() const
Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use...
Q_DECL_DEPRECATED 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 writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes the context's state to a DOM element.
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
#define Q_NOWARN_DEPRECATED_POP
QString calculateCoordinateOperation(const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination) const
Returns the Proj coordinate operation string to use when transforming from the specified source CRS t...
Q_DECL_DEPRECATED 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 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).
void writeSettings()
Write the context's state to application settings.
bool hasTransform(const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination) const
Returns true if the context has a valid coordinate operation to use when transforming from the specif...
QString authid() const
Returns the authority identifier for the CRS.
QgsCoordinateTransformContext()
Constructor for QgsCoordinateTransformContext.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.