def testWriteReadXml(self):
        # setup a context
        context = QgsCoordinateTransformContext()

        source_id_1 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4204),
                                                             QgsCoordinateReferenceSystem(4326))[0].sourceTransformId
        dest_id_1 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4204),
                                                           QgsCoordinateReferenceSystem(4326))[0].destinationTransformId

        source_id_2 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4205),
                                                             QgsCoordinateReferenceSystem(4326))[0].sourceTransformId
        dest_id_2 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4205),
                                                           QgsCoordinateReferenceSystem(4326))[0].destinationTransformId

        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(4204),
                                                                   QgsCoordinateReferenceSystem(4326), source_id_1, dest_id_1))
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(4205),
                                                                   QgsCoordinateReferenceSystem(4326), source_id_2, dest_id_2))

        self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:4204', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
                                                                      ('EPSG:4205', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_2, dest_id_2)})

        # save to xml
        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        context.writeXml(elem, QgsReadWriteContext())

        # restore from xml
        context2 = QgsCoordinateTransformContext()
        context2.readXml(elem, QgsReadWriteContext())

        # check result
        self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:4204', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
                                                                       ('EPSG:4205', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_2, dest_id_2)})
 def testStringToTransformId(self):
     """
     Test converting proj strings to corresponding datum IDs
     """
     self.assertEqual(QgsDatumTransform.projStringToDatumTransformId(''), -1)
     self.assertEqual(QgsDatumTransform.projStringToDatumTransformId('not'), -1)
     test_string = '+towgs84=-403,684,41'
     id = QgsDatumTransform.projStringToDatumTransformId(test_string)
     self.assertNotEqual(id, -1)
     string = QgsDatumTransform.datumTransformToProj(id)
     self.assertEqual(string, test_string)
     self.assertEqual(QgsDatumTransform.projStringToDatumTransformId(test_string.upper()), id)
Ejemplo n.º 3
0
    def testTransformInfo(self):
        # hopefully this transform is available on all platforms!
        transforms = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem(4613),
            QgsCoordinateReferenceSystem(4326))
        self.assertTrue(len(transforms) > 0)
        self.assertIn('+towgs84=-403,684,41', [
            QgsDatumTransform.datumTransformToProj(t.sourceTransformId)
            for t in transforms
        ])
        self.assertEqual([''] * len(transforms), [
            QgsDatumTransform.datumTransformToProj(t.destinationTransformId)
            for t in transforms
        ])
        self.assertIn('EPSG:4613', [
            QgsDatumTransform.datumTransformInfo(
                t.sourceTransformId).sourceCrsAuthId for t in transforms
        ])
        self.assertEqual([''] * len(transforms), [
            QgsDatumTransform.datumTransformInfo(
                t.destinationTransformId).destinationCrsAuthId
            for t in transforms
        ])

        # and the reverse
        transforms = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem(4326),
            QgsCoordinateReferenceSystem(4613))
        self.assertTrue(len(transforms) > 0)
        self.assertEqual([''] * len(transforms), [
            QgsDatumTransform.datumTransformToProj(t.sourceTransformId)
            for t in transforms
        ])
        self.assertIn('+towgs84=-403,684,41', [
            QgsDatumTransform.datumTransformToProj(t.destinationTransformId)
            for t in transforms
        ])
        self.assertEqual([''] * len(transforms), [
            QgsDatumTransform.datumTransformInfo(
                t.sourceTransformId).destinationCrsAuthId for t in transforms
        ])
        self.assertIn('EPSG:4613', [
            QgsDatumTransform.datumTransformInfo(
                t.destinationTransformId).sourceCrsAuthId for t in transforms
        ])
    def testReadWriteSettings(self):
        context = QgsCoordinateTransformContext()
        context.readSettings()

        source_id_1 = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem(4204),
            QgsCoordinateReferenceSystem(4326))[0].sourceTransformId
        dest_id_1 = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem(4204),
            QgsCoordinateReferenceSystem(4326))[0].destinationTransformId

        source_id_2 = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem(4205),
            QgsCoordinateReferenceSystem(4326))[0].sourceTransformId
        dest_id_2 = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem(4205),
            QgsCoordinateReferenceSystem(4326))[0].destinationTransformId

        # should be empty
        self.assertEqual(context.sourceDestinationDatumTransforms(), {})

        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem('EPSG:4204'),
                QgsCoordinateReferenceSystem('EPSG:4326'), source_id_1,
                dest_id_1))
        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem('EPSG:4205'),
                QgsCoordinateReferenceSystem(4326), source_id_2, dest_id_2))

        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:4204', 'EPSG:4326'):
                QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
                ('EPSG:4205', 'EPSG:4326'):
                QgsDatumTransform.TransformPair(source_id_2, dest_id_2)
            })

        # save to settings
        context.writeSettings()

        # restore from settings
        context2 = QgsCoordinateTransformContext()
        self.assertEqual(context2.sourceDestinationDatumTransforms(), {})
        context2.readSettings()

        # check result
        self.assertEqual(
            context2.sourceDestinationDatumTransforms(), {
                ('EPSG:4204', 'EPSG:4326'):
                QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
                ('EPSG:4205', 'EPSG:4326'):
                QgsDatumTransform.TransformPair(source_id_2, dest_id_2)
            })
