Exemplo n.º 1
2
    def testRenderLineLayerDataDefined(self):
        """ test that rendering a line symbol with data defined enabled layer works"""

        lines_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
        lines_layer = QgsVectorLayer(lines_shp, 'Lines', 'ogr')
        QgsProject.instance().addMapLayer(lines_layer)

        layer = QgsSimpleLineSymbolLayer()
        layer.setDataDefinedProperty(QgsSymbolLayer.PropertyLayerEnabled, QgsProperty.fromExpression("Name='Highway'"))
        layer.setColor(QColor(100, 150, 150))
        layer.setWidth(5)

        symbol = QgsLineSymbol()
        symbol.changeSymbolLayer(0, layer)
        lines_layer.setRenderer(QgsSingleSymbolRenderer(symbol))

        ms = QgsMapSettings()
        ms.setOutputSize(QSize(400, 400))
        ms.setOutputDpi(96)
        ms.setExtent(QgsRectangle(-133, 22, -70, 52))
        ms.setLayers([lines_layer])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(ms)
        renderchecker.setControlPathPrefix('symbol_layer')
        renderchecker.setControlName('expected_linelayer_ddenabled')
        self.assertTrue(renderchecker.runTest('linelayer_ddenabled'))
        QgsProject.instance().removeMapLayer(lines_layer)
    def testOrderBy(self):
        self.renderer.setOrderBy(QgsFeatureRequest.OrderBy([QgsFeatureRequest.OrderByClause('Value', False)]))
        self.renderer.setOrderByEnabled(True)

        # Setup rendering check
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_singlesymbol_orderby')
        self.assertTrue(renderchecker.runTest('singlesymbol_orderby'))

        # disable order by and retest
        self.renderer.setOrderByEnabled(False)
        self.assertTrue(renderchecker.runTest('single'))
