Skip to content

Commit

Permalink
Add some more datum related unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 15, 2017
1 parent 69c3deb commit ab5d895
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/src/python/test_qgscoordinatetransform.py
Expand Up @@ -207,6 +207,17 @@ def testProjectContext(self):
self.assertEqual(transform.sourceDatumTransformId(), 1)
self.assertEqual(transform.destinationDatumTransformId(), 2)

def testTransformInfo(self):
# hopefully this transform is available on all platforms!
transforms = QgsCoordinateTransform.datumTransformations(QgsCoordinateReferenceSystem(4613), QgsCoordinateReferenceSystem(4326))
self.assertTrue(len(transforms) > 0)
self.assertIn('+towgs84=-403,684,41', [QgsCoordinateTransform.datumTransformToProj(t.sourceTransformId) for t in transforms])
self.assertIn('+towgs84=-403,684,41', [QgsCoordinateTransform.datumTransformToProj(t.destinationTransformId) for t in transforms])
self.assertIn('EPSG:4613', [QgsCoordinateTransform.datumTransformInfo(t.destinationTransformId).sourceCrsAuthId for t in
transforms])
self.assertIn('EPSG:4326', [QgsCoordinateTransform.datumTransformInfo(t.destinationTransformId).destinationCrsAuthId for t in
transforms])


if __name__ == '__main__':
unittest.main()
44 changes: 43 additions & 1 deletion tests/src/python/test_qgscoordinatetransformcontext.py
Expand Up @@ -18,16 +18,26 @@
QgsCoordinateTransformContext,
QgsCoordinateTransform,
QgsReadWriteContext,
QgsProject)
QgsProject,
QgsSettings)
from qgis.testing import start_app, unittest
from qgis.PyQt.QtXml import QDomDocument
from qgis.PyQt.QtTest import QSignalSpy
from qgis.PyQt.QtCore import QCoreApplication

app = start_app()


class TestQgsCoordinateTransformContext(unittest.TestCase):

@classmethod
def setUpClass(cls):
"""Run before all tests"""
QCoreApplication.setOrganizationName("QGIS_Test")
QCoreApplication.setOrganizationDomain("TestPyQgsWFSProvider.com")
QCoreApplication.setApplicationName("TestPyQgsWFSProvider")
QgsSettings().clear()

@unittest.skip('ifdefed out in c++ until required')
def testSourceDatumTransforms(self):
context = QgsCoordinateTransformContext()
Expand Down Expand Up @@ -249,6 +259,10 @@ def testCalculateSourceDest(self):
self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:28356'),
QgsCoordinateReferenceSystem('EPSG:3111')),
QgsCoordinateTransform.TransformPair(-1, -1))
# check that reverse transforms are automatically supported
self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:4283'),
QgsCoordinateReferenceSystem('EPSG:28356')),
QgsCoordinateTransform.TransformPair(4, 3))

@unittest.skip('ifdefed out in c++ until required')
def testWriteReadXmlSingleVariant(self):
Expand Down Expand Up @@ -320,6 +334,34 @@ def testProject(self):
self.assertEqual(len(context_changed_spy), 1)
self.assertEqual(project.transformContext().sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): QgsCoordinateTransform.TransformPair(1, 2)})

def testReadWriteSettings(self):
context = QgsCoordinateTransformContext()
context.readSettings()
# should be empty
self.assertEqual(context.sourceDestinationDatumTransforms(), {})

self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2))
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
QgsCoordinateReferenceSystem(4283), 3, 4))

self.assertEqual(context.sourceDestinationDatumTransforms(),
{('EPSG:3111', 'EPSG:4283'): QgsCoordinateTransform.TransformPair(1, 2),
('EPSG:28356', 'EPSG:4283'): QgsCoordinateTransform.TransformPair(3, 4)})

# save to settings
context.writeSettings()

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

# check result
self.assertEqual(context2.sourceDestinationDatumTransforms(),
{('EPSG:3111', 'EPSG:4283'): QgsCoordinateTransform.TransformPair(1, 2),
('EPSG:28356', 'EPSG:4283'): QgsCoordinateTransform.TransformPair(3, 4)})


if __name__ == '__main__':
unittest.main()

0 comments on commit ab5d895

Please sign in to comment.