Esempio 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)
Esempio n. 2
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)
 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'))
    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 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'))
Esempio n. 6
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)
 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'))
Esempio n. 8
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
Esempio n. 9
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 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)
Esempio n. 11
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 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)
Esempio n. 13
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
 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 testRenderVariables(self):
        """ test rendering with expression variables in marker """
        self.layer.renderer().setTolerance(10)

        old_marker = self.layer.renderer().clusterSymbol().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'))
        self.layer.renderer().setClusterSymbol(new_marker)
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlPathPrefix('cluster_renderer')
        renderchecker.setControlName('expected_cluster_variables')
        result = renderchecker.runTest('expected_cluster_variables')
        self.layer.renderer().setClusterSymbol(old_marker)
        self.assertTrue(result)
Esempio n. 17
0
 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 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)
Esempio n. 19
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)
Esempio n. 20
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)
    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)
Esempio n. 22
0
    def testRenderBlendMode(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)

        layer.setBlendMode(QPainter.CompositionMode_ColorBurn)

        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_blendmode')
        result = renderchecker.runTest('expected_blendmode')
        TestQgsPointCloudRgbRenderer.report += renderchecker.report()
        self.assertTrue(result)
Esempio n. 23
0
    def testRenderVariables(self):
        """ test rendering with expression variables in marker """
        self.layer.renderer().setTolerance(10)

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

        new_marker = QgsMarkerSymbol.createSimple({
            'color': '#ffff00',
            'size': '3',
            'outline_style': 'no'
        })
        new_marker.symbolLayer(0).setDataDefinedProperty(
            'color', QgsDataDefined('@cluster_color'))
        new_marker.symbolLayer(0).setDataDefinedProperty(
            'size', QgsDataDefined('@cluster_size*2'))
        self.layer.renderer().setCenterSymbol(new_marker)
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlPathPrefix('displacement_renderer')
        renderchecker.setControlName('expected_displacement_variables')
        result = renderchecker.runTest('expected_displacement_variables')
        self.layer.renderer().setCenterSymbol(old_marker)
        self.assertTrue(result)
Esempio n. 24
0
    def testRenderFiltered(self):
        layer = QgsPointCloudLayer(
            unitTestDataPath() + '/point_clouds/ept/sunshine-coast/ept.json',
            'test', 'ept')
        self.assertTrue(layer.isValid())

        renderer = QgsPointCloudClassifiedRenderer()
        renderer.setAttribute('Classification')
        layer.setRenderer(renderer)

        layer.renderer().setPointSize(2)
        layer.renderer().setPointSizeUnit(QgsUnitTypes.RenderMillimeters)
        layer.setSubsetString('NumberOfReturns > 1')

        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_classified_render_filtered')
        result = renderchecker.runTest('expected_classified_render_filtered')
        TestQgsPointCloudClassifiedRenderer.report += renderchecker.report()
        self.assertTrue(result)

        layer.setSubsetString('')
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('pointcloudrenderer')
        renderchecker.setControlName('expected_classified_render_unfiltered')
        result = renderchecker.runTest('expected_classified_render_unfiltered')
        TestQgsPointCloudClassifiedRenderer.report += renderchecker.report()
        self.assertTrue(result)
Esempio n. 25
0
    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)
Esempio n. 27
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)
Esempio n. 29
0
    def test_reference_scale(self):
        """
        Test rendering a layer with a reference scale set
        """
        layer = QgsVectorLayer(os.path.join(TEST_DATA_DIR, 'lines.shp'), 'Lines', 'ogr')
        self.assertTrue(layer.isValid())

        sym1 = QgsLineSymbol.createSimple({'line_color': '#4dbf6f', 'line_width': 4, 'line_width_unit': "points"})

        renderer = QgsSingleSymbolRenderer(sym1)
        layer.setRenderer(renderer)

        mapsettings = QgsMapSettings()
        mapsettings.setDestinationCrs(layer.crs())
        mapsettings.setOutputSize(QSize(400, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setExtent(layer.extent())
        mapsettings.setLayers([layer])
        self.assertAlmostEqual(mapsettings.scale(), 22738556, -5)

        # Setup rendering check
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('vectorlayerrenderer')
        renderchecker.setControlName('expected_reference_scale_not_set')
        result = renderchecker.runTest('expected_reference_scale_not_set')
        self.report += renderchecker.report()
        self.assertTrue(result)

        # Set the reference scale as half the map scale -- the lines should be double as wide
        # as their preset width
        renderer.setReferenceScale(22738556 * 2)
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('vectorlayerrenderer')
        renderchecker.setControlName('expected_reference_scale_double')
        result = renderchecker.runTest('expected_reference_scale_double')
        self.report += renderchecker.report()
        self.assertTrue(result)

        # Set the reference scale as double the map scale -- the lines should be half as wide
        # as their preset width
        renderer.setReferenceScale(22738556 / 2)
        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('vectorlayerrenderer')
        renderchecker.setControlName('expected_reference_scale_half')
        result = renderchecker.runTest('expected_reference_scale_half')
        self.report += renderchecker.report()
        self.assertTrue(result)
Esempio n. 30
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)
Esempio n. 31
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)
Esempio n. 32
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)
Esempio n. 33
0
    def testMultiPoint(self):
        """
        Test multipoint handling
        """
        layer = QgsVectorLayer('Multipoint?field=cat:string', '', 'memory')
        self.assertTrue(layer.isValid())

        f = QgsFeature(layer.fields())
        f.setAttributes(['a'])
        f.setGeometry(QgsGeometry.fromWkt('MultiPoint(5 5, 5 6, 9 9)'))
        layer.dataProvider().addFeature(f)
        f.setAttributes(['b'])
        f.setGeometry(QgsGeometry.fromWkt('MultiPoint(2 1, 2 2, 5 5)'))
        layer.dataProvider().addFeature(f)
        f.setAttributes(['c'])
        f.setGeometry(QgsGeometry.fromWkt('MultiPoint(9 1)'))
        layer.dataProvider().addFeature(f)

        renderer = QgsPointDisplacementRenderer()
        sym1 = QgsMarkerSymbol.createSimple({
            'color': '#ff00ff',
            'size': '3',
            'outline_style': 'no'
        })
        sym_renderer = QgsCategorizedSymbolRenderer()
        sym_renderer.setClassAttribute('cat')
        sym1.setColor(QColor(255, 0, 0))
        sym_renderer.addCategory(QgsRendererCategory('a', sym1.clone(), 'a'))
        sym1.setColor(QColor(0, 255, 0))
        sym_renderer.addCategory(QgsRendererCategory('b', sym1.clone(), 'b'))
        sym1.setColor(QColor(0, 0, 255))
        sym_renderer.addCategory(QgsRendererCategory('c', sym1.clone(), 'c'))
        renderer.setEmbeddedRenderer(sym_renderer)

        renderer.setCircleRadiusAddition(2)
        renderer.setCircleWidth(1)
        renderer.setCircleColor(QColor(0, 0, 0))
        renderer.setCenterSymbol(
            QgsMarkerSymbol.createSimple({
                'color': '#ffff00',
                'size': '3',
                'outline_style': 'no'
            }))
        renderer.setToleranceUnit(QgsUnitTypes.RenderMapUnits)
        renderer.setTolerance(2)
        layer.setRenderer(renderer)

        rendered_layers = [layer]
        mapsettings = QgsMapSettings()
        mapsettings.setOutputSize(QSize(400, 400))
        mapsettings.setOutputDpi(96)
        mapsettings.setExtent(QgsRectangle(0, 0, 10, 10))
        mapsettings.setLayers(rendered_layers)

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