Skip to content
Permalink
Browse files

[Tests] Check that GDAL Assign Projection updates QgsRasterLayer info

  • Loading branch information
rldhont committed Jul 31, 2020
1 parent 6c44073 commit f5b819fc4c1291d653c96a398662e1b663a03dfb
Showing with 37 additions and 1 deletion.
  1. +37 −1 python/plugins/processing/tests/GdalAlgorithmsRasterTest.py
@@ -28,7 +28,9 @@

from qgis.core import (QgsProcessingContext,
QgsProcessingFeedback,
QgsRectangle)
QgsRectangle,
QgsRasterLayer,
QgsProject)

from qgis.testing import (start_app,
unittest)
@@ -133,6 +135,40 @@ def testAssignProjection(self):
'-a_srs EPSG:3111 ' +
source])

@unittest.skipIf(os.environ.get('TRAVIS', '') == 'true',
'gdal_edit.py: not found')
def testRunAssignProjection(self):
# Check that assign projection updates QgsRasterLayer info
# GDAL Assign Projection is based on gdal_edit.py

context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
source = os.path.join(testDataPath, 'dem.tif')
alg = AssignProjection()
alg.initAlgorithm()

with tempfile.TemporaryDirectory() as outdir:
fake_dem = os.path.join(outdir, 'dem-fake-crs.tif')

shutil.copy(source, fake_dem)
self.assertTrue(os.path.exists(fake_dem))

rlayer = QgsRasterLayer(fake_dem, "Fake dem")
self.assertTrue(rlayer.isValid())

self.assertEqual(rlayer.crs().authid(), 'EPSG:4326')

project = QgsProject()
project.setFileName(os.path.join(outdir, 'dem-fake-crs.qgs'))
project.addMapLayer(rlayer)
self.assertEqual(project.count(), 1)

context.setProject(project)

alg.run({'INPUT': fake_dem, 'CRS': 'EPSG:3111'},
context, feedback)
self.assertEqual(rlayer.crs().authid(), 'EPSG:3111')

def testGdalTranslate(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()

0 comments on commit f5b819f

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