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 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 testReadWriteSettings(self):
        context = QgsCoordinateTransformContext()
        context.readSettings()

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

        source_id_2 = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem('EPSG:4205'),
            QgsCoordinateReferenceSystem('EPSG:4326'))[0].sourceTransformId
        dest_id_2 = QgsDatumTransform.datumTransformations(
            QgsCoordinateReferenceSystem('EPSG:4205'),
            QgsCoordinateReferenceSystem(
                'EPSG: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('EPSG: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)
            })
Exemple #4
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 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)})