Пример #1
0
    def testSourceDestinationDatumTransforms(self):
        context = QgsCoordinateTransformContext()
        self.assertEqual(context.sourceDestinationDatumTransforms(), {})
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                 QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2))
        self.assertTrue(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                 QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                 QgsCoordinateReferenceSystem('EPSG:4326')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3113'),
                                 QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertEqual(context.sourceDestinationDatumTransforms(), {
            ('EPSG:3111', 'EPSG:4283'):
            QgsDatumTransform.TransformPair(1, 2)
        })
        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem(4283), 3, 4))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(
                    1, 2),
                ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(
                    3, 4)
            })
        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem(28357), 7, 8))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(
                    1, 2),
                ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(
                    3, 4),
                ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(
                    7, 8)
            })
        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem('EPSG:28357'), 9, 11))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:3111', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(1, 2),
                ('EPSG:28356', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(3, 4),
                ('EPSG:28356', 'EPSG:28357'):
                QgsDatumTransform.TransformPair(9, 11)
            })

        # invalid additions
        self.assertFalse(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem(),
                QgsCoordinateReferenceSystem('EPSG:28357'), 9, 11))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:3111', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(1, 2),
                ('EPSG:28356', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(3, 4),
                ('EPSG:28356', 'EPSG:28357'):
                QgsDatumTransform.TransformPair(9, 11)
            })
        self.assertFalse(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem(), 9, 11))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:3111', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(1, 2),
                ('EPSG:28356', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(3, 4),
                ('EPSG:28356', 'EPSG:28357'):
                QgsDatumTransform.TransformPair(9, 11)
            })

        # indicate no transform required
        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem(28357),
                QgsCoordinateReferenceSystem(28356), -1, -1))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:3111', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(1, 2),
                ('EPSG:28356', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(3, 4),
                ('EPSG:28356', 'EPSG:28357'):
                QgsDatumTransform.TransformPair(9, 11),
                ('EPSG:28357', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(-1, -1)
            })
        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem(3111),
                QgsCoordinateReferenceSystem(28356), 17, -1))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:3111', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(1, 2),
                ('EPSG:28356', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(3, 4),
                ('EPSG:28356', 'EPSG:28357'):
                QgsDatumTransform.TransformPair(9, 11),
                ('EPSG:28357', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(-1, -1),
                ('EPSG:3111', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(17, -1)
            })
        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem(3113),
                QgsCoordinateReferenceSystem(28356), -1, 18))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:3111', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(1, 2),
                ('EPSG:28356', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(3, 4),
                ('EPSG:28356', 'EPSG:28357'):
                QgsDatumTransform.TransformPair(9, 11),
                ('EPSG:28357', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(-1, -1),
                ('EPSG:3111', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(17, -1),
                ('EPSG:3113', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(-1, 18)
            })
        # remove non-existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3113),
                                          QgsCoordinateReferenceSystem(3111))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:3111', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(1, 2),
                ('EPSG:28356', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(3, 4),
                ('EPSG:28356', 'EPSG:28357'):
                QgsDatumTransform.TransformPair(9, 11),
                ('EPSG:28357', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(-1, -1),
                ('EPSG:3111', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(17, -1),
                ('EPSG:3113', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(-1, 18)
            })

        # remove existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3111),
                                          QgsCoordinateReferenceSystem(4283))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:28356', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(3, 4),
                ('EPSG:28356', 'EPSG:28357'):
                QgsDatumTransform.TransformPair(9, 11),
                ('EPSG:28357', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(-1, -1),
                ('EPSG:3111', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(17, -1),
                ('EPSG:3113', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(-1, 18)
            })
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3111),
                                          QgsCoordinateReferenceSystem(28356))
        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:28356', 'EPSG:4283'):
                QgsDatumTransform.TransformPair(3, 4),
                ('EPSG:28356', 'EPSG:28357'):
                QgsDatumTransform.TransformPair(9, 11),
                ('EPSG:28357', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(-1, -1),
                ('EPSG:3113', 'EPSG:28356'):
                QgsDatumTransform.TransformPair(-1, 18)
            })

        context.clear()
        self.assertEqual(context.sourceDestinationDatumTransforms(), {})
    def testSourceDestinationDatumTransforms(self):
        context = QgsCoordinateTransformContext()
        self.assertEqual(context.sourceDestinationDatumTransforms(), {})
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                                                   QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2))
        self.assertTrue(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4326')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3113'), QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2)})
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                                   QgsCoordinateReferenceSystem(4283), 3, 4))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2),
                          ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4)})
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                                   QgsCoordinateReferenceSystem(28357), 7, 8))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2),
                          ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4),
                          ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(7, 8)})
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                                   QgsCoordinateReferenceSystem('EPSG:28357'), 9, 11))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2),
                          ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4),
                          ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(9, 11)})

        # invalid additions
        self.assertFalse(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(),
                                                                    QgsCoordinateReferenceSystem('EPSG:28357'), 9, 11))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2),
                          ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4),
                          ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(9, 11)})
        self.assertFalse(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                                                    QgsCoordinateReferenceSystem(), 9, 11))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2),
                          ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4),
                          ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(9, 11)})

        # indicate no transform required
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(28357),
                                                                   QgsCoordinateReferenceSystem(28356), -1, -1))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2),
                          ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4),
                          ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(9, 11),
                          ('EPSG:28357', 'EPSG:28356'): QgsDatumTransform.TransformPair(-1, -1)})
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(3111),
                                                                   QgsCoordinateReferenceSystem(28356), 17, -1))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2),
                          ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4),
                          ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(9, 11),
                          ('EPSG:28357', 'EPSG:28356'): QgsDatumTransform.TransformPair(-1, -1),
                          ('EPSG:3111', 'EPSG:28356'): QgsDatumTransform.TransformPair(17, -1)})
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(3113),
                                                                   QgsCoordinateReferenceSystem(28356), -1, 18))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2),
                          ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4),
                          ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(9, 11),
                          ('EPSG:28357', 'EPSG:28356'): QgsDatumTransform.TransformPair(-1, -1),
                          ('EPSG:3111', 'EPSG:28356'): QgsDatumTransform.TransformPair(17, -1),
                          ('EPSG:3113', 'EPSG:28356'): QgsDatumTransform.TransformPair(-1, 18)})
        # remove non-existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3113), QgsCoordinateReferenceSystem(3111))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2),
                          ('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4),
                          ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(9, 11),
                          ('EPSG:28357', 'EPSG:28356'): QgsDatumTransform.TransformPair(-1, -1),
                          ('EPSG:3111', 'EPSG:28356'): QgsDatumTransform.TransformPair(17, -1),
                          ('EPSG:3113', 'EPSG:28356'): QgsDatumTransform.TransformPair(-1, 18)})

        # remove existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3111),
                                          QgsCoordinateReferenceSystem(4283))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4),
                          ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(9, 11),
                          ('EPSG:28357', 'EPSG:28356'): QgsDatumTransform.TransformPair(-1, -1),
                          ('EPSG:3111', 'EPSG:28356'): QgsDatumTransform.TransformPair(17, -1),
                          ('EPSG:3113', 'EPSG:28356'): QgsDatumTransform.TransformPair(-1, 18)})
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3111),
                                          QgsCoordinateReferenceSystem(28356))
        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:28356', 'EPSG:4283'): QgsDatumTransform.TransformPair(3, 4),
                          ('EPSG:28356', 'EPSG:28357'): QgsDatumTransform.TransformPair(9, 11),
                          ('EPSG:28357', 'EPSG:28356'): QgsDatumTransform.TransformPair(-1, -1),
                          ('EPSG:3113', 'EPSG:28356'): QgsDatumTransform.TransformPair(-1, 18)})

        context.clear()
        self.assertEqual(context.sourceDestinationDatumTransforms(), {})
