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
 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 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 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
 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)
Exemple #7
0
 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 testClusterConcentricLabelsDifferentSizesFarther(self):
     layer, renderer, mapsettings = self._setUp()
     renderer.setEmbeddedRenderer(self._create_categorized_renderer())
     layer.renderer().setTolerance(10)
     layer.renderer().setLabelAttributeName('Class')
     layer.renderer().setLabelDistanceFactor(1)
     f = QgsFontUtils.getStandardTestFont('Bold', 14)
     layer.renderer().setLabelFont(f)
     layer.renderer().setPlacement(QgsPointDisplacementRenderer.ConcentricRings)
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(mapsettings)
     renderchecker.setControlPathPrefix('displacement_renderer')
     renderchecker.setControlName('expected_displacement_cluster_concentric_labels_diff_size_farther')
     res = renderchecker.runTest('expected_displacement_cluster_concentric_labels_diff_size_farther')
     self.report += renderchecker.report()
     self.assertTrue(res)
     self._tearDown(layer)
 def testClusterConcentricLabelsDifferentSizesFarther(self):
     layer, renderer, mapsettings = self._setUp()
     renderer.setEmbeddedRenderer(self._create_categorized_renderer())
     layer.renderer().setTolerance(10)
     layer.renderer().setLabelAttributeName('Class')
     layer.renderer().setLabelDistanceFactor(1)
     f = QgsFontUtils.getStandardTestFont('Bold', 14)
     layer.renderer().setLabelFont(f)
     layer.renderer().setPlacement(QgsPointDisplacementRenderer.ConcentricRings)
     renderchecker = QgsMultiRenderChecker()
     renderchecker.setMapSettings(mapsettings)
     renderchecker.setControlPathPrefix('displacement_renderer')
     renderchecker.setControlName('expected_displacement_cluster_concentric_labels_diff_size_farther')
     res = renderchecker.runTest('expected_displacement_cluster_concentric_labels_diff_size_farther')
     self.report += renderchecker.report()
     self.assertTrue(res)
     self._tearDown(layer)
    def testRenderWithContrast(self):
        layer = QgsPointCloudLayer(
            unitTestDataPath() + '/point_clouds/ept/rgb/ept.json', 'test',
            'ept')
        self.assertTrue(layer.isValid())

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

        redce = QgsContrastEnhancement()
        redce.setMinimumValue(100)
        redce.setMaximumValue(120)
        redce.setContrastEnhancementAlgorithm(
            QgsContrastEnhancement.StretchToMinimumMaximum)
        layer.renderer().setRedContrastEnhancement(redce)

        greence = QgsContrastEnhancement()
        greence.setMinimumValue(130)
        greence.setMaximumValue(150)
        greence.setContrastEnhancementAlgorithm(
            QgsContrastEnhancement.StretchToMinimumMaximum)
        layer.renderer().setGreenContrastEnhancement(greence)

        bluece = QgsContrastEnhancement()
        bluece.setMinimumValue(170)
        bluece.setMaximumValue(190)
        bluece.setContrastEnhancementAlgorithm(
            QgsContrastEnhancement.StretchToMinimumMaximum)
        layer.renderer().setBlueContrastEnhancement(bluece)

        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_rgb_contrast')
        result = renderchecker.runTest('expected_rgb_contrast')
        TestQgsPointCloudRgbRenderer.report += renderchecker.report()
        self.assertTrue(result)
    def testDataDefinedOpacity(self):
        poly_shp = os.path.join(TEST_DATA_DIR, 'polys.shp')
        poly_layer = QgsVectorLayer(poly_shp, 'Polys', 'ogr')
        self.assertTrue(poly_layer.isValid())
        s = QgsFillSymbol()
        s.deleteSymbolLayer(0)

        random_fill = QgsRandomMarkerFillSymbolLayer(1, seed=481523)
        marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Circle,
                                            6)
        marker.setColor(QColor(255, 0, 0))
        marker.setStrokeWidth(1)
        marker.setDataDefinedProperty(
            QgsSymbolLayer.PropertyFillColor,
            QgsProperty.fromExpression("if(Name='Dam', 'red', 'green')"))
        marker.setDataDefinedProperty(
            QgsSymbolLayer.PropertyStrokeColor,
            QgsProperty.fromExpression("if(Name='Dam', 'magenta', 'blue')"))
        marker_symbol = QgsMarkerSymbol()
        marker_symbol.changeSymbolLayer(0, marker)
        marker_symbol.setOpacity(0.5)
        random_fill.setSubSymbol(marker_symbol)

        s.appendSymbolLayer(random_fill.clone())

        s.setDataDefinedProperty(
            QgsSymbol.PropertyOpacity,
            QgsProperty.fromExpression("if(\"Value\" >10, 25, 50)"))

        poly_layer.setRenderer(QgsSingleSymbolRenderer(s))

        ms = QgsMapSettings()
        ms.setOutputSize(QSize(400, 400))
        ms.setOutputDpi(96)
        ms.setExtent(QgsRectangle(-118.5, 19.0, -81.4, 50.4))
        ms.setLayers([poly_layer])

        # Test rendering
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(ms)
        renderchecker.setControlPathPrefix('symbol_randommarkerfill')
        renderchecker.setControlName('expected_randommarker_ddopacity')
        res = renderchecker.runTest('expected_randommarker_ddopacity')
        self.report += renderchecker.report()
        self.assertTrue(res)
    def test_units_millimeters(self):
        sym = self.points_layer.renderer().symbol()

        buffer_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'buffer($geometry, "staff")', 'outline_color': 'black'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        buffer_layer.setUnits(QgsUnitTypes.RenderMillimeters)
        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_millimeters')
        res = renderchecker.runTest('geometrygenerator_millimeters')
        self.report += renderchecker.report()
        self.assertTrue(res)
    def testOpacityWithDataDefinedColor(self):
        line_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
        line_layer = QgsVectorLayer(line_shp, 'Lines', 'ogr')
        self.assertTrue(line_layer.isValid())

        s = QgsLineSymbol()
        s.deleteSymbolLayer(0)
        marker_line = QgsMarkerLineSymbolLayer(True)
        marker_line.setPlacement(QgsTemplatedLineSymbolLayerBase.CentralPoint)
        simple_marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Circle, 10)
        simple_marker.setColor(QColor(0, 255, 0))
        simple_marker.setStrokeColor(QColor(255, 0, 0))
        simple_marker.setStrokeWidth(1)
        simple_marker.setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression(
            "if(Name='Arterial', 'red', 'green')"))
        simple_marker.setDataDefinedProperty(QgsSymbolLayer.PropertyStrokeColor, QgsProperty.fromExpression(
            "if(Name='Arterial', 'magenta', 'blue')"))

        marker_symbol = QgsMarkerSymbol()
        marker_symbol.changeSymbolLayer(0, simple_marker)
        marker_symbol.setOpacity(0.5)
        marker_line.setSubSymbol(marker_symbol)
        s.appendSymbolLayer(marker_line.clone())

        # set opacity on both the symbol and subsymbol, to test that they get combined
        s.setOpacity(0.5)

        line_layer.setRenderer(QgsSingleSymbolRenderer(s))

        ms = QgsMapSettings()
        ms.setOutputSize(QSize(400, 400))
        ms.setOutputDpi(96)
        ms.setExtent(QgsRectangle(-118.5, 19.0, -81.4, 50.4))
        ms.setLayers([line_layer])

        # Test rendering
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(ms)
        renderchecker.setControlPathPrefix('symbol_markerline')
        renderchecker.setControlName('expected_markerline_opacityddcolor')
        res = renderchecker.runTest('expected_markerline_opacityddcolor')
        self.report += renderchecker.report()
        self.assertTrue(res)
    def test_subsymbol(self):
        """
        Test rendering a generator in a subsymbol of another symbol
        """
        sym = QgsLineSymbol()
        arrow = QgsArrowSymbolLayer()
        arrow.setIsRepeated(False)
        arrow.setArrowStartWidth(10)
        arrow.setArrowWidth(5)
        arrow.setHeadLength(20)
        arrow.setHeadThickness(10)

        sym.changeSymbolLayer(0, arrow)

        self.lines_layer.renderer().setSymbol(sym)

        # here "$geometry" must refer to the created ARROW shape, NOT the original feature line geometry!
        generator_layer = QgsGeometryGeneratorSymbolLayer.create(
            {'geometryModifier': 'buffer($geometry, 3)'})
        generator_layer.setSymbolType(QgsSymbol.Fill)
        generator_layer.setUnits(QgsUnitTypes.RenderMillimeters)
        self.assertIsNotNone(generator_layer.subSymbol())

        generator_layer.subSymbol().symbolLayer(0).setColor(
            QColor(255, 255, 255))
        generator_layer.subSymbol().symbolLayer(0).setStrokeColor(
            QColor(0, 0, 0))
        generator_layer.subSymbol().symbolLayer(0).setStrokeWidth(2)

        sub_symbol = QgsFillSymbol()
        sub_symbol.changeSymbolLayer(0, generator_layer)
        arrow.setSubSymbol(sub_symbol)

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

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_subsymbol')
        res = renderchecker.runTest('geometrygenerator_subsymbol')
        self.report += renderchecker.report()
        self.assertTrue(res)
