示例#1
0
    def testBasic(self):
        renderer = QgsPointCloudAttributeByRampRenderer()
        renderer.setAttribute('attr')
        self.assertEqual(renderer.attribute(), 'attr')
        renderer.setMinimum(5)
        self.assertEqual(renderer.minimum(), 5)
        renderer.setMaximum(15)
        self.assertEqual(renderer.maximum(), 15)
        ramp = QgsStyle.defaultStyle().colorRamp("Viridis")
        shader = QgsColorRampShader(20, 30, ramp)
        renderer.setColorRampShader(shader)
        self.assertEqual(renderer.colorRampShader().minimumValue(), 20)
        self.assertEqual(renderer.colorRampShader().maximumValue(), 30)

        renderer.setMaximumScreenError(18)
        renderer.setMaximumScreenErrorUnit(QgsUnitTypes.RenderInches)
        renderer.setPointSize(13)
        renderer.setPointSizeUnit(QgsUnitTypes.RenderPoints)
        renderer.setPointSizeMapUnitScale(QgsMapUnitScale(1000, 2000))

        rr = renderer.clone()
        self.assertEqual(rr.maximumScreenError(), 18)
        self.assertEqual(rr.maximumScreenErrorUnit(),
                         QgsUnitTypes.RenderInches)
        self.assertEqual(rr.pointSize(), 13)
        self.assertEqual(rr.pointSizeUnit(), QgsUnitTypes.RenderPoints)
        self.assertEqual(rr.pointSizeMapUnitScale().minScale, 1000)
        self.assertEqual(rr.pointSizeMapUnitScale().maxScale, 2000)

        self.assertEqual(rr.attribute(), 'attr')
        self.assertEqual(rr.minimum(), 5)
        self.assertEqual(rr.maximum(), 15)
        self.assertEqual(rr.colorRampShader().minimumValue(), 20)
        self.assertEqual(rr.colorRampShader().maximumValue(), 30)
        self.assertEqual(rr.colorRampShader().sourceColorRamp().color1(),
                         renderer.colorRampShader().sourceColorRamp().color1())
        self.assertEqual(rr.colorRampShader().sourceColorRamp().color2(),
                         renderer.colorRampShader().sourceColorRamp().color2())

        doc = QDomDocument("testdoc")
        elem = renderer.save(doc, QgsReadWriteContext())

        r2 = QgsPointCloudAttributeByRampRenderer.create(
            elem, QgsReadWriteContext())
        self.assertEqual(r2.maximumScreenError(), 18)
        self.assertEqual(r2.maximumScreenErrorUnit(),
                         QgsUnitTypes.RenderInches)
        self.assertEqual(r2.pointSize(), 13)
        self.assertEqual(r2.pointSizeUnit(), QgsUnitTypes.RenderPoints)
        self.assertEqual(r2.pointSizeMapUnitScale().minScale, 1000)
        self.assertEqual(r2.pointSizeMapUnitScale().maxScale, 2000)
        self.assertEqual(r2.attribute(), 'attr')
        self.assertEqual(r2.minimum(), 5)
        self.assertEqual(r2.maximum(), 15)
        self.assertEqual(r2.colorRampShader().minimumValue(), 20)
        self.assertEqual(r2.colorRampShader().maximumValue(), 30)
        self.assertEqual(r2.colorRampShader().sourceColorRamp().color1(),
                         renderer.colorRampShader().sourceColorRamp().color1())
        self.assertEqual(r2.colorRampShader().sourceColorRamp().color2(),
                         renderer.colorRampShader().sourceColorRamp().color2())
示例#2
0
    def testLegend(self):
        renderer = QgsPointCloudAttributeByRampRenderer()
        renderer.setAttribute('Intensity')
        renderer.setMinimum(200)
        renderer.setMaximum(800)
        ramp = QgsStyle.defaultStyle().colorRamp("Viridis")
        shader = QgsColorRampShader(200, 800, ramp.clone())
        shader.setClassificationMode(QgsColorRampShader.EqualInterval)
        shader.classifyColorRamp(classes=4)
        renderer.setColorRampShader(shader)

        layer = QgsPointCloudLayer(
            unitTestDataPath() + '/point_clouds/ept/sunshine-coast/ept.json',
            'test', 'ept')
        layer_tree_layer = QgsLayerTreeLayer(layer)
        nodes = renderer.createLegendNodes(layer_tree_layer)
        self.assertEqual(len(nodes), 4)
        self.assertEqual(nodes[0].data(Qt.DisplayRole), '200')
        self.assertEqual(nodes[1].data(Qt.DisplayRole), '400')
        self.assertEqual(nodes[2].data(Qt.DisplayRole), '600')
        self.assertEqual(nodes[3].data(Qt.DisplayRole), '800')

        shader = QgsColorRampShader(200, 600, ramp.clone())
        shader.setClassificationMode(QgsColorRampShader.EqualInterval)
        shader.classifyColorRamp(classes=2)
        renderer.setColorRampShader(shader)
        nodes = renderer.createLegendNodes(layer_tree_layer)
        self.assertEqual(len(nodes), 2)
        self.assertEqual(nodes[0].data(Qt.DisplayRole), '200')
        self.assertEqual(nodes[1].data(Qt.DisplayRole), '600')
示例#3
0
    def testRenderZRange(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(layer.crs())
        mapsettings.setExtent(QgsRectangle(498061, 7050991, 498069, 7050999))
        mapsettings.setLayers([layer])
        mapsettings.setZRange(QgsDoubleRange(74.7, 75))

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlPathPrefix('pointcloudrenderer')
        renderchecker.setControlName('expected_ramp_zfilter')
        result = renderchecker.runTest('expected_ramp_zfilter')
        TestQgsPointCloudAttributeByRampRenderer.report += renderchecker.report(
        )
        self.assertTrue(result)
示例#4
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)