Пример #3
0
    def testSourceDestinationDatumTransformsProj6(self):
        context = QgsCoordinateTransformContext()
        self.assertEqual(context.sourceDestinationDatumTransforms(), {})
        proj_string = '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                 QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertFalse(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertFalse(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283'), proj_string))
        self.assertTrue(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                 QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                 QgsCoordinateReferenceSystem('EPSG:4326')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3113'),
                                 QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertEqual(context.coordinateOperations(),
                         {('EPSG:3111', 'EPSG:4283'): proj_string})
        self.assertTrue(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))
        self.assertTrue(
            context.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertTrue(
            context.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))

        self.assertTrue(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:4283'),
                                 QgsCoordinateReferenceSystem('EPSG:3111')))

        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')), proj_string)
        self.assertFalse(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')))
        # ideally not equal, but for now it's all we can do, and return True for mustReverseCoordinateOperation here
        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')), proj_string)
        self.assertTrue(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))
        self.assertTrue(
            context.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))

        proj_string_2 = 'dummy'
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111'), proj_string_2,
                False))
        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')), proj_string_2)
        self.assertFalse(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))
        context.removeCoordinateOperation(
            QgsCoordinateReferenceSystem('EPSG:4283'),
            QgsCoordinateReferenceSystem('EPSG:3111'))

        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3113'), proj_string_2,
                False))
        self.assertFalse(
            context.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3113')))
        self.assertFalse(
            context.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:3113'),
                QgsCoordinateReferenceSystem('EPSG:4283')))

        context.removeCoordinateOperation(
            QgsCoordinateReferenceSystem('EPSG:4283'),
            QgsCoordinateReferenceSystem('EPSG:3113'))

        proj_string_2 = '+proj=pipeline +step +inv +proj=utm +zone=56 +south +ellps=GRS80 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem(4283), proj_string_2))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2
            })
        proj_string_3 = '+proj=pipeline +step +inv +proj=utm +zone=56 +south +ellps=GRS80 +step +proj=utm +zone=57 +south +ellps=GRS80'
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem(28357), proj_string_3))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): proj_string_3
            })
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem('EPSG:28357'),
                'some other proj string'))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string'
            })

        # invalid additions
        self.assertFalse(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem(),
                QgsCoordinateReferenceSystem('EPSG:28357'), 'bad proj'))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string'
            })
        self.assertFalse(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem(), 'bad proj'))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string'
            })

        # indicate no transform required
        self.assertTrue(
            context.addCoordinateOperation(QgsCoordinateReferenceSystem(28357),
                                           QgsCoordinateReferenceSystem(28356),
                                           ''))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                ('EPSG:28357', 'EPSG:28356'): ''
            })

        # remove non-existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3113),
                                          QgsCoordinateReferenceSystem(3111))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                ('EPSG:28357', 'EPSG:28356'): ''
            })

        # remove existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3111),
                                          QgsCoordinateReferenceSystem(4283))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                ('EPSG:28357', 'EPSG:28356'): ''
            })
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(28356),
                                          QgsCoordinateReferenceSystem(28357))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28357', 'EPSG:28356'): ''
            })

        context.clear()
        self.assertEqual(context.coordinateOperations(), {})
    def testSourceDestinationDatumTransformsProj6(self):
        context = QgsCoordinateTransformContext()
        self.assertEqual(context.sourceDestinationDatumTransforms(), {})
        proj_string = '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:3111'),
                                                       QgsCoordinateReferenceSystem('EPSG:4283'), proj_string))
        self.assertTrue(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4326')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3113'), QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string})
        proj_string_2 = '+proj=pipeline +step +inv +proj=utm +zone=56 +south +ellps=GRS80 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                       QgsCoordinateReferenceSystem(4283), proj_string_2))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2})
        proj_string_3 = '+proj=pipeline +step +inv +proj=utm +zone=56 +south +ellps=GRS80 +step +proj=utm +zone=57 +south +ellps=GRS80'
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                       QgsCoordinateReferenceSystem(28357), proj_string_3))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): proj_string_3})
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                       QgsCoordinateReferenceSystem('EPSG:28357'),
                                                       'some other proj string'))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string'})

        # invalid additions
        self.assertFalse(context.addCoordinateOperation(QgsCoordinateReferenceSystem(),
                                                        QgsCoordinateReferenceSystem('EPSG:28357'), 'bad proj'))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string'})
        self.assertFalse(context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:3111'),
                                                        QgsCoordinateReferenceSystem(), 'bad proj'))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string'})

        # indicate no transform required
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(28357),
                                                       QgsCoordinateReferenceSystem(28356), ''))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                                                          ('EPSG:28357', 'EPSG:28356'): ''})

        # remove non-existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3113), QgsCoordinateReferenceSystem(3111))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                                                          ('EPSG:28357', 'EPSG:28356'): ''})

        # remove existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3111),
                                          QgsCoordinateReferenceSystem(4283))
        self.assertEqual(context.coordinateOperations(), {('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                                                          ('EPSG:28357', 'EPSG:28356'): ''})
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(28356),
                                          QgsCoordinateReferenceSystem(28357))
        self.assertEqual(context.coordinateOperations(), {('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28357', 'EPSG:28356'): ''})

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