From f716a9ac44a87bacae0e56d4b551a03b24523aa6 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Fri, 19 Jul 2024 08:35:16 +0200 Subject: [PATCH] add test for MVT conversion --- tests/src/python/test_qgsmapboxglconverter.py | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/tests/src/python/test_qgsmapboxglconverter.py b/tests/src/python/test_qgsmapboxglconverter.py index 7ffd08900411..4642c21acf9a 100644 --- a/tests/src/python/test_qgsmapboxglconverter.py +++ b/tests/src/python/test_qgsmapboxglconverter.py @@ -179,6 +179,47 @@ def testParseMatchList(self): 'CASE WHEN "type" IN (\'Normal\') THEN 0.625 WHEN "type" IN (\'Index\') THEN 1.25 ELSE 0.5 END') self.assertEqual(default_number, 0.5) + res, default_color, default_number = QgsMapBoxGlStyleConverter.parseMatchList([ + "match", + [ + "get", + "luminosity" + ], + -15, + "rgb(200,210,213)", + -14, + "rgb(203,213,216)", + -13, + "rgb(207,215,218)", + -12, + "rgb(210,218,221)", + -11, + "rgb(213,221,224)", + -10, + "rgb(217,224,226)", + -9, + "rgb(220,227,229)", + -8, + "rgb(224,230,231)", + -7, + "rgb(227,232,234)", + -6, + "rgb(231,235,237)", + -5, + "rgb(234,238,239)", + -4, + "rgb(238,241,242)", + -3, + "rgb(241,244,245)", + -2, + "rgb(245,247,247)", + -1, + "rgb(248,249,250)", + "rgb(252, 252, 252)" + ], QgsMapBoxGlStyleConverter.PropertyType.Numeric, conversion_context, 2.5, 200) + self.assertEqual(res.asExpression(), 'CASE WHEN "luminosity" IN (-15) THEN \'#c8d2d5\' WHEN "luminosity" IN (-14) THEN \'#cbd5d8\' WHEN "luminosity" IN (-13) THEN \'#cfd7da\' WHEN "luminosity" IN (-12) THEN \'#d2dadd\' WHEN "luminosity" IN (-11) THEN \'#d5dde0\' WHEN "luminosity" IN (-10) THEN \'#d9e0e2\' WHEN "luminosity" IN (-9) THEN \'#dce3e5\' WHEN "luminosity" IN (-8) THEN \'#e0e6e7\' WHEN "luminosity" IN (-7) THEN \'#e3e8ea\' WHEN "luminosity" IN (-6) THEN \'#e7ebed\' WHEN "luminosity" IN (-5) THEN \'#eaeeef\' WHEN "luminosity" IN (-4) THEN \'#eef1f2\' WHEN "luminosity" IN (-3) THEN \'#f1f4f5\' WHEN "luminosity" IN (-2) THEN \'#f5f7f7\' WHEN "luminosity" IN (-1) THEN \'#f8f9fa\' ELSE \'#fcfcfc\' END') + self.assertEqual(default_number, 0.5) + def testParseValueList(self): conversion_context = QgsMapBoxGlStyleConversionContext() res, default_color, default_number = QgsMapBoxGlStyleConverter.parseValueList([ @@ -1293,6 +1334,74 @@ def testFillOpacityWithStops(self): prop = dd_props.property(QgsSymbolLayer.Property.PropertyFillColor) self.assertEqual(prop.asExpression(), 'CASE WHEN @vector_tile_zoom < 0 THEN color_hsla(66, 25, 85, 255) WHEN @vector_tile_zoom >= 0 AND @vector_tile_zoom < 8 THEN color_hsla(66, 25, 85, 255) WHEN @vector_tile_zoom >= 8 AND @vector_tile_zoom < 14 THEN color_hsla(66, 25, 85, 255) WHEN @vector_tile_zoom >= 14 AND @vector_tile_zoom < 15 THEN color_hsla(66, scale_linear(@vector_tile_zoom,14,15,25,21), scale_linear(@vector_tile_zoom,14,15,85,90), 255) WHEN @vector_tile_zoom >= 15 AND @vector_tile_zoom < 17 THEN color_hsla(scale_linear(@vector_tile_zoom,15,17,66,67), scale_linear(@vector_tile_zoom,15,17,21,23), scale_linear(@vector_tile_zoom,15,17,90,93), 255) WHEN @vector_tile_zoom >= 17 THEN color_hsla(67, 23, 93, 255) ELSE color_hsla(67, 23, 93, 255) END') + def testFillColorDDHasBrush(self): + context = QgsMapBoxGlStyleConversionContext() + # from https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json + style = { + "id": "building_fill", + "type": "fill", + "source": "base_v1.0.0", + "source-layer": "building", + "minzoom": 14.0, + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": [ + "interpolate", + [ + "linear" + ], + [ + "zoom" + ], + 14, + [ + "match", + [ + "get", + "class" + ], + [ + "roof", + "cooling_tower" + ], + "rgb(210, 210, 214)", + "rgba(184, 184, 188, 1)" + ], + 16, + [ + "match", + [ + "get", + "class" + ], + [ + "roof", + "cooling_tower" + ], + "rgb(210, 210, 214)", + "rgba(184, 184, 188, 1)" + ] + ], + "fill-opacity": 1 + }, + "filter": [ + "all", + [ + "!=", + "class", + "covered_bridge" + ] + ] + } + has_renderer, renderer = QgsMapBoxGlStyleConverter.parseFillLayer(style, context) + self.assertTrue(has_renderer) + self.assertEqual(renderer.symbol()[0].brushStyle(), Qt.BrushStyle.SolidPattern) + dd_props = renderer.symbol()[0].dataDefinedProperties() + prop = dd_props.property(QgsSymbolLayer.Property.PropertyFillColor) + self.assertEqual(prop.asExpression(), 'CASE WHEN @vector_tile_zoom < 13 THEN color_hsla(220, 9, 81, 255) WHEN @vector_tile_zoom >= 13 AND @vector_tile_zoom < 17 THEN color_hsla(220, 9, scale_linear(@vector_tile_zoom,13,17,81,74), 255) WHEN @vector_tile_zoom >= 17 THEN color_hsla(220, 9, 74, 255) ELSE color_hsla(220, 9, 74, 255) END') + if __name__ == '__main__': unittest.main()