Exemplo n.º 3
0
    def test_3(self):
        sym = self.lines_layer.renderer().symbol()
        # double headed
        sym_layer = QgsArrowSymbolLayer.create(
            {
                "arrow_width": "7",
                "head_length": "6",
                "head_thickness": "8",
                "head_type": "0",
                "arrow_type": "1",
                "is_curved": "0",
            }
        )
        fill_sym = QgsFillSymbol.createSimple(
            {"color": "#8bcfff", "outline_color": "#000000", "outline_style": "solid", "outline_width": "1"}
        )
        sym_layer.setSubSymbol(fill_sym)
        sym.changeSymbolLayer(0, sym_layer)

        rendered_layers = [self.lines_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        ms = self.mapsettings
        ms.setExtent(QgsRectangle(-101, 35, -99, 37))
        renderchecker.setMapSettings(ms)
        renderchecker.setControlName("expected_arrowsymbollayer_3")
        self.assertTrue(renderchecker.runTest("arrowsymbollayer_3"))
Exemplo n.º 4
0
    def testRenderFillLayerDataDefined(self):
        """ test that rendering a fill symbol with data defined enabled layer works"""

        polys_shp = os.path.join(TEST_DATA_DIR, 'polys.shp')
        polys_layer = QgsVectorLayer(polys_shp, 'Polygons', 'ogr')
        QgsProject.instance().addMapLayer(polys_layer)

        layer = QgsSimpleFillSymbolLayer()
        layer.setDataDefinedProperty("enabled", QgsDataDefined("Name='Lake'"))
        layer.setBorderStyle(Qt.NoPen)
        layer.setColor(QColor(100, 150, 150))

        symbol = QgsFillSymbol()
        symbol.changeSymbolLayer(0, layer)
        polys_layer.setRenderer(QgsSingleSymbolRenderer(symbol))

        ms = QgsMapSettings()
        ms.setOutputSize(QSize(400, 400))
        ms.setOutputDpi(96)
        ms.setExtent(QgsRectangle(-133, 22, -70, 52))
        ms.setLayers([polys_layer])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(ms)
        renderchecker.setControlPathPrefix('symbol_layer')
        renderchecker.setControlName('expected_filllayer_ddenabled')
        self.assertTrue(renderchecker.runTest('filllayer_ddenabled'))
        QgsProject.instance().removeMapLayer(polys_layer)
Exemplo n.º 5
0
 def testRenderWithin(self):
     self.layer.renderer().setTolerance(10)
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(self.mapsettings)
     renderchecker.setControlPathPrefix('cluster_renderer')
     renderchecker.setControlName('expected_cluster_cluster')
     self.assertTrue(renderchecker.runTest('expected_cluster_cluster'))
 def testRenderNoCluster(self):
     self.layer.renderer().setTolerance(1)
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(self.mapsettings)
     renderchecker.setControlPathPrefix('displacement_renderer')
     renderchecker.setControlName('expected_displacement_no_cluster')
     self.assertTrue(renderchecker.runTest('displacement_no_cluster'))
Exemplo n.º 7
0
    def testRenderMarkerLayerDataDefined(self):
        """ test that rendering a marker symbol with data defined enabled layer works"""

        points_shp = os.path.join(TEST_DATA_DIR, 'points.shp')
        points_layer = QgsVectorLayer(points_shp, 'Points', 'ogr')
        QgsProject.instance().addMapLayer(points_layer)

        layer = QgsSimpleMarkerSymbolLayer()
        layer.setDataDefinedProperty(QgsSymbolLayer.PropertyLayerEnabled, QgsProperty.fromExpression("Class='Biplane'"))
        layer.setColor(QColor(100, 150, 150))
        layer.setSize(5)
        layer.setStrokeStyle(Qt.NoPen)

        symbol = QgsMarkerSymbol()
        symbol.changeSymbolLayer(0, layer)
        points_layer.setRenderer(QgsSingleSymbolRenderer(symbol))

        ms = QgsMapSettings()
        ms.setOutputSize(QSize(400, 400))
        ms.setOutputDpi(96)
        ms.setExtent(QgsRectangle(-133, 22, -70, 52))
        ms.setLayers([points_layer])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(ms)
        renderchecker.setControlPathPrefix('symbol_layer')
        renderchecker.setControlName('expected_markerlayer_ddenabled')
        self.assertTrue(renderchecker.runTest('markerlayer_ddenabled'))
        QgsProject.instance().removeMapLayer(points_layer)
Exemplo n.º 8
0
    def testVectorBlending(self):
        """Test that blend modes work for vector layers."""

        # Add vector layers to map
        myLayers = []
        myLayers.append(self.mLineLayer.id())
        myLayers.append(self.mPolygonLayer.id())
        self.mapSettings.setLayers(myLayers)
        self.mapSettings.setExtent(self.extent)

        # Set blending modes for both layers
        self.mLineLayer.setBlendMode(QPainter.CompositionMode_Difference)
        self.mPolygonLayer.setBlendMode(QPainter.CompositionMode_Difference)

        checker = QgsMultiRenderChecker()
        checker.setControlName("expected_vector_blendmodes")
        checker.setMapSettings(self.mapSettings)
        checker.setColorTolerance(1)

        myResult = checker.runTest("vector_blendmodes", 20)
        myMessage = ('vector blending failed')
        assert myResult, myMessage

        # Reset layers
        self.mLineLayer.setBlendMode(QPainter.CompositionMode_SourceOver)
        self.mPolygonLayer.setBlendMode(QPainter.CompositionMode_SourceOver)
    def renderCheck(self, mismatch=0, colortol=0, imgpath='', grpprefix=''):
        """Check rendered map canvas or existing image against control image

        :mismatch: number of pixels different from control, and still valid
        :colortol: maximum difference for each color component including alpha
        :imgpath: existing image; if present, skips rendering canvas
        :grpprefix: compare test image/rendering against different test group
        """
        if not grpprefix:
            grpprefix = self._TestGroupPrefix
        chk = QgsMultiRenderChecker()

        chk.setControlPathPrefix('expected_' + grpprefix)

        chk.setControlName(self._Test)

        if imgpath:
            chk.setRenderedImage(imgpath)

        ms = self._MapSettings  # class settings
        if self._TestMapSettings is not None:
            ms = self._TestMapSettings  # per test settings
        chk.setMapSettings(ms)

        chk.setColorTolerance(colortol)
        # noinspection PyUnusedLocal
        res = chk.runTest(self._Test, mismatch)
        if PALREPORT and not res:  # don't report ok checks
            testname = self._TestGroup + ' . ' + self._Test
            PALREPORTS[testname] = chk.report()
        msg = '\nRender check failed for "{0}"'.format(self._Test)
        return res, msg
Exemplo n.º 10
0
    def testElse(self):
        # Setup rendering check
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_rulebased_else')
        result = renderchecker.runTest('rulebased_else')

        assert result
Exemplo n.º 11
0
 def testRenderGrid(self):
     self.layer.renderer().setTolerance(10)
     self.layer.renderer().setPlacement(QgsPointDisplacementRenderer.Grid)
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(self.mapsettings)
     renderchecker.setControlPathPrefix('displacement_renderer')
     renderchecker.setControlName('expected_displacement_grid')
     self.assertTrue(renderchecker.runTest('expected_displacement_grid'))
Exemplo n.º 12
0
 def testRender(self):
     # test no features are rendered
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(self.mapsettings)
     renderchecker.setControlPathPrefix('null_renderer')
     renderchecker.setControlName('expected_nullrenderer_render')
     result = renderchecker.runTest('nullrenderer_render')
     assert result
Exemplo n.º 13
0
 def testSelected(self):
     # select a feature and render
     self.layer.select([1, 2, 3])
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(self.mapsettings)
     renderchecker.setControlPathPrefix('null_renderer')
     renderchecker.setControlName('expected_nullrenderer_selected')
     result = renderchecker.runTest('nullrenderer_selected')
     assert result
 def test_marker(self):
     sym = self.renderer.symbol()
     sym_layer = QgsGeometryGeneratorSymbolLayerV2.create({'geometryModifier': 'centroid($geometry)'})
     sym_layer.setSymbolType(QgsSymbolV2.Marker)
     sym.changeSymbolLayer(0, sym_layer)
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(self.mapsettings)
     renderchecker.setControlName('expected_geometrygenerator_marker')
     self.assertTrue(renderchecker.runTest('geometrygenerator_marker'))
Exemplo n.º 15
0
    def testDisabledElse(self):
        # Disable a rule and assert that it's hidden not rendered with else
        self.r2.setActive(False)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_rulebased_disabled_else')
        result = renderchecker.runTest('rulebased_disabled_else')

        assert result
Exemplo n.º 16
0
    def testOrderBy(self):
        self.renderer.setOrderBy(QgsFeatureRequest.OrderBy([QgsFeatureRequest.OrderByClause('Value', False)]))

        # Setup rendering check
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_singlesymbol_orderby')
        result = renderchecker.runTest('singlesymbol_orderby')

        assert result
Exemplo n.º 17
0
 def checkImage(self, name, reference_image, rendered_image, size_tolerance=0):
     checker = QgsMultiRenderChecker()
     checker.setControlPathPrefix("layout_exporter")
     checker.setControlName("expected_layoutexporter_" + reference_image)
     checker.setRenderedImage(rendered_image)
     checker.setColorTolerance(2)
     checker.setSizeTolerance(size_tolerance, size_tolerance)
     result = checker.runTest(name, 20)
     self.report += checker.report()
     print((self.report))
     return result
 def testRenderWithin(self):
     layer, renderer, mapsettings = self._setUp()
     layer.renderer().setTolerance(10)
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(mapsettings)
     renderchecker.setControlPathPrefix('displacement_renderer')
     renderchecker.setControlName('expected_displacement_cluster')
     res = renderchecker.runTest('expected_displacement_cluster')
     self.report += renderchecker.report()
     self.assertTrue(res)
     self._tearDown(layer)
    def test_marker(self):
        sym = self.polys_layer.renderer().symbol()
        sym_layer = QgsGeometryGeneratorSymbolLayer.create({"geometryModifier": "centroid($geometry)"})
        sym_layer.setSymbolType(QgsSymbol.Marker)
        sym.changeSymbolLayer(0, sym_layer)

        rendered_layers = [self.polys_layer.id()]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName("expected_geometrygenerator_marker")
        self.assertTrue(renderchecker.runTest("geometrygenerator_marker"))
 def test_mixed(self):
     sym = self.renderer.symbol()
     buffer_layer = QgsGeometryGeneratorSymbolLayerV2.create({'geometryModifier': 'buffer($geometry, "value"/15)'})
     buffer_layer.setSymbolType(QgsSymbolV2.Fill)
     buffer_layer.subSymbol()
     sym.appendSymbolLayer(buffer_layer)
     marker_layer = QgsGeometryGeneratorSymbolLayerV2.create({'geometryModifier': 'centroid($geometry)'})
     marker_layer.setSymbolType(QgsSymbolV2.Marker)
     sym.appendSymbolLayer(marker_layer)
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(self.mapsettings)
     renderchecker.setControlName('expected_geometrygenerator_mixed')
     self.assertTrue(renderchecker.runTest('geometrygenerator_mixed'))
 def testRenderGridAdjust(self):
     layer, renderer, mapsettings = self._setUp()
     layer.renderer().setTolerance(10)
     layer.renderer().setCircleRadiusAddition(5)
     layer.renderer().setPlacement(QgsPointDisplacementRenderer.Grid)
     layer.renderer().setCircleColor(QColor())
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(mapsettings)
     renderchecker.setControlPathPrefix('displacement_renderer')
     renderchecker.setControlName('expected_displacement_adjust_grid')
     res = renderchecker.runTest('expected_displacement_adjust_grid')
     self.report += renderchecker.report()
     self.assertTrue(res)
     self._tearDown(layer)
    def test_marker(self):
        sym = self.polys_layer.renderer().symbol()
        sym_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'centroid($geometry)'})
        sym_layer.setSymbolType(QgsSymbol.Marker)
        sym_layer.subSymbol().symbolLayer(0).setStrokeColor(QColor(0, 0, 0))
        sym.changeSymbolLayer(0, sym_layer)

        rendered_layers = [self.polys_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_marker')
        self.assertTrue(renderchecker.runTest('geometrygenerator_marker'))
Exemplo n.º 23
0
 def imageCheck(self, name, reference_image, image):
     self.report += "<h2>Render {}</h2>\n".format(name)
     temp_dir = QDir.tempPath() + '/'
     file_name = temp_dir + 'annotation_' + name + ".png"
     image.save(file_name, "PNG")
     checker = QgsMultiRenderChecker()
     checker.setControlPathPrefix("annotations")
     checker.setControlName("expected_" + reference_image)
     checker.setRenderedImage(file_name)
     checker.setColorTolerance(2)
     result = checker.runTest(name, 20)
     self.report += checker.report()
     print((self.report))
     return result
Exemplo n.º 24
0
    def test_2(self):
        sym = self.lines_layer.renderer().symbol()
        # double headed
        sym_layer = QgsArrowSymbolLayer.create({'arrow_width': '5', 'head_length': '4', 'head_thickness': '6', 'head_type': '2'})
        fill_sym = QgsFillSymbol.createSimple({'color': '#8bcfff', 'outline_color': '#000000', 'outline_style': 'solid', 'outline_width': '1'})
        sym_layer.setSubSymbol(fill_sym)
        sym.changeSymbolLayer(0, sym_layer)

        rendered_layers = [self.lines_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_arrowsymbollayer_2')
        self.assertTrue(renderchecker.runTest('arrowsymbollayer_2'))
    def test_buffer_lines(self):
        sym = self.lines_layer.rendererV2().symbol()

        buffer_layer = QgsGeometryGeneratorSymbolLayerV2.create({'geometryModifier': 'buffer($geometry, "value"/15)'})
        buffer_layer.setSymbolType(QgsSymbolV2.Fill)
        self.assertIsNotNone(buffer_layer.subSymbol())
        sym.appendSymbolLayer(buffer_layer)

        rendered_layers = [self.lines_layer.id()]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_buffer_lines')
        self.assertTrue(renderchecker.runTest('geometrygenerator_buffer_lines'))
 def testClusterRingLabels(self):
     layer, renderer, mapsettings = self._setUp()
     layer.renderer().setTolerance(10)
     layer.renderer().setLabelAttributeName('Class')
     layer.renderer().setLabelDistanceFactor(0.35)
     f = QgsFontUtils.getStandardTestFont('Bold', 14)
     layer.renderer().setLabelFont(f)
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(mapsettings)
     renderchecker.setControlPathPrefix('displacement_renderer')
     renderchecker.setControlName('expected_displacement_cluster_ring_labels')
     res = renderchecker.runTest('expected_displacement_cluster_ring_labels')
     self.report += renderchecker.report()
     self.assertTrue(res)
     self._tearDown(layer)
    def testPartCount(self):
        # Create rulebased style
        sym1 = QgsFillSymbol.createSimple({'color': '#fdbf6f', 'outline_color': 'black'})

        renderer = QgsSingleSymbolRenderer(sym1)
        renderer.symbols(QgsRenderContext())[0].symbolLayers()[0].setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression('color_rgb( (@geometry_part_count - 1) * 200, 0, 0 )'))
        self.layer.setRenderer(renderer)

        # Setup rendering check
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometry_part_count')
        result = renderchecker.runTest('part_geometry_part_count')

        self.assertTrue(result)
    def testSymbolColor(self):
        # Create rulebased style
        sym1 = QgsFillSymbol.createSimple({'color': '#ff0000', 'outline_color': 'black'})

        renderer = QgsSingleSymbolRenderer(sym1)
        renderer.symbols(QgsRenderContext())[0].symbolLayers()[0].setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression('set_color_part( @symbol_color, \'value\', "Value" * 4)'))
        self.layer.setRenderer(renderer)

        # Setup rendering check
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_symbol_color_variable')
        result = renderchecker.runTest('symbol_color_variable', 50)

        self.assertTrue(result)
    def testPartNum(self):
        # Create rulebased style
        sym1 = QgsFillSymbolV2.createSimple({'color': '#fdbf6f'})

        renderer = QgsSingleSymbolRendererV2(sym1)
        renderer.symbols()[0].symbolLayers()[0].setDataDefinedProperty('color', 'color_rgb( (@geometry_part_num - 1) * 200, 0, 0 )')
        self.layer.setRendererV2(renderer)

        # Setup rendering check
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometry_part_num')
        result = renderchecker.runTest('part_geometry_part_num')

        self.assertTrue(result)
    def test_buffer_points(self):
        sym = self.points_layer.renderer().symbol()

        buffer_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'buffer($geometry, "staff"/15)', 'outline_color': 'black'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        self.assertIsNotNone(buffer_layer.subSymbol())
        sym.appendSymbolLayer(buffer_layer)

        rendered_layers = [self.points_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_buffer_points')
        self.assertTrue(renderchecker.runTest('geometrygenerator_buffer_points'))
Exemplo n.º 31
0
    def testRenderPointSize(self):
        layer = QgsPointCloudLayer(
            unitTestDataPath() + '/point_clouds/ept/rgb/ept.json', 'test',
            'ept')
        self.assertTrue(layer.isValid())

        layer.renderer().setPointSize(0.05)
        layer.renderer().setPointSizeUnit(QgsUnitTypes.RenderMapUnits)

        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(400, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setDestinationCrs(layer.crs())
        mapsettings.setExtent(
            QgsRectangle(497753.5, 7050887.5, 497754.6, 7050888.6))
        mapsettings.setLayers([layer])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('pointcloudrenderer')
        renderchecker.setControlName('expected_pointsize')
        result = renderchecker.runTest('expected_pointsize')
        TestQgsPointCloudRgbRenderer.report += renderchecker.report()
        self.assertTrue(result)
Exemplo n.º 32
0
    def testVectorBlending(self):
        """Test that blend modes work for vector layers."""

        # Add vector layers to map
        myLayers = [self.mLineLayer, self.mPolygonLayer]
        self.mapSettings.setLayers(myLayers)
        self.mapSettings.setExtent(self.extent)

        # Set blending modes for both layers
        self.mLineLayer.setBlendMode(QPainter.CompositionMode_Difference)
        self.mPolygonLayer.setBlendMode(QPainter.CompositionMode_Difference)

        checker = QgsMultiRenderChecker()
        checker.setControlName("expected_vector_blendmodes")
        checker.setMapSettings(self.mapSettings)
        checker.setColorTolerance(1)

        myResult = checker.runTest("vector_blendmodes", 20)
        myMessage = ('vector blending failed')
        assert myResult, myMessage

        # Reset layers
        self.mLineLayer.setBlendMode(QPainter.CompositionMode_SourceOver)
        self.mPolygonLayer.setBlendMode(QPainter.CompositionMode_SourceOver)
    def test_multi_poly_opacity(self):
        # test that multi-type features are only rendered once

        multipoly = QgsVectorLayer(os.path.join(TEST_DATA_DIR, 'multipatch.shp'), 'Polygons', 'ogr')

        sym = QgsFillSymbol.createSimple({'color': '#77fdbf6f', 'outline_color': 'black'})

        buffer_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'buffer($geometry, -0.01)', 'outline_color': 'black'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        buffer_layer.setSubSymbol(sym)
        geom_symbol = QgsFillSymbol()
        geom_symbol.changeSymbolLayer(0, buffer_layer)
        multipoly.renderer().setSymbol(geom_symbol)

        mapsettings = QgsMapSettings(self.mapsettings)
        mapsettings.setExtent(multipoly.extent())
        mapsettings.setLayers([multipoly])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_opacity')
        res = renderchecker.runTest('geometrygenerator_opacity')
        self.report += renderchecker.report()
        self.assertTrue(res)
    def testRenderCrsTransform(self):
        layer = QgsPointCloudLayer(unitTestDataPath() + '/point_clouds/ept/sunshine-coast/ept.json', 'test', 'ept')
        self.assertTrue(layer.isValid())

        categories = QgsPointCloudRendererRegistry.classificationAttributeCategories(layer)
        renderer = QgsPointCloudClassifiedRenderer('Classification', categories)
        layer.setRenderer(renderer)

        layer.renderer().setPointSize(2)
        layer.renderer().setPointSizeUnit(QgsUnitTypes.RenderMillimeters)

        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(400, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
        mapsettings.setExtent(QgsRectangle(152.980508492, -26.662023491, 152.980586020, -26.662071137))
        mapsettings.setLayers([layer])
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('pointcloudrenderer')
        renderchecker.setControlName('expected_classified_render_crs_transform')
        result = renderchecker.runTest('expected_classified_render_crs_transform')
        TestQgsPointCloudClassifiedRenderer.report += renderchecker.report()
        self.assertTrue(result)
Exemplo n.º 35
0
 def testElse(self):
     # Setup rendering check
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(self.mapsettings)
     renderchecker.setControlName('expected_rulebased_else')
     self.assertTrue(renderchecker.runTest('rulebased_else'))
Exemplo n.º 36
0
    def testRenderMultipleRenderersAboveAndBelow(self):
        poly_layer = QgsVectorLayer(os.path.join(TEST_DATA_DIR, 'polys.shp'))
        self.assertTrue(poly_layer.isValid())

        sym1 = QgsFillSymbol.createSimple({
            'color': '#ffaaff',
            'outline_color': '#000000',
            'outline_width': '1'
        })
        renderer = QgsSingleSymbolRenderer(sym1)
        poly_layer.setRenderer(renderer)

        # add secondary renderer, for rendering below
        class Gen1(QgsFeatureRendererGenerator):
            def id(self):
                return 'Gen1'

            def level(self):
                return 3

            def createRenderer(self):
                renderer = QgsCategorizedSymbolRenderer()
                renderer.setClassAttribute('Name')

                cf1 = QgsCentroidFillSymbolLayer()
                cf1.setSubSymbol(
                    QgsMarkerSymbol.createSimple({
                        'color': '#33aa33',
                        'outline_style': 'no',
                        'size': '5'
                    }))
                sym1 = QgsFillSymbol([cf1])

                cf2 = QgsCentroidFillSymbolLayer()
                cf2.setSubSymbol(
                    QgsMarkerSymbol.createSimple({
                        'color': '#aa33aa',
                        'outline_style': 'no',
                        'size': '5'
                    }))
                sym2 = QgsFillSymbol([cf2])

                renderer.addCategory(QgsRendererCategory('Dam', sym1, 'Dam'))
                renderer.addCategory(QgsRendererCategory('Lake', sym2, 'Lake'))
                return renderer

        # add secondary renderer, for rendering below
        class Gen2(QgsFeatureRendererGenerator):
            def id(self):
                return 'Gen2'

            def level(self):
                return 2

            def createRenderer(self):
                renderer = QgsCategorizedSymbolRenderer()
                renderer.setClassAttribute('Value < 12')

                cf1 = QgsCentroidFillSymbolLayer()
                cf1.setSubSymbol(
                    QgsMarkerSymbol.createSimple({
                        'color': '#aa1111',
                        'outline_style': 'no',
                        'size': '8'
                    }))
                sym1 = QgsFillSymbol([cf1])

                cf2 = QgsCentroidFillSymbolLayer()
                cf2.setSubSymbol(
                    QgsMarkerSymbol.createSimple({
                        'color': '#1111dd',
                        'outline_style': 'no',
                        'size': '8'
                    }))
                sym2 = QgsFillSymbol([cf2])

                renderer.addCategory(QgsRendererCategory('1', sym1, '1'))
                renderer.addCategory(QgsRendererCategory('0', sym2, '0'))
                return renderer

        # add secondary renderer, for rendering below

        class Gen1b(QgsFeatureRendererGenerator):
            def id(self):
                return 'Gen1b'

            def level(self):
                return -2

            def createRenderer(self):
                renderer = QgsCategorizedSymbolRenderer()
                renderer.setClassAttribute('Name')

                sym1 = QgsFillSymbol.createSimple({
                    'color': '#ffaaff',
                    'outline_color': '#33aa33',
                    'outline_width': '3'
                })
                sym2 = QgsFillSymbol.createSimple({
                    'color': '#ffaaff',
                    'outline_color': '#aa33aa',
                    'outline_width': '3'
                })

                renderer.addCategory(QgsRendererCategory('Dam', sym1, 'Dam'))
                renderer.addCategory(QgsRendererCategory('Lake', sym2, 'Lake'))
                return renderer

        # add secondary renderer, for rendering below
        class Gen2b(QgsFeatureRendererGenerator):
            def id(self):
                return 'Gen2b'

            def level(self):
                return -3

            def createRenderer(self):
                renderer = QgsCategorizedSymbolRenderer()
                renderer.setClassAttribute('Value < 12')

                sym1 = QgsFillSymbol.createSimple({
                    'color': '#ffaaff',
                    'outline_color': '#aa1111',
                    'outline_width': '5'
                })
                sym2 = QgsFillSymbol.createSimple({
                    'color': '#ffaaff',
                    'outline_color': '#1111dd',
                    'outline_width': '5'
                })

                renderer.addCategory(QgsRendererCategory('1', sym1, '1'))
                renderer.addCategory(QgsRendererCategory('0', sym2, '0'))
                return renderer

        poly_layer.addFeatureRendererGenerator(Gen1())
        poly_layer.addFeatureRendererGenerator(Gen2())
        poly_layer.addFeatureRendererGenerator(Gen1b())
        poly_layer.addFeatureRendererGenerator(Gen2b())

        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(400, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setDestinationCrs(
            QgsCoordinateReferenceSystem('EPSG:3857'))
        mapsettings.setExtent(
            QgsRectangle(-13875783.2, 2266009.4, -8690110.7, 6673344.5))
        mapsettings.setLayers([poly_layer])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('vectorlayerrenderer')
        renderchecker.setControlName(
            'expected_multiple_renderers_both_above_below')
        result = renderchecker.runTest(
            'expected_multiple_renderers_both_above_below')
        self.report += renderchecker.report()
        self.assertTrue(result)

        # also try with symbol levels
        renderer.setUsingSymbolLevels(True)
        poly_layer.setRenderer(renderer)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('vectorlayerrenderer')
        renderchecker.setControlName(
            'expected_multiple_renderers_both_above_below')
        result = renderchecker.runTest(
            'expected_multiple_renderers_both_above_below')
        self.report += renderchecker.report()
        self.assertTrue(result)
Exemplo n.º 37
0
    def testIntersectionRuleBased(self):
        """
        Test that rule based renderer using intersection clip paths correctly uses original feature area for rule
        evaluation, not clipped area
        """
        poly_layer = QgsVectorLayer(os.path.join(TEST_DATA_DIR, 'polys.shp'))
        self.assertTrue(poly_layer.isValid())

        sym1 = QgsFillSymbol.createSimple({
            'color': '#ff00ff',
            'outline_color': '#000000',
            'outline_width': '1'
        })
        sym2 = QgsFillSymbol.createSimple({
            'color': '#00ffff',
            'outline_color': '#000000',
            'outline_width': '1'
        })

        r1 = QgsRuleBasedRenderer.Rule(sym1, 0, 0, 'area($geometry)>25')
        r2 = QgsRuleBasedRenderer.Rule(sym2, 0, 0, 'ELSE')

        rootrule = QgsRuleBasedRenderer.Rule(None)
        rootrule.appendChild(r1)
        rootrule.appendChild(r2)
        renderer = QgsRuleBasedRenderer(rootrule)
        poly_layer.setRenderer(renderer)

        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(400, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setDestinationCrs(
            QgsCoordinateReferenceSystem('EPSG:3857'))
        mapsettings.setExtent(
            QgsRectangle(-13875783.2, 2266009.4, -8690110.7, 6673344.5))
        mapsettings.setLayers([poly_layer])
        mapsettings.setEllipsoid('')

        region = QgsMapClippingRegion(
            QgsGeometry.fromWkt(
                'Polygon ((-11725957 5368254, -12222900 4807501, -12246014 3834025, -12014878 3496059, -11259833 3518307, -10751333 3621153, -10574129 4516741, -10847640 5194995, -11105742 5325957, -11725957 5368254))'
            ))
        region.setFeatureClip(
            QgsMapClippingRegion.FeatureClippingType.ClipToIntersection)
        region2 = QgsMapClippingRegion(
            QgsGeometry.fromWkt(
                'Polygon ((-11032549 5421399, -11533344 4693167, -11086481 4229112, -11167378 3742984, -10616504 3553984, -10161936 3925771, -9618766 4668482, -9472380 5620753, -10115709 5965063, -11032549 5421399))'
            ))
        region2.setFeatureClip(
            QgsMapClippingRegion.FeatureClippingType.ClipToIntersection)
        mapsettings.addClippingRegion(region)
        mapsettings.addClippingRegion(region2)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('vectorlayerrenderer')
        renderchecker.setControlName('expected_intersection_rule_based')
        result = renderchecker.runTest('expected_intersection_rule_based')
        self.report += renderchecker.report()
        self.assertTrue(result)

        # also try with symbol levels
        renderer.setUsingSymbolLevels(True)
        poly_layer.setRenderer(renderer)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('vectorlayerrenderer')
        renderchecker.setControlName('expected_intersection_rule_based')
        result = renderchecker.runTest('expected_intersection_rule_based')
        self.report += renderchecker.report()
        self.assertTrue(result)
Exemplo n.º 38
0
    def testRenderMultipleRenderersSelection(self):
        """
        Test that selection colors only apply to main renderer
        :return:
        """
        poly_layer = QgsVectorLayer(os.path.join(TEST_DATA_DIR, 'polys.shp'))
        self.assertTrue(poly_layer.isValid())
        poly_layer.selectAll()

        sym1 = QgsFillSymbol.createSimple({
            'color': '#ffaaff',
            'outline_color': '#000000',
            'outline_style': 'no'
        })
        renderer = QgsSingleSymbolRenderer(sym1)
        poly_layer.setRenderer(renderer)

        # add secondary renderer, for rendering below
        class Gen1(QgsFeatureRendererGenerator):
            def id(self):
                return 'Gen1'

            def level(self):
                return -2

            def createRenderer(self):
                renderer = QgsCategorizedSymbolRenderer()
                renderer.setClassAttribute('Name')

                sym1 = QgsFillSymbol.createSimple({
                    'color': '#ffaaff',
                    'outline_color': '#33aa33',
                    'outline_width': '3'
                })
                sym2 = QgsFillSymbol.createSimple({
                    'color': '#ffaaff',
                    'outline_color': '#aa33aa',
                    'outline_width': '3'
                })

                renderer.addCategory(QgsRendererCategory('Dam', sym1, 'Dam'))
                renderer.addCategory(QgsRendererCategory('Lake', sym2, 'Lake'))
                return renderer

        poly_layer.addFeatureRendererGenerator(Gen1())

        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(400, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setDestinationCrs(
            QgsCoordinateReferenceSystem('EPSG:3857'))
        mapsettings.setExtent(
            QgsRectangle(-13875783.2, 2266009.4, -8690110.7, 6673344.5))
        mapsettings.setLayers([poly_layer])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('vectorlayerrenderer')
        renderchecker.setControlName('expected_multiple_renderers_selection')
        result = renderchecker.runTest('expected_multiple_renderers_selection')
        self.report += renderchecker.report()
        self.assertTrue(result)

        # also try with symbol levels
        renderer.setUsingSymbolLevels(True)
        poly_layer.setRenderer(renderer)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('vectorlayerrenderer')
        renderchecker.setControlName('expected_multiple_renderers_selection')
        result = renderchecker.runTest('expected_multiple_renderers_selection')
        self.report += renderchecker.report()
        self.assertTrue(result)