Skip to content
Permalink
Browse files

fix some deprecation warnings in the QgsRasterLayer Python test

  • Loading branch information
alexbruy committed Jun 30, 2020
1 parent ce3cc7c commit e87aa998a78a4ad104495067e2c86dc9939ef308
Showing with 17 additions and 17 deletions.
  1. +17 −17 tests/src/python/test_qgsrasterlayer.py
@@ -1306,71 +1306,71 @@ def setUp(self):
"""Prepare tc"""
super(TestQgsRasterLayerTransformContext, self).setUp()
self.ctx = QgsCoordinateTransformContext()
self.ctx.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(4326),
QgsCoordinateReferenceSystem(3857), 1234, 1235)
self.ctx.addCoordinateOperation(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857), 'test')
self.ctx.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:4326'),
QgsCoordinateReferenceSystem('EPSG:3857'), 1234, 1235)
self.ctx.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857'), 'test')
self.rpath = os.path.join(unitTestDataPath(), 'landsat.tif')

def testTransformContextIsSetInCtor(self):
"""Test transform context can be set from ctor"""

rl = QgsRasterLayer(self.rpath, 'raster')
self.assertFalse(
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))

options = QgsRasterLayer.LayerOptions(transformContext=self.ctx)
rl = QgsRasterLayer(self.rpath, 'raster', 'gdal', options)
self.assertTrue(
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))

def testTransformContextInheritsFromProject(self):
"""Test that when a layer is added to a project it inherits its context"""

rl = QgsRasterLayer(self.rpath, 'raster')
self.assertFalse(
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))

p = QgsProject()
self.assertFalse(
p.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
p.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))
p.setTransformContext(self.ctx)
self.assertTrue(
p.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
p.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))

p.addMapLayers([rl])
self.assertTrue(
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))

def testTransformContextIsSyncedFromProject(self):
"""Test that when a layer is synced when project context changes"""

rl = QgsRasterLayer(self.rpath, 'raster')
self.assertFalse(
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))

p = QgsProject()
self.assertFalse(
p.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
p.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))
p.setTransformContext(self.ctx)
self.assertTrue(
p.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
p.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))

p.addMapLayers([rl])
self.assertTrue(
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))

# Now change the project context
tc2 = QgsCoordinateTransformContext()
p.setTransformContext(tc2)
self.assertFalse(
p.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
p.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))
self.assertFalse(
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))
p.setTransformContext(self.ctx)
self.assertTrue(
p.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
p.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))
self.assertTrue(
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857)))
rl.transformContext().hasTransform(QgsCoordinateReferenceSystem('EPSG:4326'), QgsCoordinateReferenceSystem('EPSG:3857')))


if __name__ == '__main__':

0 comments on commit e87aa99

Please sign in to comment.
You can’t perform that action at this time.