Ejemplo n.º 5
0
    def testWriteReadXml(self):
        # setup a context
        context = QgsCoordinateTransformContext()

        source_id_1 = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem(4204),
            QgsCoordinateReferenceSystem(4326))[0].sourceTransformId
        dest_id_1 = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem(4204),
            QgsCoordinateReferenceSystem(4326))[0].destinationTransformId

        source_id_2 = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem(4205),
            QgsCoordinateReferenceSystem(4326))[0].sourceTransformId
        dest_id_2 = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem(4205),
            QgsCoordinateReferenceSystem(4326))[0].destinationTransformId

        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem(4204),
                QgsCoordinateReferenceSystem(4326), source_id_1, dest_id_1))
        self.assertTrue(
            context.addSourceDestinationDatumTransform(
                QgsCoordinateReferenceSystem(4205),
                QgsCoordinateReferenceSystem(4326), source_id_2, dest_id_2))

        self.assertEqual(
            context.sourceDestinationDatumTransforms(), {
                ('EPSG:4204', 'EPSG:4326'):
                QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
                ('EPSG:4205', 'EPSG:4326'):
                QgsDatumTransform.TransformPair(source_id_2, dest_id_2)
            })

        # save to xml
        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        context.writeXml(elem, QgsReadWriteContext())

        # restore from xml
        context2 = QgsCoordinateTransformContext()
        context2.readXml(elem, QgsReadWriteContext())

        # check result
        self.assertEqual(
            context2.sourceDestinationDatumTransforms(), {
                ('EPSG:4204', 'EPSG:4326'):
                QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
                ('EPSG:4205', 'EPSG:4326'):
                QgsDatumTransform.TransformPair(source_id_2, dest_id_2)
            })
Ejemplo n.º 6
0
 def testNoLasLos(self):
     """
     Test that operations which rely on an NADCON5 grid shift file (which are unsupported by Proj... at time of writing !) are not returned
     """
     ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:4138'),
                                        QgsCoordinateReferenceSystem('EPSG:4269'))
     self.assertEqual(len(ops), 2)
     self.assertTrue(ops[0].name)
     self.assertTrue(ops[0].proj)
     self.assertTrue(ops[1].name)
     self.assertTrue(ops[1].proj)
    def testTransformInfo(self):
        # hopefully this transform is available on all platforms!
        transforms = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4613), QgsCoordinateReferenceSystem(4326))
        self.assertTrue(len(transforms) > 0)
        self.assertIn('+towgs84=-403,684,41', [QgsDatumTransform.datumTransformToProj(t.sourceTransformId) for t in transforms])
        self.assertEqual([''] * len(transforms), [QgsDatumTransform.datumTransformToProj(t.destinationTransformId) for t in transforms])
        self.assertIn('EPSG:4613', [QgsDatumTransform.datumTransformInfo(t.sourceTransformId).sourceCrsAuthId for t in
                                    transforms])
        self.assertEqual([''] * len(transforms), [QgsDatumTransform.datumTransformInfo(t.destinationTransformId).destinationCrsAuthId for t in
                                                  transforms])

        # and the reverse
        transforms = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(4613))
        self.assertTrue(len(transforms) > 0)
        self.assertEqual([''] * len(transforms), [QgsDatumTransform.datumTransformToProj(t.sourceTransformId) for t in transforms])
        self.assertIn('+towgs84=-403,684,41',
                      [QgsDatumTransform.datumTransformToProj(t.destinationTransformId) for t in transforms])
        self.assertEqual([''] * len(transforms), [QgsDatumTransform.datumTransformInfo(t.sourceTransformId).destinationCrsAuthId for t in
                                                  transforms])
        self.assertIn('EPSG:4613', [QgsDatumTransform.datumTransformInfo(t.destinationTransformId).sourceCrsAuthId for t in
                                    transforms])
    def testReadWriteSettings(self):
        context = QgsCoordinateTransformContext()
        context.readSettings()

        source_id_1 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4204),
                                                             QgsCoordinateReferenceSystem(4326))[0].sourceTransformId
        dest_id_1 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4204),
                                                           QgsCoordinateReferenceSystem(4326))[0].destinationTransformId

        source_id_2 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4205),
                                                             QgsCoordinateReferenceSystem(4326))[0].sourceTransformId
        dest_id_2 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4205),
                                                           QgsCoordinateReferenceSystem(4326))[0].destinationTransformId

        # should be empty
        self.assertEqual(context.sourceDestinationDatumTransforms(), {})

        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:4204'),
                                                                   QgsCoordinateReferenceSystem('EPSG:4326'),
                                                                   source_id_1, dest_id_1))
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:4205'),
                                                                   QgsCoordinateReferenceSystem(4326), source_id_2,
                                                                   dest_id_2))

        self.assertEqual(context.sourceDestinationDatumTransforms(),
                         {('EPSG:4204', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
                          ('EPSG:4205', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_2, dest_id_2)})

        # save to settings
        context.writeSettings()

        # restore from settings
        context2 = QgsCoordinateTransformContext()
        self.assertEqual(context2.sourceDestinationDatumTransforms(), {})
        context2.readSettings()

        # check result
        self.assertEqual(context2.sourceDestinationDatumTransforms(),
                         {('EPSG:4204', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
                          ('EPSG:4205', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_2, dest_id_2)})
 def testProject(self):
     """
     Test project's transform context
     """
     project = QgsProject()
     context_changed_spy = QSignalSpy(project.transformContextChanged)
     context = project.transformContext()
     context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                                QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2)
     project.setTransformContext(context)
     self.assertEqual(len(context_changed_spy), 1)
     self.assertEqual(project.transformContext().sourceDestinationDatumTransforms(),
                      {('EPSG:3111', 'EPSG:4283'): QgsDatumTransform.TransformPair(1, 2)})
Ejemplo n.º 10
0
 def testNoLasLos(self):
     """
     Test that operations which rely on an las/los grid shift file (which are unsupported by Proj6) are not returned
     """
     ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:3035'),
                                        QgsCoordinateReferenceSystem('EPSG:5514'))
     self.assertEqual(len(ops), 3)
     self.assertTrue(ops[0].name)
     self.assertTrue(ops[0].proj)
     self.assertTrue(ops[1].name)
     self.assertTrue(ops[1].proj)
     self.assertTrue(ops[2].name)
     self.assertTrue(ops[2].proj)
