Skip to content

Commit

Permalink
Fix handling of transform-not-required in QgsCoordinateTransformContext
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 15, 2017
1 parent 40e551d commit 3916628
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 58 deletions.
44 changes: 40 additions & 4 deletions python/core/qgscoordinatetransformcontext.sip
Expand Up @@ -66,6 +66,9 @@ class QgsCoordinateTransformContext
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.
Expand All @@ -80,7 +83,8 @@ class QgsCoordinateTransformContext
Adds a new ``transform`` to use when projecting coordinates from the specified source
``crs``.

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

Returns true if the new transform was added successfully.

Expand All @@ -89,14 +93,25 @@ class QgsCoordinateTransformContext

.. seealso:: sourceDatumTransforms()
.. seealso:: addDestinationDatumTransform()
.. seealso:: removeSourceDatumTransform()
:rtype: bool
%End

void removeSourceDatumTransform( const QgsCoordinateReferenceSystem &crs );
%Docstring
Removes the source datum transform for the specified ``crs``.
.. seealso:: addSourceDatumTransform()
.. seealso:: removeDestinationDatumTransform()
%End

QMap< QString, int > destinationDatumTransforms() const;
%Docstring
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.
Expand All @@ -111,7 +126,8 @@ class QgsCoordinateTransformContext
Adds a new ``transform`` to use when projecting coordinates to the specified destination
``crs``.

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

Returns true if the new transform was added successfully.

Expand All @@ -120,14 +136,25 @@ class QgsCoordinateTransformContext

.. seealso:: destinationDatumTransforms()
.. seealso:: addSourceDatumTransform()
.. seealso:: removeDestinationDatumTransform()
:rtype: bool
%End

void removeDestinationDatumTransform( const QgsCoordinateReferenceSystem &crs );
%Docstring
Removes the destination datum transform for the specified ``crs``.
.. seealso:: addDestinationDatumTransform()
.. seealso:: removeSourceDatumTransform()
%End

QMap< QPair< QString, QString>, QPair< int, int > > sourceDestinationDatumTransforms() const;
%Docstring
Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use.
The map keys will be QgsCoordinateReferenceSystems.authid()s.

If either the source transform or destination transform is -1, then no datum transform is
required for transformations for that source or destination.

\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.
Expand All @@ -144,8 +171,8 @@ class QgsCoordinateTransformContext
Adds a new ``sourceTransform`` and ``destinationTransform`` to use when projecting coordinates
from the the specified ``sourceCrs`` to the specified ``destinationCrs``.

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

Returns true if the new transform pair was added successfully.

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

.. seealso:: sourceDestinationDatumTransforms()
.. seealso:: removeSourceDestinationDatumTransform()
:rtype: bool
%End

void removeSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs,
const QgsCoordinateReferenceSystem &destinationCrs );
%Docstring
Removes the source to destination datum transform pair for the specified ``sourceCrs`` and
``destinationCrs``.
.. seealso:: addSourceDestinationDatumTransform()
%End

