def testRenderOrderedBottomToTop(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(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_classified_bottom_to_top') result = renderchecker.runTest('expected_classified_bottom_to_top') TestQgsPointCloudClassifiedRenderer.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()) renderer = QgsPointCloudClassifiedRenderer() renderer.setAttribute('Classification') 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)
def testUsedAttributes(self): renderer = QgsPointCloudClassifiedRenderer() renderer.setAttribute('attr') rc = QgsRenderContext() prc = QgsPointCloudRenderContext(rc, QgsVector3D(), QgsVector3D()) self.assertEqual(renderer.usedAttributes(prc), {'attr'})
def testBasic(self): renderer = QgsPointCloudClassifiedRenderer() renderer.setAttribute('attr') self.assertEqual(renderer.attribute(), 'attr') renderer.setCategories([ QgsPointCloudCategory(3, QColor(255, 0, 0), 'cat 3'), QgsPointCloudCategory(7, QColor(0, 255, 0), 'cat 7') ]) self.assertEqual(len(renderer.categories()), 2) self.assertEqual(renderer.categories()[0].label(), 'cat 3') self.assertEqual(renderer.categories()[1].label(), 'cat 7') 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(len(rr.categories()), 2) self.assertEqual(rr.categories()[0].label(), 'cat 3') self.assertEqual(rr.categories()[1].label(), 'cat 7') doc = QDomDocument("testdoc") elem = renderer.save(doc, QgsReadWriteContext()) r2 = QgsPointCloudClassifiedRenderer.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(len(r2.categories()), 2) self.assertEqual(r2.categories()[0].label(), 'cat 3') self.assertEqual(r2.categories()[1].label(), 'cat 7')
def testLegend(self): renderer = QgsPointCloudClassifiedRenderer() renderer.setAttribute('Classification') renderer.setCategories([QgsPointCloudCategory(3, QColor(255, 0, 0), 'cat 3'), QgsPointCloudCategory(7, QColor(0, 255, 0), 'cat 7')]) 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), 2) self.assertEqual(nodes[0].data(Qt.DisplayRole), 'cat 3') self.assertEqual(nodes[0].data(QgsLayerTreeModelLegendNode.RuleKeyRole), '3') self.assertEqual(nodes[1].data(Qt.DisplayRole), 'cat 7') self.assertEqual(nodes[1].data(QgsLayerTreeModelLegendNode.RuleKeyRole), '7')