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 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)
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 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)