Ejemplo n.º 11
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.removeSourceDestinationDatumTransform(
            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.removeSourceDestinationDatumTransform(
            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.removeSourceDestinationDatumTransform(
            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(), {})
Ejemplo n.º 12
0
    def testOperationsCruftyProj(self):
        w = QgsCoordinateOperationWidget()
        self.assertFalse(w.hasSelection())
        spy = QSignalSpy(w.operationChanged)
        w.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:4283'))
        self.assertEqual(len(spy), 0)
        w.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:7844'))
        self.assertEqual(len(spy), 1)
        self.assertTrue(w.hasSelection())
        self.assertEqual(len(w.availableOperations()), 2)

        self.assertEqual(
            QgsDatumTransform.datumTransformToProj(
                w.defaultOperation().sourceTransformId),
            '+nadgrids=GDA94_GDA2020_conformal_and_distortion.gsb')
        self.assertEqual(w.defaultOperation().destinationTransformId, -1)
        self.assertEqual(
            QgsDatumTransform.datumTransformToProj(
                w.selectedOperation().sourceTransformId),
            '+nadgrids=GDA94_GDA2020_conformal_and_distortion.gsb')
        self.assertEqual(w.selectedOperation().destinationTransformId, -1)

        self.assertEqual(
            QgsDatumTransform.datumTransformToProj(
                w.availableOperations()[1].sourceTransformId),
            '+nadgrids=GDA94_GDA2020_conformal.gsb')
        self.assertEqual(w.availableOperations()[1].destinationTransformId, -1)

        op = QgsCoordinateOperationWidget.OperationDetails()
        op.sourceTransformId = w.availableOperations()[1].sourceTransformId
        w.setSelectedOperation(op)
        self.assertEqual(
            QgsDatumTransform.datumTransformToProj(
                w.selectedOperation().sourceTransformId),
            '+nadgrids=GDA94_GDA2020_conformal.gsb')
        self.assertEqual(len(spy), 2)
        w.setSelectedOperation(op)
        self.assertEqual(
            QgsDatumTransform.datumTransformToProj(
                w.selectedOperation().sourceTransformId),
            '+nadgrids=GDA94_GDA2020_conformal.gsb')
        self.assertEqual(len(spy), 2)

        op.sourceTransformId = w.availableOperations()[0].sourceTransformId
        op.destinationTransformId = -1
        w.setSelectedOperation(op)
        self.assertEqual(
            QgsDatumTransform.datumTransformToProj(
                w.selectedOperation().sourceTransformId),
            '+nadgrids=GDA94_GDA2020_conformal_and_distortion.gsb')
        self.assertEqual(len(spy), 3)

        op.destinationTransformId = w.availableOperations(
        )[1].sourceTransformId
        op.sourceTransformId = -1
        w.setSelectedOperation(op)
        self.assertEqual(
            QgsDatumTransform.datumTransformToProj(
                w.selectedOperation().sourceTransformId),
            '+nadgrids=GDA94_GDA2020_conformal.gsb')
        self.assertEqual(len(spy), 4)

        op.destinationTransformId = w.availableOperations(
        )[0].sourceTransformId
        op.sourceTransformId = -1
        w.setSelectedOperation(op)
        self.assertEqual(
            QgsDatumTransform.datumTransformToProj(
                w.selectedOperation().sourceTransformId),
            '+nadgrids=GDA94_GDA2020_conformal_and_distortion.gsb')
        self.assertEqual(len(spy), 5)
Ejemplo n.º 13
0
    def testOperations(self):
        ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem(),
                                           QgsCoordinateReferenceSystem())
        self.assertEqual(ops, [])
        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem())
        self.assertEqual(ops, [])
        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem(),
            QgsCoordinateReferenceSystem('EPSG:3111'))
        self.assertEqual(ops, [])

        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem('EPSG:3111'))
        self.assertEqual(len(ops), 1)
        self.assertTrue(ops[0].name)
        self.assertEqual(ops[0].proj, '+proj=noop')
        self.assertEqual(ops[0].accuracy, 0.0)
        self.assertTrue(ops[0].isAvailable)

        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem('EPSG:4283'))
        self.assertEqual(len(ops), 1)
        self.assertTrue(ops[0].name)
        self.assertEqual(
            ops[0].proj,
            '+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'
        )
        self.assertEqual(ops[0].accuracy, -1.0)
        self.assertTrue(ops[0].isAvailable)

        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem('EPSG:28355'))
        self.assertEqual(len(ops), 1)
        self.assertTrue(ops[0].name)
        self.assertEqual(
            ops[0].proj,
            '+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=utm +zone=55 +south +ellps=GRS80'
        )
        self.assertEqual(ops[0].accuracy, 0.0)
        self.assertTrue(ops[0].isAvailable)

        # uses a grid file
        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:4283'),
            QgsCoordinateReferenceSystem('EPSG:7844'))
        self.assertGreaterEqual(len(ops), 5)

        op1_index = [
            i for i in range(len(ops)) if ops[i].proj ==
            '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg'
        ][0]
        self.assertTrue(ops[op1_index].name)
        self.assertEqual(
            ops[op1_index].proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg'
        )
        self.assertTrue(ops[op1_index].isAvailable)
        self.assertEqual(ops[op1_index].accuracy, 0.01)
        self.assertEqual(len(ops[op1_index].grids), 0)

        if QgsProjUtils.projVersionMajor() == 6:
            op2_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            ][0]
        else:
            op2_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal_and_distortion.tif +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            ][0]
        self.assertTrue(ops[op2_index].name)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(
                ops[op2_index].proj,
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            )
        else:
            self.assertEqual(
                ops[op2_index].proj,
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal_and_distortion.tif +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            )
        self.assertEqual(ops[op2_index].accuracy, 0.05)
        self.assertEqual(len(ops[op2_index].grids), 1)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(ops[op2_index].grids[0].shortName,
                             'GDA94_GDA2020_conformal_and_distortion.gsb')
        else:
            self.assertEqual(
                ops[op2_index].grids[0].shortName,
                'au_icsm_GDA94_GDA2020_conformal_and_distortion.tif')
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertTrue(ops[op2_index].grids[0].packageName)
        self.assertIn('http', ops[op2_index].grids[0].url)
        self.assertTrue(ops[op2_index].grids[0].directDownload)
        self.assertTrue(ops[op2_index].grids[0].openLicense)

        if QgsProjUtils.projVersionMajor() == 6:
            op3_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            ][0]
        else:
            op3_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal.tif +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            ][0]
        self.assertTrue(ops[op3_index].name)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(
                ops[op3_index].proj,
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            )
        else:
            self.assertEqual(
                ops[op3_index].proj,
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal.tif +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            )
        self.assertEqual(ops[op3_index].accuracy, 0.05)
        self.assertEqual(len(ops[op3_index].grids), 1)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(ops[op3_index].grids[0].shortName,
                             'GDA94_GDA2020_conformal.gsb')
        else:
            self.assertEqual(ops[op3_index].grids[0].shortName,
                             'au_icsm_GDA94_GDA2020_conformal.tif')
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertTrue(ops[op3_index].grids[0].packageName)
        self.assertIn('http', ops[op3_index].grids[0].url)
        self.assertTrue(ops[op3_index].grids[0].directDownload)
        self.assertTrue(ops[op3_index].grids[0].openLicense)

        if QgsProjUtils.projVersionMajor() == 6:
            op4_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_cocos_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            ][0]
        else:
            op4_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal_cocos_island.tif +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            ][0]
        self.assertTrue(ops[op4_index].name)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(
                ops[op4_index].proj,
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_cocos_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            )
        else:
            self.assertEqual(
                ops[op4_index].proj,
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal_cocos_island.tif +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            )
        self.assertEqual(ops[op4_index].accuracy, 0.05)
        self.assertEqual(len(ops[op4_index].grids), 1)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(ops[op4_index].grids[0].shortName,
                             'GDA94_GDA2020_conformal_cocos_island.gsb')
        else:
            self.assertEqual(
                ops[op4_index].grids[0].shortName,
                'au_icsm_GDA94_GDA2020_conformal_cocos_island.tif')
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertTrue(ops[op4_index].grids[0].packageName)
        self.assertIn('http', ops[op4_index].grids[0].url)

        if QgsProjUtils.projVersionMajor() == 6:
            op5_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_christmas_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            ][0]
        else:
            op5_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal_christmas_island.tif +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            ][0]
        self.assertTrue(ops[op5_index].name)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(
                ops[op5_index].proj,
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_christmas_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            )
        else:
            self.assertEqual(
                ops[op5_index].proj,
                '+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal_christmas_island.tif +step +proj=unitconvert +xy_in=rad +xy_out=deg'
            )
        self.assertEqual(ops[op5_index].accuracy, 0.05)
        self.assertEqual(len(ops[op5_index].grids), 1)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(ops[op5_index].grids[0].shortName,
                             'GDA94_GDA2020_conformal_christmas_island.gsb')
        else:
            self.assertEqual(
                ops[op5_index].grids[0].shortName,
                'au_icsm_GDA94_GDA2020_conformal_christmas_island.tif')
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertTrue(ops[op5_index].grids[0].packageName)
        self.assertIn('http', ops[op5_index].grids[0].url)

        # uses a pivot datum (technically a proj test, but this will help me sleep at night ;)
        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem('EPSG:7899'))

        self.assertGreaterEqual(len(ops), 3)

        op1_index = [
            i for i in range(len(ops)) if ops[i].proj ==
            '+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=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
        ][0]
        self.assertTrue(ops[op1_index].name)
        self.assertEqual(
            ops[op1_index].proj,
            '+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=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
        )
        self.assertTrue(ops[op1_index].isAvailable)
        self.assertEqual(ops[op1_index].accuracy, 0.01)
        self.assertEqual(len(ops[op1_index].grids), 0)

        if QgsProjUtils.projVersionMajor() == 6:
            op2_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+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=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
            ][0]
        else:
            op2_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+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=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal_and_distortion.tif +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
            ][0]
        self.assertTrue(ops[op2_index].name)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(
                ops[op2_index].proj,
                '+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=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
            )
        else:
            self.assertEqual(
                ops[op2_index].proj,
                '+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=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal_and_distortion.tif +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
            )
        self.assertEqual(ops[op2_index].accuracy, 0.05)
        self.assertEqual(len(ops[op2_index].grids), 1)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(ops[op2_index].grids[0].shortName,
                             'GDA94_GDA2020_conformal_and_distortion.gsb')
        else:
            self.assertEqual(
                ops[op2_index].grids[0].shortName,
                'au_icsm_GDA94_GDA2020_conformal_and_distortion.tif')
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertTrue(ops[op2_index].grids[0].packageName)
        self.assertIn('http', ops[op2_index].grids[0].url)
        self.assertTrue(ops[op2_index].grids[0].directDownload)
        self.assertTrue(ops[op2_index].grids[0].openLicense)

        if QgsProjUtils.projVersionMajor() == 6:
            op3_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+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=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
            ][0]
        else:
            op3_index = [
                i for i in range(len(ops)) if ops[i].proj ==
                '+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=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal.tif +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
            ][0]
        self.assertTrue(ops[op3_index].name)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(
                ops[op3_index].proj,
                '+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=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
            )
        else:
            self.assertEqual(
                ops[op3_index].proj,
                '+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=hgridshift +grids=au_icsm_GDA94_GDA2020_conformal.tif +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
            )
        self.assertEqual(ops[op3_index].accuracy, 0.05)
        self.assertEqual(len(ops[op3_index].grids), 1)
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertEqual(ops[op3_index].grids[0].shortName,
                             'GDA94_GDA2020_conformal.gsb')
        else:
            self.assertEqual(ops[op3_index].grids[0].shortName,
                             'au_icsm_GDA94_GDA2020_conformal.tif')
        if QgsProjUtils.projVersionMajor() == 6:
            self.assertTrue(ops[op3_index].grids[0].packageName)
        self.assertIn('http', ops[op3_index].grids[0].url)
        self.assertTrue(ops[op3_index].grids[0].directDownload)
        self.assertTrue(ops[op3_index].grids[0].openLicense)