QPair< int, int > calculateDatumTransforms( const QgsCoordinateReferenceSystem &source,
const QgsCoordinateReferenceSystem &destination ) const;
%Docstring
Expand Down
42 changes: 18 additions & 24 deletions src/core/qgscoordinatetransformcontext.cpp
Expand Up @@ -58,18 +58,16 @@ bool QgsCoordinateTransformContext::addSourceDatumTransform( const QgsCoordinate

d.detach();
d->mLock.lockForWrite();
if ( transform == -1 )
{
d->mSourceDatumTransforms.remove( crs.authid() );
}
else
{
d->mSourceDatumTransforms.insert( crs.authid(), transform );
}
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();
Expand All @@ -87,18 +85,16 @@ bool QgsCoordinateTransformContext::addDestinationDatumTransform( const QgsCoord
d.detach();

d->mLock.lockForWrite();
if ( transform == -1 )
{
d->mDestDatumTransforms.remove( crs.authid() );
}
else
{
d->mDestDatumTransforms.insert( crs.authid(), transform );
}
d->mDestDatumTransforms.insert( crs.authid(), transform );
d->mLock.unlock();
return true;
}

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

QMap<QPair<QString, QString>, QPair<int, int> > QgsCoordinateTransformContext::sourceDestinationDatumTransforms() const
{
d->mLock.lockForRead();
Expand All @@ -115,18 +111,16 @@ bool QgsCoordinateTransformContext::addSourceDestinationDatumTransform( const Qg

d.detach();
d->mLock.lockForWrite();
if ( sourceTransform == -1 && destinationTransform == -1 )
{
d->mSourceDestDatumTransforms.remove( qMakePair( sourceCrs.authid(), destinationCrs.authid() ) );
}
else
{
d->mSourceDestDatumTransforms.insert( qMakePair( sourceCrs.authid(), destinationCrs.authid() ), qMakePair( sourceTransform, destinationTransform ) );
}
d->mSourceDestDatumTransforms.insert( qMakePair( sourceCrs.authid(), destinationCrs.authid() ), qMakePair( sourceTransform, destinationTransform ) );
d->mLock.unlock();
return true;
}

void QgsCoordinateTransformContext::removeSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs )
{
d->mSourceDestDatumTransforms.remove( qMakePair( sourceCrs.authid(), destinationCrs.authid() ) );
}

QPair<int, int> QgsCoordinateTransformContext::calculateDatumTransforms( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
{
QString srcKey = source.authid();
Expand Down
44 changes: 40 additions & 4 deletions src/core/qgscoordinatetransformcontext.h
Expand Up @@ -82,6 +82,9 @@ class CORE_EXPORT QgsCoordinateTransformContext
* 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.
Expand All @@ -95,7 +98,8 @@ class CORE_EXPORT QgsCoordinateTransformContext
* Adds a new \a transform to use when projecting coordinates from the specified source
* \a crs.
*
* If \a transform is -1, then any existing source transform for the \a crs will be removed.
* 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.
*
Expand All @@ -104,13 +108,24 @@ class CORE_EXPORT QgsCoordinateTransformContext
*
* \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.
Expand All @@ -124,7 +139,8 @@ class CORE_EXPORT QgsCoordinateTransformContext
* Adds a new \a transform to use when projecting coordinates to the specified destination
* \a crs.
*
* If \a transform is -1, then any existing destination transform for the \a crs will be removed.
* 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.
*
Expand All @@ -133,13 +149,24 @@ class CORE_EXPORT QgsCoordinateTransformContext
*
* \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 );

/**
* Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use.
* The map keys will be QgsCoordinateReferenceSystems::authid()s.
*
* If either the source transform or destination transform is -1, then no datum transform is
* required for transformations for that source or destination.
*
* \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.
Expand All @@ -152,21 +179,30 @@ class CORE_EXPORT QgsCoordinateTransformContext
* Adds a new \a sourceTransform and \a destinationTransform to use when projecting coordinates
* from the the specified \a sourceCrs to the specified \a destinationCrs.
*
* If either \a sourceTransform or \a destinationTransform is -1, then any existing source to destination
* transform for the crs pair will be removed.
* If either \a sourceTransform or \a destinationTransform is -1, then no datum transform is
* required for transformations for that source or destination.
*
* Returns true if the new transform pair was added successfully.
*
* \note Transforms set using this method will override any specific source or destination
* transforms set by addSourceDatumTransform() or addDestinationDatumTransform().
*
* \see sourceDestinationDatumTransforms()
* \see removeSourceDestinationDatumTransform()
*/
bool addSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs,
const QgsCoordinateReferenceSystem &destinationCrs,
int sourceTransform,
int destinationTransform );

/**
* Removes the source to destination datum transform pair for the specified \a sourceCrs and
* \a destinationCrs.
* \see addSourceDestinationDatumTransform()
*/
void removeSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs,
const QgsCoordinateReferenceSystem &destinationCrs );

/**
* Returns the pair of source and destination datum transforms to use
* for a transform from the specified \a source CRS to \a destination CRS.
Expand Down

0 comments on commit 3916628

Please sign in to comment.