24 : d( new QgsCoordinateTransformContextPrivate() )
43 d->mLock.lockForWrite();
44 d->mSourceDestDatumTransforms.clear();
46 d->mSourceDatumTransforms.clear();
47 d->mDestDatumTransforms.clear();
52 #ifdef singlesourcedest 53 QMap<QString, int> QgsCoordinateTransformContext::sourceDatumTransforms()
const 55 d->mLock.lockForRead();
56 auto res = d->mSourceDatumTransforms;
68 d->mLock.lockForWrite();
69 d->mSourceDatumTransforms.insert( crs.
authid(), transform );
76 d->mSourceDatumTransforms.remove( crs.
authid() );
79 QMap<QString, int> QgsCoordinateTransformContext::destinationDatumTransforms()
const 81 d->mLock.lockForRead();
82 auto res = d->mDestDatumTransforms;
95 d->mLock.lockForWrite();
96 d->mDestDatumTransforms.insert( crs.
authid(), transform );
103 d->mDestDatumTransforms.remove( crs.
authid() );
110 d->mLock.lockForRead();
111 auto res = d->mSourceDestDatumTransforms;
123 d->mLock.lockForWrite();
131 d->mSourceDestDatumTransforms.remove( qMakePair( sourceCrs.
authid(), destinationCrs.
authid() ) );
143 QString srcKey = source.
authid();
144 QString destKey = destination.
authid();
146 d->mLock.lockForRead();
158 #ifdef singlesourcedest 160 int srcTransform = d->mSourceDatumTransforms.value( srcKey, -1 );
161 int destTransform = d->mDestDatumTransforms.value( destKey, -1 );
163 return qMakePair( srcTransform, destTransform );
170 d->mLock.lockForWrite();
172 d->mSourceDestDatumTransforms.clear();
174 d->mSourceDatumTransforms.clear();
175 d->mDestDatumTransforms.clear();
178 const QDomNodeList contextNodes = element.elementsByTagName( QStringLiteral(
"transformContext" ) );
179 if ( contextNodes.count() < 1 )
185 missingTransforms.clear();
188 const QDomElement contextElem = contextNodes.at( 0 ).toElement();
191 const QDomNodeList srcDestNodes = contextElem.elementsByTagName( QStringLiteral(
"srcDest" ) );
192 for (
int i = 0; i < srcDestNodes.size(); ++i )
194 const QDomElement transformElem = srcDestNodes.at( i ).toElement();
195 QString key1 = transformElem.attribute( QStringLiteral(
"source" ) );
196 QString key2 = transformElem.attribute( QStringLiteral(
"dest" ) );
198 QString value1 = transformElem.attribute( QStringLiteral(
"sourceTransform" ) );
199 QString value2 = transformElem.attribute( QStringLiteral(
"destTransform" ) );
204 if ( !value1.isEmpty() )
210 missingTransforms << value1;
213 if ( !value2.isEmpty() )
219 missingTransforms << value2;
228 const QDomNodeList srcNodes = contextElem.elementsByTagName( QStringLiteral(
"source" ) );
229 for (
int i = 0; i < srcNodes .size(); ++i )
231 const QDomElement transformElem = srcNodes.at( i ).toElement();
232 QString key = transformElem.attribute( QStringLiteral(
"crs" ) );
233 QString value = transformElem.attribute( QStringLiteral(
"transform" ) );
234 if ( value.isEmpty() )
237 int datumId = QgsCoordinateTransform::projStringToDatumTransformId( value );
239 d->mSourceDatumTransforms.insert( key, datumId );
243 const QDomNodeList destNodes = contextElem.elementsByTagName( QStringLiteral(
"dest" ) );
244 for (
int i = 0; i < destNodes.size(); ++i )
246 const QDomElement transformElem = destNodes.at( i ).toElement();
247 QString key = transformElem.attribute( QStringLiteral(
"crs" ) );
248 QString value = transformElem.attribute( QStringLiteral(
"transform" ) );
249 if ( value.isEmpty() )
252 int datumId = QgsCoordinateTransform::projStringToDatumTransformId( value );
254 d->mDestDatumTransforms.insert( key, datumId );
264 d->mLock.lockForRead();
266 QDomElement contextElem = element.ownerDocument().createElement( QStringLiteral(
"transformContext" ) );
269 for (
auto it = d->mSourceDestDatumTransforms.constBegin(); it != d->mSourceDestDatumTransforms.constEnd(); ++ it )
271 QDomElement transformElem = element.ownerDocument().createElement( QStringLiteral(
"srcDest" ) );
272 transformElem.setAttribute( QStringLiteral(
"source" ), it.key().first );
273 transformElem.setAttribute( QStringLiteral(
"dest" ), it.key().second );
275 transformElem.setAttribute( QStringLiteral(
"destTransform" ), it.value().destinationTransformId < 0 ? QString() :
QgsDatumTransform::datumTransformToProj( it.value().destinationTransformId ) );
276 contextElem.appendChild( transformElem );
281 for (
auto it = d->mSourceDatumTransforms.constBegin(); it != d->mSourceDatumTransforms.constEnd(); ++ it )
283 QDomElement transformElem = element.ownerDocument().createElement( QStringLiteral(
"source" ) );
284 transformElem.setAttribute( QStringLiteral(
"crs" ), it.key() );
285 transformElem.setAttribute( QStringLiteral(
"transform" ), it.value() < 0 ? QString() : it.value() );
286 contextElem.appendChild( transformElem );
290 for (
auto it = d->mDestDatumTransforms.constBegin(); it != d->mDestDatumTransforms.constEnd(); ++ it )
292 QDomElement transformElem = element.ownerDocument().createElement( QStringLiteral(
"dest" ) );
293 transformElem.setAttribute( QStringLiteral(
"crs" ), it.key() );
294 transformElem.setAttribute( QStringLiteral(
"transform" ), it.value() < 0 ? QString() : it.value() );
295 contextElem.appendChild( transformElem );
299 element.appendChild( contextElem );
306 d->mLock.lockForWrite();
308 d->mSourceDestDatumTransforms.clear();
310 d->mSourceDatumTransforms.clear();
311 d->mDestDatumTransforms.clear();
315 settings.
beginGroup( QStringLiteral(
"/Projections" ) );
316 QStringList projectionKeys = settings.
allKeys();
319 QMap< QPair< QString, QString >, QPair< int, int > > transforms;
320 QStringList::const_iterator pkeyIt = projectionKeys.constBegin();
321 for ( ; pkeyIt != projectionKeys.constEnd(); ++pkeyIt )
323 if ( pkeyIt->contains( QLatin1String(
"srcTransform" ) ) || pkeyIt->contains( QLatin1String(
"destTransform" ) ) )
325 QStringList split = pkeyIt->split(
'/' );
326 QString srcAuthId, destAuthId;
327 if ( ! split.isEmpty() )
329 srcAuthId = split.at( 0 );
331 if ( split.size() > 1 )
333 destAuthId = split.at( 1 ).split(
'_' ).at( 0 );
336 QString proj = settings.
value( *pkeyIt ).toString();
338 if ( pkeyIt->contains( QLatin1String(
"srcTransform" ) ) )
340 transforms[ qMakePair( srcAuthId, destAuthId )].first = datumId;
342 else if ( pkeyIt->contains( QLatin1String(
"destTransform" ) ) )
344 transforms[ qMakePair( srcAuthId, destAuthId )].second = datumId;
350 QMap< QPair< QString, QString >, QPair< int, int > >::const_iterator transformIt = transforms.constBegin();
351 for ( ; transformIt != transforms.constEnd(); ++transformIt )
363 settings.
beginGroup( QStringLiteral(
"/Projections" ) );
364 QStringList groupKeys = settings.
allKeys();
365 QStringList::const_iterator groupKeyIt = groupKeys.constBegin();
366 for ( ; groupKeyIt != groupKeys.constEnd(); ++groupKeyIt )
368 if ( groupKeyIt->contains( QLatin1String(
"srcTransform" ) ) || groupKeyIt->contains( QLatin1String(
"destTransform" ) ) )
370 settings.
remove( *groupKeyIt );
374 for (
auto transformIt = d->mSourceDestDatumTransforms.constBegin(); transformIt != d->mSourceDestDatumTransforms.constEnd(); ++transformIt )
376 QString srcAuthId = transformIt.key().first;
377 QString destAuthId = transformIt.key().second;
378 int sourceDatumTransform = transformIt.value().sourceTransformId;
379 QString sourceDatumProj;
380 if ( sourceDatumTransform >= 0 )
382 int destinationDatumTransform = transformIt.value().destinationTransformId;
383 QString destinationDatumProj;
384 if ( destinationDatumTransform >= 0 )
387 settings.
setValue( srcAuthId +
"//" + destAuthId +
"_srcTransform", sourceDatumProj );
388 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.
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...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
~QgsCoordinateTransformContext()
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 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.
Contains information about the context in which a coordinate transform is executed.
QMap< QPair< QString, QString >, QgsDatumTransform::TransformPair > sourceDestinationDatumTransforms() const
Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use...
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.
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 datum transform to use when transforming from the specified s...
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.