From fce87ff43b0daf98da0c161e42812ca88c4d4b32 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 14 May 2024 09:37:31 +1000 Subject: [PATCH] Update tests --- felt/test/test_layer_exporter.py | 67 ++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/felt/test/test_layer_exporter.py b/felt/test/test_layer_exporter.py index c945f6d..f675207 100644 --- a/felt/test/test_layer_exporter.py +++ b/felt/test/test_layer_exporter.py @@ -12,7 +12,9 @@ QgsRasterLayer, QgsCoordinateTransformContext, QgsCoordinateReferenceSystem, - QgsWkbTypes + QgsWkbTypes, + QgsPalettedRasterRenderer, + QgsRasterContourRenderer ) from .utilities import get_qgis_app @@ -220,13 +222,15 @@ def test_raster_conversion_raw(self): file = str(TEST_DATA_PATH / 'dem.tif') layer = QgsRasterLayer(file, 'test') self.assertTrue(layer.isValid()) + # set a renderer we can convert + renderer = QgsPalettedRasterRenderer(layer.dataProvider(), 1, []) + layer.setRenderer(renderer) exporter = LayerExporter( QgsCoordinateTransformContext() ) result = exporter.export_layer_for_felt( - layer, - force_upload_raster_as_styled=False + layer ) self.assertEqual(result.result, LayerExportResult.Success) self.assertTrue(result.filename) @@ -313,6 +317,63 @@ def test_raster_conversion_styled(self): self.assertAlmostEqual(out_layer.extent().yMaximum(), 45.8117014376, 3) + def test_raster_conversion_no_fsl_conversion(self): + """ + Test raster layer conversion + """ + file = str(TEST_DATA_PATH / 'dem.tif') + layer = QgsRasterLayer(file, 'test') + self.assertTrue(layer.isValid()) + + # set a renderer we can't convert to FSL + renderer = QgsRasterContourRenderer(layer.dataProvider()) + layer.setRenderer(renderer) + + exporter = LayerExporter( + QgsCoordinateTransformContext() + ) + result = exporter.export_layer_for_felt( + layer, + force_upload_raster_as_styled=False + ) + self.assertEqual(result.result, LayerExportResult.Success) + self.assertTrue(result.filename) + self.assertEqual(result.filename[-4:], '.zip') + with zipfile.ZipFile(result.filename) as z: + tif_files = [f for f in z.namelist() if f.endswith('tif')] + self.assertEqual(len(tif_files), 1) + + self.assertEqual( + result.qgis_style_xml[:58], + "" + ) + + out_layer = QgsRasterLayer( + '/vsizip/{}/{}'.format(result.filename, tif_files[0]), + 'test') + self.assertTrue(out_layer.isValid()) + self.assertEqual(out_layer.width(), 373) + self.assertEqual(out_layer.height(), 350) + self.assertEqual(out_layer.bandCount(), 4) + self.assertEqual(out_layer.dataProvider().dataType(1), + Qgis.DataType.Byte) + self.assertEqual(out_layer.dataProvider().dataType(2), + Qgis.DataType.Byte) + self.assertEqual(out_layer.dataProvider().dataType(3), + Qgis.DataType.Byte) + self.assertEqual(out_layer.dataProvider().dataType(4), + Qgis.DataType.Byte) + self.assertEqual(out_layer.crs(), + QgsCoordinateReferenceSystem('EPSG:4326')) + self.assertAlmostEqual(out_layer.extent().xMinimum(), + 18.6662979442, 3) + self.assertAlmostEqual(out_layer.extent().xMaximum(), + 18.7035979442, 3) + self.assertAlmostEqual(out_layer.extent().yMinimum(), + 45.7767014376, 3) + self.assertAlmostEqual(out_layer.extent().yMaximum(), + 45.8117014376, 3) + if __name__ == "__main__": suite = unittest.makeSuite(LayerExporterTest)