Exemple #15
0
 def canvasImageCheck(self,
                      name,
                      reference_image,
                      canvas,
                      expect_fail=False):
     self.report += "<h2>Render {}</h2>\n".format(name)
     temp_dir = QDir.tempPath() + '/'
     file_name = temp_dir + 'mapcanvas_' + name + ".png"
     print(file_name)
     canvas.saveAsImage(file_name)
     checker = QgsMultiRenderChecker()
     checker.setControlPathPrefix("mapcanvas")
     checker.setControlName("expected_" + reference_image)
     checker.setRenderedImage(file_name)
     checker.setColorTolerance(2)
     checker.setExpectFail(expect_fail)
     result = checker.runTest(name, 20)
     self.report += checker.report()
     print((self.report))
     return result
Exemple #16
0
    def canvasImageCheck(self, name, reference_image, canvas):
        self.report += "<h2>Render {}</h2>\n".format(name)
        temp_dir = QDir.tempPath() + '/'
        file_name = temp_dir + 'rendered_' + name + ".png"

        image = QImage(canvas.size(), QImage.Format_ARGB32)
        painter = QPainter(image)
        canvas.render(painter)
        painter.end()
        image.save(file_name)

        checker = QgsMultiRenderChecker()
        checker.setControlPathPrefix("highlight")
        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
