Skip to content

Commit

Permalink
Remove unused support for single source/dest settings in QgsCoordinat…
Browse files Browse the repository at this point in the history
…eTransformContext

This has been #ifdef'ed out since it's original implementation,
and it has no meaning in the world of Proj >= 6.0
  • Loading branch information
nyalldawson committed May 31, 2019
1 parent 0c590a1 commit c61fb85
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 398 deletions.
11 changes: 1 addition & 10 deletions python/core/auto_generated/qgscoordinatetransformcontext.sip.in
Expand Up @@ -17,17 +17,10 @@ class QgsCoordinateTransformContext
%Docstring
Contains information about the context in which a coordinate transform is executed.

The context stores various information regarding which coordinate transforms should
The context stores various information regarding which coordinate operations should
be used when transforming points from a source to destination coordinate reference
system.

The highest priority transforms are those set using addSourceDestinationDatumTransform()
and which the transform has a matching source to destination CRS pair.

Failing this, if the source CRS has a matching transform specified by
addSourceDatumTransform() then this datum transform will be used. The same logic
applies for destination CRS transforms set using addDestinationDatumTransform().

.. note::

QgsCoordinateTransformContext objects are thread safe for read and write.
Expand Down Expand Up @@ -70,8 +63,6 @@ Copy constructor
Clears all stored transform information from the context.
%End



QMap< QPair< QString, QString>, QgsDatumTransform::TransformPair > sourceDestinationDatumTransforms() const;
%Docstring
Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use.
Expand Down
26 changes: 7 additions & 19 deletions src/app/qgsdatumtransformtablewidget.cpp
Expand Up @@ -57,12 +57,7 @@ void QgsDatumTransformTableModel::removeTransform( const QModelIndexList &indexe
int QgsDatumTransformTableModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent )
return mTransformContext.sourceDestinationDatumTransforms().count()
#ifdef singlesourcedest
+ mTransformContext.sourceDatumTransforms().count()
+ mTransformContext.destinationDatumTransforms().count()
#endif
;
return mTransformContext.sourceDestinationDatumTransforms().count();
}

int QgsDatumTransformTableModel::columnCount( const QModelIndex &parent ) const
Expand All @@ -78,19 +73,12 @@ QVariant QgsDatumTransformTableModel::data( const QModelIndex &index, int role )
int sourceTransform = -1;
int destinationTransform = -1;

#ifdef singlesourcedest
if ( index.row() < mTransformContext.sourceDestinationDatumTransforms().count() )
{
#endif
QPair< QString, QString> crses = mTransformContext.sourceDestinationDatumTransforms().keys().at( index.row() );
sourceCrs = crses.first;
destinationCrs = crses.second;
const QgsDatumTransform::TransformPair transforms = mTransformContext.sourceDestinationDatumTransforms().value( crses );
sourceTransform = transforms.sourceTransformId;
destinationTransform = transforms.destinationTransformId;
#ifdef singlesourcedest
}
#endif
QPair< QString, QString> crses = mTransformContext.sourceDestinationDatumTransforms().keys().at( index.row() );
sourceCrs = crses.first;
destinationCrs = crses.second;
const QgsDatumTransform::TransformPair transforms = mTransformContext.sourceDestinationDatumTransforms().value( crses );
sourceTransform = transforms.sourceTransformId;
destinationTransform = transforms.destinationTransformId;

switch ( role )
{
Expand Down
128 changes: 0 additions & 128 deletions src/core/qgscoordinatetransformcontext.cpp
Expand Up @@ -55,69 +55,9 @@ void QgsCoordinateTransformContext::clear()
// play it safe
d->mLock.lockForWrite();
d->mSourceDestDatumTransforms.clear();
#if 0
d->mSourceDatumTransforms.clear();
d->mDestDatumTransforms.clear();
#endif
d->mLock.unlock();
}

#ifdef singlesourcedest
QMap<QString, int> QgsCoordinateTransformContext::sourceDatumTransforms() const
{
d->mLock.lockForRead();
auto res = d->mSourceDatumTransforms;
res.detach();
d->mLock.unlock();
return res;
}

bool QgsCoordinateTransformContext::addSourceDatumTransform( const QgsCoordinateReferenceSystem &crs, int transform )
{
if ( !crs.isValid() )
return false;

d.detach();
d->mLock.lockForWrite();
d->mSourceDatumTransforms.insert( crs.authid(), transform );
d->mLock.unlock();
return true;
}

void QgsCoordinateTransformContext::removeSourceDatumTransform( const QgsCoordinateReferenceSystem &crs )
{
d->mSourceDatumTransforms.remove( crs.authid() );
}

