Skip to content
Permalink
Browse files

Allow removing existing transforms from context

  • Loading branch information
nyalldawson committed Nov 5, 2017
1 parent ae3538c commit be95b79b39623a367715f750a5e97554d4900ad7
@@ -52,6 +52,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.

Returns true if the new transform was added successfully.

\warning Transforms set using this method may be overridden by specific source/destination
@@ -81,6 +83,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.

Returns true if the new transform was added successfully.

\warning Transforms set using this method may be overridden by specific source/destination
@@ -112,6 +116,9 @@ 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.

Returns true if the new transform pair was added successfully.

.. note::
@@ -34,6 +34,12 @@ bool QgsCoordinateTransformContext::addSourceDatumTransform( const QgsCoordinate
if ( !crs.isValid() )
return false;

if ( transform == -1 )
{
mSourceDatumTransforms.remove( crs.authid() );
return true;
}

mSourceDatumTransforms.insert( crs.authid(), transform );
return true;
}
@@ -48,6 +54,12 @@ bool QgsCoordinateTransformContext::addDestinationDatumTransform( const QgsCoord
if ( !crs.isValid() )
return false;

if ( transform == -1 )
{
mDestDatumTransforms.remove( crs.authid() );
return true;
}

mDestDatumTransforms.insert( crs.authid(), transform );
return true;
}
@@ -62,6 +74,12 @@ bool QgsCoordinateTransformContext::addSourceDestinationDatumTransform( const Qg
if ( !sourceCrs.isValid() || !destinationCrs.isValid() )
return false;

if ( sourceTransform == -1 || destinationTransform == -1 )
{
mSourceDestDatumTransforms.remove( qMakePair( sourceCrs.authid(), destinationCrs.authid() ) );
return true;
}

mSourceDestDatumTransforms.insert( qMakePair( sourceCrs.authid(), destinationCrs.authid() ), qMakePair( sourceTransform, destinationTransform ) );
return true;
}
@@ -61,6 +61,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.
*
* Returns true if the new transform was added successfully.
*
* \warning Transforms set using this method may be overridden by specific source/destination
@@ -88,6 +90,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.
*
* Returns true if the new transform was added successfully.
*
* \warning Transforms set using this method may be overridden by specific source/destination
@@ -114,6 +118,9 @@ 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.
*
* Returns true if the new transform pair was added successfully.
*
* \note Transforms set using this method will override any specific source or destination
@@ -39,6 +39,14 @@ def testSourceDatumTransforms(self):
self.assertFalse(context.addSourceDatumTransform(QgsCoordinateReferenceSystem(), 4))
self.assertEqual(context.sourceDatumTransforms(), {'EPSG:3111': 1, 'EPSG:28356': 3})

# removing non-existing
self.assertTrue(context.addSourceDatumTransform(QgsCoordinateReferenceSystem(28357), -1))
self.assertEqual(context.sourceDatumTransforms(), {'EPSG:3111': 1, 'EPSG:28356': 3})

# remove existing
self.assertTrue(context.addSourceDatumTransform(QgsCoordinateReferenceSystem(28356), -1))
self.assertEqual(context.sourceDatumTransforms(), {'EPSG:3111': 1})

context.clear()
self.assertEqual(context.sourceDatumTransforms(), {})

@@ -58,6 +66,14 @@ def testDestDatumTransforms(self):
self.assertFalse(context.addDestinationDatumTransform(QgsCoordinateReferenceSystem(), 4))
self.assertEqual(context.destinationDatumTransforms(), {'EPSG:3111': 1, 'EPSG:28356': 3})

# removing non-existing
self.assertTrue(context.addDestinationDatumTransform(QgsCoordinateReferenceSystem(28357), -1))
self.assertEqual(context.destinationDatumTransforms(), {'EPSG:3111': 1, 'EPSG:28356': 3})

# remove existing
self.assertTrue(context.addDestinationDatumTransform(QgsCoordinateReferenceSystem(28356), -1))
self.assertEqual(context.destinationDatumTransforms(), {'EPSG:3111': 1})

context.clear()
self.assertEqual(context.destinationDatumTransforms(), {})

@@ -94,6 +110,27 @@ def testSourceDestinationDatumTransforms(self):
('EPSG:28356', 'EPSG:4283'): (3, 4),
('EPSG:28356', 'EPSG:28357'): (9, 11)})

# removing non-existing
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(28357),
QgsCoordinateReferenceSystem(28356), -1, -1))
self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
('EPSG:28356', 'EPSG:4283'): (3, 4),
('EPSG:28356', 'EPSG:28357'): (9, 11)})
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(3111),
QgsCoordinateReferenceSystem(28356), -1, -1))
self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
('EPSG:28356', 'EPSG:4283'): (3, 4),
('EPSG:28356', 'EPSG:28357'): (9, 11)})

# remove existing
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(3111),
QgsCoordinateReferenceSystem(4283), -1, 3))
self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:28356', 'EPSG:4283'): (3, 4),
('EPSG:28356', 'EPSG:28357'): (9, 11)})
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(28356),
QgsCoordinateReferenceSystem(28357), 1, -1))
self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:28356', 'EPSG:4283'): (3, 4)})

context.clear()
self.assertEqual(context.sourceDestinationDatumTransforms(), {})

0 comments on commit be95b79

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