Exemple #17
0
    def testRenderCrsTransform(self):
        layer = QgsPointCloudLayer(unitTestDataPath() + '/point_clouds/ept/rgb/ept.json', 'test', 'ept')
        self.assertTrue(layer.isValid())

        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.977434544, -26.663017454, 152.977424882, -26.663009624))
        mapsettings.setLayers([layer])
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('pointcloudrenderer')
        renderchecker.setControlName('expected_rgb_render_crs_transform')
        result = renderchecker.runTest('expected_rgb_render_crs_transform')
        TestQgsPointCloudRgbRenderer.report += renderchecker.report()
        self.assertTrue(result)
    def testRenderVariables(self):
        """ test rendering with expression variables in marker """
        layer, renderer, mapsettings = self._setUp()
        layer.renderer().setTolerance(10)

        old_marker = layer.renderer().centerSymbol().clone()

        new_marker = QgsMarkerSymbol.createSimple({'color': '#ffff00', 'size': '3', 'outline_style': 'no'})
        new_marker.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression('@cluster_color'))
        new_marker.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertySize, QgsProperty.fromExpression('@cluster_size*2'))
        layer.renderer().setCenterSymbol(new_marker)
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('displacement_renderer')
        renderchecker.setControlName('expected_displacement_variables')
        result = renderchecker.runTest('expected_displacement_variables')
        self.report += renderchecker.report()
        layer.renderer().setCenterSymbol(old_marker)
        self.assertTrue(result)
        self._tearDown(layer)
    def testRenderVariables(self):
        """ test rendering with expression variables in marker """
        layer, renderer, mapsettings = self._setUp()
        layer.renderer().setTolerance(10)

        old_marker = layer.renderer().centerSymbol().clone()

        new_marker = QgsMarkerSymbol.createSimple({'color': '#ffff00', 'size': '3', 'outline_style': 'no'})
        new_marker.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression('@cluster_color'))
        new_marker.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertySize, QgsProperty.fromExpression('@cluster_size*2'))
        layer.renderer().setCenterSymbol(new_marker)
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('displacement_renderer')
        renderchecker.setControlName('expected_displacement_variables')
        result = renderchecker.runTest('expected_displacement_variables')
        self.report += renderchecker.report()
        layer.renderer().setCenterSymbol(old_marker)
        self.assertTrue(result)
        self._tearDown(layer)
