|
27 | 27 |
|
28 | 28 | class TestQgsCoordinateTransformContext(unittest.TestCase):
|
29 | 29 |
|
| 30 | + @unittest.skip('ifdefed out in c++ until required') |
30 | 31 | def testSourceDatumTransforms(self):
|
31 | 32 | context = QgsCoordinateTransformContext()
|
32 | 33 | self.assertEqual(context.sourceDatumTransforms(), {})
|
@@ -58,6 +59,7 @@ def testSourceDatumTransforms(self):
|
58 | 59 | context.clear()
|
59 | 60 | self.assertEqual(context.sourceDatumTransforms(), {})
|
60 | 61 |
|
| 62 | + @unittest.skip('ifdefed out in c++ until required') |
61 | 63 | def testDestDatumTransforms(self):
|
62 | 64 | context = QgsCoordinateTransformContext()
|
63 | 65 | self.assertEqual(context.destinationDatumTransforms(), {})
|
@@ -171,6 +173,7 @@ def testSourceDestinationDatumTransforms(self):
|
171 | 173 | context.clear()
|
172 | 174 | self.assertEqual(context.sourceDestinationDatumTransforms(), {})
|
173 | 175 |
|
| 176 | + @unittest.skip('ifdefed out in c++ until required') |
174 | 177 | def testCalculate(self):
|
175 | 178 | context = QgsCoordinateTransformContext()
|
176 | 179 |
|
@@ -217,7 +220,30 @@ def testCalculate(self):
|
217 | 220 | QgsCoordinateReferenceSystem('EPSG:3111')),
|
218 | 221 | (1, -1))
|
219 | 222 |
|
220 |
| - def testWriteReadXml(self): |
| 223 | + def testCalculateSourceDest(self): |
| 224 | + context = QgsCoordinateTransformContext() |
| 225 | + |
| 226 | + #empty context |
| 227 | + self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:3111'), |
| 228 | + QgsCoordinateReferenceSystem('EPSG:4283')), |
| 229 | + (-1, -1)) |
| 230 | + |
| 231 | + #add specific source/dest pair - should take precedence |
| 232 | + context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'), |
| 233 | + QgsCoordinateReferenceSystem('EPSG:4283'), |
| 234 | + 3, 4) |
| 235 | + self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:28356'), |
| 236 | + QgsCoordinateReferenceSystem('EPSG:4283')), |
| 237 | + (3, 4)) |
| 238 | + self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:3111'), |
| 239 | + QgsCoordinateReferenceSystem('EPSG:4283')), |
| 240 | + (-1, -1)) |
| 241 | + self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:28356'), |
| 242 | + QgsCoordinateReferenceSystem('EPSG:3111')), |
| 243 | + (-1, -1)) |
| 244 | + |
| 245 | + @unittest.skip('ifdefed out in c++ until required') |
| 246 | + def testWriteReadXmlSingleVariant(self): |
221 | 247 | # setup a context
|
222 | 248 | context = QgsCoordinateTransformContext()
|
223 | 249 | self.assertTrue(context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1))
|
@@ -249,17 +275,42 @@ def testWriteReadXml(self):
|
249 | 275 | self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
|
250 | 276 | ('EPSG:28356', 'EPSG:4283'): (3, 4)})
|
251 | 277 |
|
| 278 | + def testWriteReadXml(self): |
| 279 | + # setup a context |
| 280 | + context = QgsCoordinateTransformContext() |
| 281 | + self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), |
| 282 | + QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2)) |
| 283 | + self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'), |
| 284 | + QgsCoordinateReferenceSystem(4283), 3, 4)) |
| 285 | + |
| 286 | + self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2), |
| 287 | + ('EPSG:28356', 'EPSG:4283'): (3, 4)}) |
| 288 | + |
| 289 | + # save to xml |
| 290 | + doc = QDomDocument("testdoc") |
| 291 | + elem = doc.createElement("test") |
| 292 | + context.writeXml(elem, doc, QgsReadWriteContext()) |
| 293 | + |
| 294 | + # restore from xml |
| 295 | + context2 = QgsCoordinateTransformContext() |
| 296 | + context2.readXml(elem, doc, QgsReadWriteContext()) |
| 297 | + |
| 298 | + # check result |
| 299 | + self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2), |
| 300 | + ('EPSG:28356', 'EPSG:4283'): (3, 4)}) |
| 301 | + |
252 | 302 | def testProject(self):
|
253 | 303 | """
|
254 | 304 | Test project's transform context
|
255 | 305 | """
|
256 | 306 | project = QgsProject()
|
257 | 307 | context_changed_spy = QSignalSpy(project.transformContextChanged)
|
258 | 308 | context = project.transformContext()
|
259 |
| - context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1) |
| 309 | + context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), |
| 310 | + QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2) |
260 | 311 | project.setTransformContext(context)
|
261 | 312 | self.assertEqual(len(context_changed_spy), 1)
|
262 |
| - self.assertEqual(project.transformContext().sourceDatumTransforms(), {'EPSG:3111': 1}) |
| 313 | + self.assertEqual(project.transformContext().sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2)}) |
263 | 314 |
|
264 | 315 |
|
265 | 316 | if __name__ == '__main__':
|
|
0 commit comments