QMap<QString, int> QgsCoordinateTransformContext::destinationDatumTransforms() const
{
d->mLock.lockForRead();
auto res = d->mDestDatumTransforms;
res.detach();
d->mLock.unlock();
return res;
}

bool QgsCoordinateTransformContext::addDestinationDatumTransform( const QgsCoordinateReferenceSystem &crs, int transform )
{
if ( !crs.isValid() )
return false;

d.detach();

d->mLock.lockForWrite();
d->mDestDatumTransforms.insert( crs.authid(), transform );
d->mLock.unlock();
return true;
}

void QgsCoordinateTransformContext::removeDestinationDatumTransform( const QgsCoordinateReferenceSystem &crs )
{
d->mDestDatumTransforms.remove( crs.authid() );
}

#endif

QMap<QPair<QString, QString>, QgsDatumTransform::TransformPair> QgsCoordinateTransformContext::sourceDestinationDatumTransforms() const
{
d->mLock.lockForRead();
Expand Down Expand Up @@ -167,14 +107,6 @@ QgsDatumTransform::TransformPair QgsCoordinateTransformContext::calculateDatumTr
}
d->mLock.unlock();
return res;

#ifdef singlesourcedest
// fallback to checking src and dest separately
int srcTransform = d->mSourceDatumTransforms.value( srcKey, -1 );
int destTransform = d->mDestDatumTransforms.value( destKey, -1 );
d->mLock.unlock();
return qMakePair( srcTransform, destTransform );
#endif
}

bool QgsCoordinateTransformContext::readXml( const QDomElement &element, const QgsReadWriteContext &, QStringList &missingTransforms )
Expand All @@ -183,10 +115,6 @@ bool QgsCoordinateTransformContext::readXml( const QDomElement &element, const Q
d->mLock.lockForWrite();

d->mSourceDestDatumTransforms.clear();
#if 0
d->mSourceDatumTransforms.clear();
d->mDestDatumTransforms.clear();
#endif

const QDomNodeList contextNodes = element.elementsByTagName( QStringLiteral( "transformContext" ) );
if ( contextNodes.count() < 1 )
Expand Down Expand Up @@ -238,38 +166,6 @@ bool QgsCoordinateTransformContext::readXml( const QDomElement &element, const Q
d->mSourceDestDatumTransforms.insert( qMakePair( key1, key2 ), QgsDatumTransform::TransformPair( datumId1, datumId2 ) );
}

#if 0
// src transforms
const QDomNodeList srcNodes = contextElem.elementsByTagName( QStringLiteral( "source" ) );
for ( int i = 0; i < srcNodes .size(); ++i )
{
const QDomElement transformElem = srcNodes.at( i ).toElement();
QString key = transformElem.attribute( QStringLiteral( "crs" ) );
QString value = transformElem.attribute( QStringLiteral( "transform" ) );
if ( value.isEmpty() )
continue;

int datumId = QgsCoordinateTransform::projStringToDatumTransformId( value );
//TODO - throw warning if datumId is -1
d->mSourceDatumTransforms.insert( key, datumId );
}

// dest transforms
const QDomNodeList destNodes = contextElem.elementsByTagName( QStringLiteral( "dest" ) );
for ( int i = 0; i < destNodes.size(); ++i )
{
const QDomElement transformElem = destNodes.at( i ).toElement();
QString key = transformElem.attribute( QStringLiteral( "crs" ) );
QString value = transformElem.attribute( QStringLiteral( "transform" ) );
if ( value.isEmpty() )
continue;

int datumId = QgsCoordinateTransform::projStringToDatumTransformId( value );
//TODO - throw warning if datumId is -1
d->mDestDatumTransforms.insert( key, datumId );
}
#endif

d->mLock.unlock();
return result;
}
Expand All @@ -293,26 +189,6 @@ void QgsCoordinateTransformContext::writeXml( QDomElement &element, const QgsRea
contextElem.appendChild( transformElem );
}

#if 0
// src transforms
for ( auto it = d->mSourceDatumTransforms.constBegin(); it != d->mSourceDatumTransforms.constEnd(); ++ it )
{
QDomElement transformElem = element.ownerDocument().createElement( QStringLiteral( "source" ) );
transformElem.setAttribute( QStringLiteral( "crs" ), it.key() );
transformElem.setAttribute( QStringLiteral( "transform" ), it.value() < 0 ? QString() : it.value() );
contextElem.appendChild( transformElem );
}

// dest transforms
for ( auto it = d->mDestDatumTransforms.constBegin(); it != d->mDestDatumTransforms.constEnd(); ++ it )
{
QDomElement transformElem = element.ownerDocument().createElement( QStringLiteral( "dest" ) );
transformElem.setAttribute( QStringLiteral( "crs" ), it.key() );
transformElem.setAttribute( QStringLiteral( "transform" ), it.value() < 0 ? QString() : it.value() );
contextElem.appendChild( transformElem );
}
#endif