Ejemplo n.º 14
0
    def testOperations(self):
        ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem(),
                                           QgsCoordinateReferenceSystem())
        self.assertEqual(ops, [])
        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem())
        self.assertEqual(ops, [])
        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem(),
            QgsCoordinateReferenceSystem('EPSG:3111'))
        self.assertEqual(ops, [])

        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem('EPSG:3111'))
        self.assertEqual(len(ops), 1)
        self.assertTrue(ops[0].name)
        self.assertEqual(ops[0].proj, '+proj=noop')
        self.assertEqual(ops[0].accuracy, 0.0)
        self.assertTrue(ops[0].isAvailable)

        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem('EPSG:4283'))
        self.assertEqual(len(ops), 1)
        self.assertTrue(ops[0].name)
        self.assertEqual(
            ops[0].proj,
            '+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.assertEqual(ops[0].accuracy, -1.0)
        self.assertTrue(ops[0].isAvailable)

        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem('EPSG:28355'))
        self.assertEqual(len(ops), 1)
        self.assertTrue(ops[0].name)
        self.assertEqual(
            ops[0].proj,
            '+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=utm +zone=55 +south +ellps=GRS80'
        )
        self.assertEqual(ops[0].accuracy, 0.0)
        self.assertTrue(ops[0].isAvailable)

        # uses a grid file
        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:4283'),
            QgsCoordinateReferenceSystem('EPSG:7844'))
        self.assertGreaterEqual(len(ops), 5)

        op1_index = [
            i for i in range(len(ops)) if ops[i].proj ==
            '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        ][0]
        self.assertTrue(ops[op1_index].name)
        self.assertEqual(
            ops[op1_index].proj,
            '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        )
        self.assertTrue(ops[op1_index].isAvailable)
        self.assertEqual(ops[op1_index].accuracy, 0.01)
        self.assertEqual(len(ops[op1_index].grids), 0)

        op2_index = [
            i for i in range(len(ops)) if ops[i].proj ==
            '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        ][0]
        self.assertTrue(ops[op2_index].name)
        self.assertEqual(
            ops[op2_index].proj,
            '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        )
        self.assertEqual(
            ops[op2_index].accuracy,
            0.05)  # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op2_index].grids), 1)
        self.assertEqual(ops[op2_index].grids[0].shortName,
                         'GDA94_GDA2020_conformal_and_distortion.gsb')
        self.assertEqual(ops[op2_index].grids[0].fullName, '')
        self.assertEqual(ops[op2_index].grids[0].packageName,
                         'proj-datumgrid-oceania')
        self.assertEqual(
            ops[op2_index].grids[0].url,
            'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip'
        )
        self.assertTrue(ops[op2_index].grids[0].directDownload)
        self.assertTrue(ops[op2_index].grids[0].openLicense)

        op3_index = [
            i for i in range(len(ops)) if ops[i].proj ==
            '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        ][0]
        self.assertTrue(ops[op3_index].name)
        self.assertEqual(
            ops[op3_index].proj,
            '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        )
        self.assertEqual(
            ops[op3_index].accuracy,
            0.05)  # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op3_index].grids), 1)
        self.assertEqual(ops[op3_index].grids[0].shortName,
                         'GDA94_GDA2020_conformal.gsb')
        self.assertEqual(ops[op3_index].grids[0].fullName, '')
        self.assertEqual(ops[op3_index].grids[0].packageName,
                         'proj-datumgrid-oceania')
        self.assertEqual(
            ops[op3_index].grids[0].url,
            'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip'
        )
        self.assertTrue(ops[op3_index].grids[0].directDownload)
        self.assertTrue(ops[op3_index].grids[0].openLicense)

        op4_index = [
            i for i in range(len(ops)) if ops[i].proj ==
            '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_cocos_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        ][0]
        self.assertTrue(ops[op4_index].name)
        self.assertEqual(
            ops[op4_index].proj,
            '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_cocos_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        )
        self.assertEqual(
            ops[op4_index].accuracy,
            0.05)  # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op4_index].grids), 1)
        self.assertEqual(ops[op4_index].grids[0].shortName,
                         'GDA94_GDA2020_conformal_cocos_island.gsb')
        self.assertEqual(ops[op4_index].grids[0].fullName, '')

        op5_index = [
            i for i in range(len(ops)) if ops[i].proj ==
            '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_christmas_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        ][0]
        self.assertTrue(ops[op5_index].name)
        self.assertEqual(
            ops[op5_index].proj,
            '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_christmas_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        )
        self.assertEqual(
            ops[op5_index].accuracy,
            0.05)  # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op5_index].grids), 1)
        self.assertEqual(ops[op5_index].grids[0].shortName,
                         'GDA94_GDA2020_conformal_christmas_island.gsb')
        self.assertEqual(ops[op5_index].grids[0].fullName, '')

        # uses a pivot datum (technically a proj test, but this will help me sleep at night ;)
        ops = QgsDatumTransform.operations(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem('EPSG:7899'))

        self.assertGreaterEqual(len(ops), 3)

        op1_index = [
            i for i in range(len(ops)) if ops[i].proj ==
            '+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=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
        ][0]
        self.assertTrue(ops[op1_index].name)
        self.assertEqual(
            ops[op1_index].proj,
            '+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=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
        )
        self.assertTrue(ops[op1_index].isAvailable)
        self.assertEqual(ops[op1_index].accuracy, 0.01)
        self.assertEqual(len(ops[op1_index].grids), 0)

        op2_index = [
            i for i in range(len(ops)) if ops[i].proj ==
            '+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=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
        ][0]
        self.assertTrue(ops[op2_index].name)
        self.assertEqual(
            ops[op2_index].proj,
            '+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=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
        )
        self.assertEqual(
            ops[op2_index].accuracy,
            0.05)  # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op2_index].grids), 1)
        self.assertEqual(ops[op2_index].grids[0].shortName,
                         'GDA94_GDA2020_conformal_and_distortion.gsb')
        self.assertEqual(ops[op2_index].grids[0].fullName, '')
        self.assertEqual(ops[op2_index].grids[0].packageName,
                         'proj-datumgrid-oceania')
        self.assertEqual(
            ops[op2_index].grids[0].url,
            'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip'
        )
        self.assertTrue(ops[op2_index].grids[0].directDownload)
        self.assertTrue(ops[op2_index].grids[0].openLicense)

        op3_index = [
            i for i in range(len(ops)) if ops[i].proj ==
            '+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=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
        ][0]
        self.assertTrue(ops[op3_index].name)
        self.assertEqual(
            ops[op3_index].proj,
            '+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=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'
        )
        self.assertEqual(
            ops[op3_index].accuracy,
            0.05)  # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op3_index].grids), 1)
        self.assertEqual(ops[op3_index].grids[0].shortName,
                         'GDA94_GDA2020_conformal.gsb')
        self.assertEqual(ops[op3_index].grids[0].fullName, '')
        self.assertEqual(ops[op3_index].grids[0].packageName,
                         'proj-datumgrid-oceania')
        self.assertEqual(
            ops[op3_index].grids[0].url,
            'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip'
        )
        self.assertTrue(ops[op3_index].grids[0].directDownload)
        self.assertTrue(ops[op3_index].grids[0].openLicense)
Ejemplo n.º 15
0
    def testOperations(self):
        ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem(),
                                           QgsCoordinateReferenceSystem())
        self.assertEqual(ops, [])
        ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:3111'),
                                           QgsCoordinateReferenceSystem())
        self.assertEqual(ops, [])
        ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem(),
                                           QgsCoordinateReferenceSystem('EPSG:3111'))
        self.assertEqual(ops, [])

        ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:3111'),
                                           QgsCoordinateReferenceSystem('EPSG:3111'))
        self.assertEqual(len(ops), 1)
        self.assertTrue(ops[0].name)
        self.assertEqual(ops[0].proj, '+proj=noop')
        self.assertEqual(ops[0].accuracy, 0.0)
        self.assertTrue(ops[0].isAvailable)

        ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:3111'),
                                           QgsCoordinateReferenceSystem('EPSG:4283'))
        self.assertEqual(len(ops), 1)
        self.assertTrue(ops[0].name)
        self.assertEqual(ops[0].proj, '+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.assertEqual(ops[0].accuracy, -1.0)
        self.assertTrue(ops[0].isAvailable)

        ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:3111'),
                                           QgsCoordinateReferenceSystem('EPSG:28355'))
        self.assertEqual(len(ops), 1)
        self.assertTrue(ops[0].name)
        self.assertEqual(ops[0].proj, '+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=utm +zone=55 +south +ellps=GRS80')
        self.assertEqual(ops[0].accuracy, 0.0)
        self.assertTrue(ops[0].isAvailable)

        # uses a grid file
        ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:4283'),
                                           QgsCoordinateReferenceSystem('EPSG:7844'))
        self.assertGreaterEqual(len(ops), 5)

        op1_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'][0]
        self.assertTrue(ops[op1_index].name)
        self.assertEqual(ops[op1_index].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
        self.assertTrue(ops[op1_index].isAvailable)
        self.assertEqual(ops[op1_index].accuracy, 0.01)
        self.assertEqual(len(ops[op1_index].grids), 0)

        op2_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'][0]
        self.assertTrue(ops[op2_index].name)
        self.assertEqual(ops[op2_index].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
        self.assertEqual(ops[op2_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op2_index].grids), 1)
        self.assertEqual(ops[op2_index].grids[0].shortName, 'GDA94_GDA2020_conformal_and_distortion.gsb')
        self.assertEqual(ops[op2_index].grids[0].fullName, '')
        self.assertEqual(ops[op2_index].grids[0].packageName, 'proj-datumgrid-oceania')
        self.assertEqual(ops[op2_index].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
        self.assertTrue(ops[op2_index].grids[0].directDownload)
        self.assertTrue(ops[op2_index].grids[0].openLicense)

        op3_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'][0]
        self.assertTrue(ops[op3_index].name)
        self.assertEqual(ops[op3_index].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
        self.assertEqual(ops[op3_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op3_index].grids), 1)
        self.assertEqual(ops[op3_index].grids[0].shortName, 'GDA94_GDA2020_conformal.gsb')
        self.assertEqual(ops[op3_index].grids[0].fullName, '')
        self.assertEqual(ops[op3_index].grids[0].packageName, 'proj-datumgrid-oceania')
        self.assertEqual(ops[op3_index].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
        self.assertTrue(ops[op3_index].grids[0].directDownload)
        self.assertTrue(ops[op3_index].grids[0].openLicense)

        op4_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_cocos_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'][0]
        self.assertTrue(ops[op4_index].name)
        self.assertEqual(ops[op4_index].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_cocos_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
        self.assertEqual(ops[op4_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op4_index].grids), 1)
        self.assertEqual(ops[op4_index].grids[0].shortName, 'GDA94_GDA2020_conformal_cocos_island.gsb')
        self.assertEqual(ops[op4_index].grids[0].fullName, '')

        op5_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_christmas_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'][0]
        self.assertTrue(ops[op5_index].name)
        self.assertEqual(ops[op5_index].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_christmas_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
        self.assertEqual(ops[op5_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op5_index].grids), 1)
        self.assertEqual(ops[op5_index].grids[0].shortName, 'GDA94_GDA2020_conformal_christmas_island.gsb')
        self.assertEqual(ops[op5_index].grids[0].fullName, '')

        # uses a pivot datum (technically a proj test, but this will help me sleep at night ;)
        ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:3111'),
                                           QgsCoordinateReferenceSystem('EPSG:7899'))

        self.assertGreaterEqual(len(ops), 3)

        op1_index = [i for i in range(len(ops)) if ops[i].proj == '+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=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'][0]
        self.assertTrue(ops[op1_index].name)
        self.assertEqual(ops[op1_index].proj, '+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=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80')
        self.assertTrue(ops[op1_index].isAvailable)
        self.assertEqual(ops[op1_index].accuracy, 0.01)
        self.assertEqual(len(ops[op1_index].grids), 0)

        op2_index = [i for i in range(len(ops)) if ops[i].proj == '+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=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'][0]
        self.assertTrue(ops[op2_index].name)
        self.assertEqual(ops[op2_index].proj, '+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=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80')
        self.assertEqual(ops[op2_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op2_index].grids), 1)
        self.assertEqual(ops[op2_index].grids[0].shortName, 'GDA94_GDA2020_conformal_and_distortion.gsb')
        self.assertEqual(ops[op2_index].grids[0].fullName, '')
        self.assertEqual(ops[op2_index].grids[0].packageName, 'proj-datumgrid-oceania')
        self.assertEqual(ops[op2_index].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
        self.assertTrue(ops[op2_index].grids[0].directDownload)
        self.assertTrue(ops[op2_index].grids[0].openLicense)

        op3_index = [i for i in range(len(ops)) if ops[i].proj == '+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=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'][0]
        self.assertTrue(ops[op3_index].name)
        self.assertEqual(ops[op3_index].proj, '+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=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80')
        self.assertEqual(ops[op3_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
        self.assertEqual(len(ops[op3_index].grids), 1)
        self.assertEqual(ops[op3_index].grids[0].shortName, 'GDA94_GDA2020_conformal.gsb')
        self.assertEqual(ops[op3_index].grids[0].fullName, '')
        self.assertEqual(ops[op3_index].grids[0].packageName, 'proj-datumgrid-oceania')
        self.assertEqual(ops[op3_index].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
        self.assertTrue(ops[op3_index].grids[0].directDownload)
        self.assertTrue(ops[op3_index].grids[0].openLicense)
    def testOperations(self):
        w = QgsCoordinateOperationWidget()
        self.assertFalse(w.hasSelection())
        spy = QSignalSpy(w.operationChanged)
        w.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:26745'))
        self.assertEqual(len(spy), 0)
        w.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
        self.assertEqual(len(spy), 1)
        self.assertTrue(w.hasSelection())
        self.assertGreaterEqual(len(w.availableOperations()), 3)

        available_operations = QgsDatumTransform.operations(
            w.sourceCrs(), w.destinationCrs())
        for op in available_operations:
            if op.isAvailable:
                default_proj = op.proj
                break
        else:
            self.assertTrue(False, 'No operations available')

        self.assertEqual(w.defaultOperation().proj, default_proj)
        self.assertEqual(w.selectedOperation().proj, default_proj)
        self.assertTrue(w.selectedOperation().isAvailable)

        op = QgsCoordinateOperationWidget.OperationDetails()
        op.proj = '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        op.allowFallback = True
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertTrue(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 2)
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertTrue(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 2)

        op.proj = '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=159 +z=175 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        op.allowFallback = False
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=159 +z=175 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertFalse(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 3)

        op.allowFallback = True
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=159 +z=175 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertTrue(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 4)

        context = QgsCoordinateTransformContext()
        op.proj = '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        w.setSelectedOperation(op)
        w.setSelectedOperationUsingContext(context)
        # should go to default, because there's nothing in the context matching these crs
        self.assertEqual(w.selectedOperation().proj, default_proj)
        self.assertEqual(len(spy), 6)

        # put something in the context
        context.addCoordinateOperation(
            w.sourceCrs(), w.destinationCrs(),
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        w.setSelectedOperationUsingContext(context)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertTrue(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 7)

        context.addCoordinateOperation(
            w.sourceCrs(), w.destinationCrs(),
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84',
            False)
        w.setSelectedOperationUsingContext(context)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertFalse(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 8)