Exemple #20
0
    def testRenderClipRegion(self):
        layer = QgsPointCloudLayer(
            unitTestDataPath() + '/point_clouds/ept/rgb/ept.json', 'test',
            'ept')
        self.assertTrue(layer.isValid())

        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.977434544, -26.663017454, 152.977424882,
                         -26.663009624))
        mapsettings.setLayers([layer])

        region = QgsMapClippingRegion(
            QgsGeometry.fromWkt(
                'Polygon ((152.97742833685992991 -26.66301088198133584, 152.97742694456141521 -26.66301085776744983, 152.97742676295726483 -26.66301358182974468, 152.97742895431403554 -26.66301349708113833, 152.97742833685992991 -26.66301088198133584))'
            ))
        region.setFeatureClip(
            QgsMapClippingRegion.FeatureClippingType.ClipPainterOnly)
        region2 = QgsMapClippingRegion(
            QgsGeometry.fromWkt(
                'Polygon ((152.97743215054714483 -26.66301111201326535, 152.97742715037946937 -26.66301116044103736, 152.97742754990858316 -26.66301436878107367, 152.97743264693181686 -26.66301491359353193, 152.97743215054714483 -26.66301111201326535))'
            ))
        region2.setFeatureClip(
            QgsMapClippingRegion.FeatureClippingType.ClipToIntersection)
        mapsettings.addClippingRegion(region)
        mapsettings.addClippingRegion(region2)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('pointcloudrenderer')
        renderchecker.setControlName('expected_clip_region')
        result = renderchecker.runTest('expected_clip_region')
        TestQgsPointCloudRgbRenderer.report += renderchecker.report()
        self.assertTrue(result)
Exemple #21
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)
Exemple #22
0
    def _img_diff(self, image, control_image, max_diff, max_size_diff=QSize(), outputJpg=False):

        extFile = 'png'
        if outputJpg:
            extFile = 'jpg'

        temp_image = os.path.join(tempfile.gettempdir(), "%s_result.%s" % (control_image, extFile))

        with open(temp_image, "wb") as f:
            f.write(image)

        if outputJpg:
            return (True, "QgsRenderChecker can't be used for JPG images")

        control = QgsMultiRenderChecker()
        control.setControlPathPrefix("qgis_server")
        control.setControlName(control_image)
        control.setRenderedImage(temp_image)
        if max_size_diff.isValid():
            control.setSizeTolerance(max_size_diff.width(), max_size_diff.height())
        return control.runTest(control_image, max_diff), control.report()
    def testMapInfoMarkerSymbolConversion(self):
        line_layer = QgsVectorLayer(TEST_DATA_DIR + '/mapinfo/marker_styles.TAB', 'Marker', 'ogr')

        renderer = QgsEmbeddedSymbolRenderer(defaultSymbol=QgsMarkerSymbol.createSimple({}))
        line_layer.setRenderer(renderer)

        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(2000, 4000))
        mapsettings.setOutputDpi(96)
        mapsettings.setMagnificationFactor(2)
        mapsettings.setExtent(line_layer.extent().buffered(0.1))

        mapsettings.setLayers([line_layer])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('embedded')
        renderchecker.setControlName('expected_embedded_mapinfo_markers')
        res = renderchecker.runTest('embedded_mapinfo_markers')
        TestQgsEmbeddedSymbolRenderer.report += renderchecker.report()
        self.assertTrue(res)
