Skip to content
Permalink
Browse files

Fix handling of transform-not-required in QgsCoordinateTransformContext

  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 6384f1f commit 68f2c26097cb2867c9f159b25e5cf6b1484c2851
@@ -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.
@@ -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.

@@ -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.
@@ -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.

@@ -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.
@@ -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.

@@ -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
@@ -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();
@@ -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();
@@ -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();
@@ -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.
@@ -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.
*
@@ -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.
@@ -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.
*
@@ -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.
@@ -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.

0 comments on commit 68f2c26

Please sign in to comment.
You can’t perform that action at this time.