Skip to content

Commit

Permalink
add test for MVT conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jul 22, 2024
1 parent d723e6b commit 4dd28bf
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions tests/src/python/test_qgsmapboxglconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 0 WHEN "luminosity" IN (-14) THEN 0 WHEN "luminosity" IN (-13) THEN 0 WHEN "luminosity" IN (-12) THEN 0 WHEN "luminosity" IN (-11) THEN 0 WHEN "luminosity" IN (-10) THEN 0 WHEN "luminosity" IN (-9) THEN 0 WHEN "luminosity" IN (-8) THEN 0 WHEN "luminosity" IN (-7) THEN 0 WHEN "luminosity" IN (-6) THEN 0 WHEN "luminosity" IN (-5) THEN 0 WHEN "luminosity" IN (-4) THEN 0 WHEN "luminosity" IN (-3) THEN 0 WHEN "luminosity" IN (-2) THEN 0 WHEN "luminosity" IN (-1) THEN 0 ELSE 0 END')
self.assertEqual(default_number, 0.0)

def testParseValueList(self):
conversion_context = QgsMapBoxGlStyleConversionContext()
res, default_color, default_number = QgsMapBoxGlStyleConverter.parseValueList([
Expand Down Expand Up @@ -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 >= 14 AND @vector_tile_zoom < 16 THEN color_hsla(color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'hsl_hue\'), color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'hsl_saturation\'), color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'lightness\'), color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'alpha\')) WHEN @vector_tile_zoom >= 16 THEN color_hsla(color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'hsl_hue\'), color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'hsl_saturation\'), color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'lightness\'), color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'alpha\')) ELSE color_hsla(color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'hsl_hue\'), color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'hsl_saturation\'), color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'lightness\'), color_part(CASE WHEN "class" IN (\'roof\', \'cooling_tower\') THEN color_rgba(210,210,214,255) ELSE color_rgba(184,184,188,255) END,\'alpha\')) END')


if __name__ == '__main__':
unittest.main()

0 comments on commit 4dd28bf

Please sign in to comment.