Exemple #24
0
    def testDataDefinedOffset(self):
        """ test that rendering a fill symbol with data defined offset works"""

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

        # lets render two layers, to make comparison easier
        layer = QgsSimpleFillSymbolLayer()
        layer.setStrokeStyle(Qt.NoPen)
        layer.setColor(QColor(200, 250, 50))

        symbol = QgsFillSymbol()
        symbol.changeSymbolLayer(0, layer)

        layer = QgsSimpleFillSymbolLayer()
        layer.setDataDefinedProperty(
            QgsSymbolLayer.PropertyOffset,
            QgsProperty.fromExpression(
                "array(-(x_min($geometry)+100)/5, (y_min($geometry)-35)/5)"))
        layer.setStrokeStyle(Qt.NoPen)
        layer.setColor(QColor(100, 150, 150))

        symbol.appendSymbolLayer(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])

        # Test rendering
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(ms)
        renderchecker.setControlPathPrefix('symbol_simplefill')
        renderchecker.setControlName('expected_simplefill_ddoffset')
        res = renderchecker.runTest('simplefill_ddoffset')
        TestQgsSimpleFillSymbolLayer.report += renderchecker.report()
        self.assertTrue(res)
    def test_feature_geometry(self):
        """
        The geometry($currentfeature) expression used in a subsymbol should refer to the original FEATURE geometry
        """
        points = QgsVectorLayer('Point?crs=epsg:4326', 'Points', 'memory')
        self.assertTrue(points.isValid())
        f = QgsFeature()
        f.setGeometry(QgsGeometry.fromWkt('Point(1 2)'))
        points.dataProvider().addFeature(f)

        font = QgsFontUtils.getStandardTestFont('Bold')
        font_marker = QgsFontMarkerSymbolLayer(font.family(), 'x', 16)
        font_marker.setDataDefinedProperty(
            QgsSymbolLayer.PropertyCharacter,
            QgsProperty.fromExpression(
                'geom_to_wkt(geometry($currentfeature))'))
        subsymbol = QgsMarkerSymbol()
        subsymbol.changeSymbolLayer(0, font_marker)

        parent_generator = QgsGeometryGeneratorSymbolLayer.create(
            {'geometryModifier': 'translate($geometry, 1, 2)'})
        parent_generator.setSymbolType(QgsSymbol.Marker)

        parent_generator.setSubSymbol(subsymbol)

        geom_symbol = QgsMarkerSymbol()
        geom_symbol.changeSymbolLayer(0, parent_generator)
        points.renderer().setSymbol(geom_symbol)

        mapsettings = QgsMapSettings(self.mapsettings)
        mapsettings.setExtent(QgsRectangle(0, 0, 5, 5))
        mapsettings.setLayers([points])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlName(
            'expected_geometrygenerator_feature_geometry')
        res = renderchecker.runTest('geometrygenerator_feature_geometry')
        self.report += renderchecker.report()
        self.assertTrue(res)
    def testDataDefinedOpacity(self):
        line_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
        line_layer = QgsVectorLayer(line_shp, 'Lines', 'ogr')
        self.assertTrue(line_layer.isValid())

        s = QgsLineSymbol()
        s.deleteSymbolLayer(0)
        hash_line = QgsHashedLineSymbolLayer(True)
        simple_line = QgsSimpleLineSymbolLayer()
        simple_line.setColor(QColor(0, 255, 0))
        simple_line.setDataDefinedProperty(QgsSymbolLayer.PropertyStrokeColor, QgsProperty.fromExpression(
            "if(Name='Arterial', 'red', 'green')"))

        simple_line.setWidth(1)
        line_symbol = QgsLineSymbol()
        line_symbol.changeSymbolLayer(0, simple_line)
        line_symbol.setOpacity(0.5)
        hash_line.setSubSymbol(line_symbol)
        hash_line.setHashLength(10)
        hash_line.setAverageAngleLength(0)
        s.appendSymbolLayer(hash_line.clone())

        s.setDataDefinedProperty(QgsSymbol.PropertyOpacity, QgsProperty.fromExpression("if(\"Value\" = 1, 25, 50)"))

        line_layer.setRenderer(QgsSingleSymbolRenderer(s))

        ms = QgsMapSettings()
        ms.setOutputSize(QSize(400, 400))
        ms.setOutputDpi(96)
        ms.setExtent(QgsRectangle(-118.5, 19.0, -81.4, 50.4))
        ms.setLayers([line_layer])

        # Test rendering
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(ms)
        renderchecker.setControlPathPrefix('symbol_hashline')
        renderchecker.setControlName('expected_hashline_ddopacity')
        res = renderchecker.runTest('expected_hashline_ddopacity')
        self.report += renderchecker.report()
        self.assertTrue(res)
    def test_mixed(self):
        sym = self.polys_layer.renderer().symbol()

        buffer_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'buffer($geometry, "value"/15)', 'outline_color': 'black'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        buffer_layer.subSymbol().symbolLayer(0).setStrokeColor(QColor(0, 0, 0))
        self.assertIsNotNone(buffer_layer.subSymbol())
        sym.appendSymbolLayer(buffer_layer)
        marker_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'centroid($geometry)', 'outline_color': 'black'})
        marker_layer.setSymbolType(QgsSymbol.Marker)
        marker_layer.subSymbol().symbolLayer(0).setStrokeColor(QColor(0, 0, 0))
        sym.appendSymbolLayer(marker_layer)

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

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_mixed')
        res = renderchecker.runTest('geometrygenerator_mixed')
        self.report += renderchecker.report()
        self.assertTrue(res)