element.appendChild( contextElem );
d->mLock.unlock();
}
Expand All @@ -323,10 +199,6 @@ void QgsCoordinateTransformContext::readSettings()
d->mLock.lockForWrite();

d->mSourceDestDatumTransforms.clear();
#if 0
d->mSourceDatumTransforms.clear();
d->mDestDatumTransforms.clear();
#endif

QgsSettings settings;
settings.beginGroup( QStringLiteral( "/Projections" ) );
Expand Down
97 changes: 1 addition & 96 deletions src/core/qgscoordinatetransformcontext.h
Expand Up @@ -40,17 +40,10 @@ class QDomElement;
* \ingroup core
* Contains information about the context in which a coordinate transform is executed.
*
* The context stores various information regarding which coordinate transforms should
* The context stores various information regarding which coordinate operations should
* be used when transforming points from a source to destination coordinate reference
* system.
*
* The highest priority transforms are those set using addSourceDestinationDatumTransform()
* and which the transform has a matching source to destination CRS pair.
*
* Failing this, if the source CRS has a matching transform specified by
* addSourceDatumTransform() then this datum transform will be used. The same logic
* applies for destination CRS transforms set using addDestinationDatumTransform().
*
* \note QgsCoordinateTransformContext objects are thread safe for read and write.
*
* \note QgsCoordinateTransformContext objects are implicitly shared.
Expand Down Expand Up @@ -89,94 +82,6 @@ class CORE_EXPORT QgsCoordinateTransformContext
*/
void clear();


#if 0
//singlesourcedest

/**
* Returns the stored mapping for source CRS to associated datum transform to use.
* The map keys will be QgsCoordinateReferenceSystems::authid()s.
*
* A datum transform of -1 indicates that no datum transform is required for the
* source CRS.
*
* \warning This method should not be used to calculate the corresponding datum transforms
* to use for a coordinate transform. Instead, always use calculateDatumTransforms()
* to determine this.
*
* \see addSourceDatumTransform()
* \see destinationDatumTransforms()
*/
QMap<QString, int> sourceDatumTransforms() const;

/**
* Adds a new \a transform to use when projecting coordinates from the specified source
* \a crs.
*
* A datum \a transform of -1 indicates that no datum transform is required for the
* source CRS.
*
* Returns TRUE if the new transform was added successfully.
*
* \warning Transforms set using this method may be overridden by specific source/destination
* transforms set by addSourceDestinationDatumTransform().
*
* \see sourceDatumTransforms()
* \see addDestinationDatumTransform()
* \see removeSourceDatumTransform()
*/
bool addSourceDatumTransform( const QgsCoordinateReferenceSystem &crs, int transform );

/**
* Removes the source datum transform for the specified \a crs.
* \see addSourceDatumTransform()
* \see removeDestinationDatumTransform()
*/
void removeSourceDatumTransform( const QgsCoordinateReferenceSystem &crs );

/**
* Returns the stored mapping for destination CRS to associated datum transform to use.
* The map keys will be QgsCoordinateReferenceSystems::authid()s.
*
* A datum transform of -1 indicates that no datum transform is required for the
* destination CRS.
*
* \warning This method should not be used to calculate the corresponding datum transforms
* to use for a coordinate transform. Instead, always use calculateDatumTransforms()
* to determine this.
*
* \see addDestinationDatumTransform()
* \see sourceDatumTransforms()
*/
QMap< QString, int > destinationDatumTransforms() const;

/**
* Adds a new \a transform to use when projecting coordinates to the specified destination
* \a crs.
*
* A datum \a transform of -1 indicates that no datum transform is required for the
* destination CRS.
*
* Returns TRUE if the new transform was added successfully.
*
* \warning Transforms set using this method may be overridden by specific source/destination
* transforms set by addSourceDestinationDatumTransform().
*
* \see destinationDatumTransforms()
* \see addSourceDatumTransform()
* \see removeDestinationDatumTransform()
*/
bool addDestinationDatumTransform( const QgsCoordinateReferenceSystem &crs, int transform );

/**
* Removes the destination datum transform for the specified \a crs.
* \see addDestinationDatumTransform()
* \see removeSourceDatumTransform()
*/
void removeDestinationDatumTransform( const QgsCoordinateReferenceSystem &crs );

#endif

/**
* Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use.
* The map keys will be QgsCoordinateReferenceSystems::authid()s.
Expand Down

0 comments on commit c61fb85

Please sign in to comment.