Exemple #28
0
    def test_render_paint_effect(self):
        """
        Test rendering layers as a group with paint effect
        """
        vl1 = QgsVectorLayer(TEST_DATA_DIR + '/lines.shp')
        self.assertTrue(vl1.isValid())
        vl2 = QgsVectorLayer(TEST_DATA_DIR + '/points.shp')
        self.assertTrue(vl2.isValid())

        options = QgsGroupLayer.LayerOptions(QgsCoordinateTransformContext())
        group_layer = QgsGroupLayer('group', options)
        group_layer.setChildLayers([vl2, vl1])

        drop_shadow = QgsDropShadowEffect()
        drop_shadow.setBlurLevel(0)
        drop_shadow.setOpacity(1)
        drop_shadow.setColor(QColor(255, 0, 255))
        drop_shadow.setOffsetDistance(3)

        effect_stack = QgsEffectStack()
        effect_stack.appendEffect(drop_shadow)
        effect_stack.appendEffect(QgsDrawSourceEffect())
        group_layer.setPaintEffect(effect_stack)

        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(600, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setDestinationCrs(group_layer.crs())
        mapsettings.setExtent(group_layer.extent())
        mapsettings.setLayers([group_layer])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('group_layer')
        renderchecker.setControlName('expected_group_paint_effect')
        result = renderchecker.runTest('expected_group_paint_effect')
        TestQgsGroupLayer.report += renderchecker.report()
        self.assertTrue(result)
Exemple #29
0
    def testDataDefinedOpacity(self):
        poly_shp = os.path.join(TEST_DATA_DIR, 'polys.shp')
        poly_layer = QgsVectorLayer(poly_shp, 'Polys', 'ogr')
        self.assertTrue(poly_layer.isValid())

        layer = QgsSimpleFillSymbolLayer()
        layer.setStrokeStyle(Qt.NoPen)
        layer.setColor(QColor(200, 250, 50))
        layer.setDataDefinedProperty(
            QgsSymbolLayer.PropertyFillColor,
            QgsProperty.fromExpression("if(Name='Dam', 'red', 'green')"))
        layer.setDataDefinedProperty(
            QgsSymbolLayer.PropertyStrokeColor,
            QgsProperty.fromExpression("if(Name='Dam', 'magenta', 'blue')"))

        symbol = QgsFillSymbol()
        symbol.changeSymbolLayer(0, layer)

        symbol.setDataDefinedProperty(
            QgsSymbol.PropertyOpacity,
            QgsProperty.fromExpression("if(\"Value\" >10, 25, 50)"))

        poly_layer.setRenderer(QgsSingleSymbolRenderer(symbol))

        ms = QgsMapSettings()
        ms.setOutputSize(QSize(400, 400))
        ms.setOutputDpi(96)
        ms.setExtent(QgsRectangle(-118.5, 19.0, -81.4, 50.4))
        ms.setLayers([poly_layer])

        # Test rendering
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(ms)
        renderchecker.setControlPathPrefix('symbol_simplefill')
        renderchecker.setControlName('expected_simplefill_ddopacity')
        res = renderchecker.runTest('expected_simplefill_ddopacity')
        self.report += renderchecker.report()
        self.assertTrue(res)
    def testRender(self):
        layer = QgsPointCloudLayer(
            unitTestDataPath() + '/point_clouds/ept/sunshine-coast/ept.json',
            'test', 'ept')
        self.assertTrue(layer.isValid())

        renderer = QgsPointCloudExtentRenderer()
        layer.setRenderer(renderer)

        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(400, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setDestinationCrs(layer.crs())
        mapsettings.setExtent(QgsRectangle(498061, 7050991, 498069, 7050999))
        mapsettings.setLayers([layer])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('pointcloudrenderer')
        renderchecker.setControlName('expected_extent_render')
        result = renderchecker.runTest('expected_extent_render')
        TestQgsPointCloudExtentRenderer.report += renderchecker.report()
        self.assertTrue(result)
    def testRenderWithPainterClipRegions(self):
        raster_layer = QgsRasterLayer(
            os.path.join(TEST_DATA_DIR, 'rgb256x256.png'))
        self.assertTrue(raster_layer.isValid())
        raster_layer.setCrs(QgsCoordinateReferenceSystem('EPSG:3857'))

        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(400, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setDestinationCrs(
            QgsCoordinateReferenceSystem('EPSG:4326'))
        mapsettings.setExtent(
            QgsRectangle(0.0001451, -0.0001291, 0.0021493, -0.0021306))
        mapsettings.setLayers([raster_layer])

        region = QgsMapClippingRegion(
            QgsGeometry.fromWkt(
                'Polygon ((0.00131242078273144 -0.00059281669806561, 0.00066744230712249 -0.00110186995774045, 0.00065145110524788 -0.00152830200772984, 0.00141369839460392 -0.00189076925022083, 0.00210931567614912 -0.00094195793899443, 0.00169354442740946 -0.00067810310806349, 0.00131242078273144 -0.00059281669806561))'
            ))
        region.setFeatureClip(
            QgsMapClippingRegion.FeatureClippingType.ClipPainterOnly)
        region2 = QgsMapClippingRegion(
            QgsGeometry.fromWkt(
                'Polygon ((0.00067010750743492 -0.0007740503193111, 0.00064612070462302 -0.00151764120648011, 0.00153629760897587 -0.00158693641460339, 0.0014909892036645 -0.00063812510337699, 0.00106722235398754 -0.00055816909400397, 0.00067010750743492 -0.0007740503193111))'
            ))
        region2.setFeatureClip(
            QgsMapClippingRegion.FeatureClippingType.ClipToIntersection)
        mapsettings.addClippingRegion(region)
        mapsettings.addClippingRegion(region2)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('rasterlayerrenderer')
        renderchecker.setControlName('expected_painterclip_region')
        result = renderchecker.runTest('expected_painterclip_region')
        self.report += renderchecker.report()
        self.assertTrue(result)
    def testRenderBottomToTop(self):
        layer = QgsPointCloudLayer(
            unitTestDataPath() + '/point_clouds/ept/sunshine-coast/ept.json',
            'test', 'ept')
        self.assertTrue(layer.isValid())

        renderer = QgsPointCloudAttributeByRampRenderer()
        renderer.setAttribute('Intensity')
        renderer.setMinimum(200)
        renderer.setMaximum(1000)
        ramp = QgsStyle.defaultStyle().colorRamp("Viridis")
        shader = QgsColorRampShader(200, 1000, ramp)
        shader.classifyColorRamp()
        renderer.setColorRampShader(shader)

        layer.setRenderer(renderer)

        layer.renderer().setPointSize(6)
        layer.renderer().setPointSizeUnit(QgsUnitTypes.RenderMillimeters)
        layer.renderer().setDrawOrder2d(
            QgsPointCloudRenderer.DrawOrder.BottomToTop)

        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(400, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setDestinationCrs(layer.crs())
        mapsettings.setExtent(QgsRectangle(498061, 7050991, 498069, 7050999))
        mapsettings.setLayers([layer])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('pointcloudrenderer')
        renderchecker.setControlName('expected_ramp_bottom_to_top')
        result = renderchecker.runTest('expected_ramp_bottom_to_top')
        TestQgsPointCloudAttributeByRampRenderer.report += renderchecker.report(
        )
        self.assertTrue(result)
    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)
Exemple #34
0
    def testRenderCrsTransform(self):
        layer = QgsPointCloudLayer(
            unitTestDataPath() + '/point_clouds/ept/sunshine-coast/ept.json',
            'test', 'ept')
        self.assertTrue(layer.isValid())

        renderer = QgsPointCloudAttributeByRampRenderer()
        renderer.setAttribute('Intensity')
        renderer.setMinimum(200)
        renderer.setMaximum(1000)
        ramp = QgsStyle.defaultStyle().colorRamp("Viridis")
        shader = QgsColorRampShader(200, 1000, ramp)
        shader.classifyColorRamp()
        renderer.setColorRampShader(shader)

        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_ramp_render_crs_transform')
        result = renderchecker.runTest('expected_ramp_render_crs_transform')
        TestQgsPointCloudAttributeByRampRenderer.report += renderchecker.report(
        )
        self.assertTrue(result)
    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)
Exemple #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)
Exemple #37
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)
    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)