def testDashPatternOffset(self): s = QgsLineSymbol.createSimple({ 'outline_color': '#ff0000', 'outline_width': '0.6' }) s.symbolLayer(0).setDashPatternOffset(1.2) s.symbolLayer(0).setDashPatternOffsetUnit(QgsUnitTypes.RenderPoints) s.symbolLayer(0).setDashPatternOffsetMapUnitScale( QgsMapUnitScale(5, 10)) s2 = s.clone() self.assertEqual(s2.symbolLayer(0).dashPatternOffset(), 1.2) self.assertEqual( s2.symbolLayer(0).dashPatternOffsetUnit(), QgsUnitTypes.RenderPoints) self.assertEqual( s2.symbolLayer(0).dashPatternOffsetMapUnitScale().minScale, 5) self.assertEqual( s2.symbolLayer(0).dashPatternOffsetMapUnitScale().maxScale, 10) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertEqual(s2.symbolLayer(0).dashPatternOffset(), 1.2) self.assertEqual( s2.symbolLayer(0).dashPatternOffsetUnit(), QgsUnitTypes.RenderPoints) self.assertEqual( s2.symbolLayer(0).dashPatternOffsetMapUnitScale().minScale, 5) self.assertEqual( s2.symbolLayer(0).dashPatternOffsetMapUnitScale().maxScale, 10)
def testTrimDistance(self): s = QgsLineSymbol.createSimple({'outline_color': '#ff0000', 'outline_width': '0.6'}) s.symbolLayer(0).setTrimDistanceStart(1.2) s.symbolLayer(0).setTrimDistanceStartUnit(QgsUnitTypes.RenderPoints) s.symbolLayer(0).setTrimDistanceStartMapUnitScale(QgsMapUnitScale(5, 10)) s.symbolLayer(0).setTrimDistanceEnd(3.2) s.symbolLayer(0).setTrimDistanceEndUnit(QgsUnitTypes.RenderPercentage) s.symbolLayer(0).setTrimDistanceEndMapUnitScale(QgsMapUnitScale(15, 20)) s2 = s.clone() self.assertEqual(s2.symbolLayer(0).trimDistanceStart(), 1.2) self.assertEqual(s2.symbolLayer(0).trimDistanceStartUnit(), QgsUnitTypes.RenderPoints) self.assertEqual(s2.symbolLayer(0).trimDistanceStartMapUnitScale().minScale, 5) self.assertEqual(s2.symbolLayer(0).trimDistanceStartMapUnitScale().maxScale, 10) self.assertEqual(s2.symbolLayer(0).trimDistanceEnd(), 3.2) self.assertEqual(s2.symbolLayer(0).trimDistanceEndUnit(), QgsUnitTypes.RenderPercentage) self.assertEqual(s2.symbolLayer(0).trimDistanceEndMapUnitScale().minScale, 15) self.assertEqual(s2.symbolLayer(0).trimDistanceEndMapUnitScale().maxScale, 20) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertEqual(s2.symbolLayer(0).trimDistanceStart(), 1.2) self.assertEqual(s2.symbolLayer(0).trimDistanceStartUnit(), QgsUnitTypes.RenderPoints) self.assertEqual(s2.symbolLayer(0).trimDistanceStartMapUnitScale().minScale, 5) self.assertEqual(s2.symbolLayer(0).trimDistanceStartMapUnitScale().maxScale, 10) self.assertEqual(s2.symbolLayer(0).trimDistanceEnd(), 3.2) self.assertEqual(s2.symbolLayer(0).trimDistanceEndUnit(), QgsUnitTypes.RenderPercentage) self.assertEqual(s2.symbolLayer(0).trimDistanceEndMapUnitScale().minScale, 15) self.assertEqual(s2.symbolLayer(0).trimDistanceEndMapUnitScale().maxScale, 20)
def testRingFilter(self): # test filtering rings during rendering s = QgsFillSymbol() s.deleteSymbolLayer(0) hash_line = QgsHashedLineSymbolLayer(True) hash_line.setPlacement(QgsTemplatedLineSymbolLayerBase.Interval) hash_line.setInterval(6) simple_line = QgsSimpleLineSymbolLayer() simple_line.setColor(QColor(0, 255, 0)) simple_line.setWidth(1) line_symbol = QgsLineSymbol() line_symbol.changeSymbolLayer(0, simple_line) hash_line.setSubSymbol(line_symbol) hash_line.setHashLength(10) hash_line.setAverageAngleLength(0) s.appendSymbolLayer(hash_line.clone()) self.assertEqual( s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.AllRings) s.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) self.assertEqual( s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) s2 = s.clone() self.assertEqual( s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertEqual( s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) # rendering test s3 = QgsFillSymbol() s3.deleteSymbolLayer(0) s3.appendSymbolLayer(hash_line.clone()) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('hashline_exterioronly', 'hashline_exterioronly', rendered_image) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.InteriorRingsOnly) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('hashline_interioronly', 'hashline_interioronly', rendered_image)
def testRingFilter(self): # test filtering rings during rendering s = QgsFillSymbol() s.deleteSymbolLayer(0) marker_line = QgsMarkerLineSymbolLayer(True) marker_line.setPlacement(QgsMarkerLineSymbolLayer.FirstVertex) marker = QgsSimpleMarkerSymbolLayer( QgsSimpleMarkerSymbolLayer.Triangle, 4) marker.setColor(QColor(255, 0, 0)) marker.setStrokeStyle(Qt.NoPen) marker_symbol = QgsMarkerSymbol() marker_symbol.changeSymbolLayer(0, marker) marker_line.setSubSymbol(marker_symbol) s.appendSymbolLayer(marker_line.clone()) self.assertEqual( s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.AllRings) s.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) self.assertEqual( s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) s2 = s.clone() self.assertEqual( s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertEqual( s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) # rendering test s3 = QgsFillSymbol() s3.deleteSymbolLayer(0) s3.appendSymbolLayer(QgsMarkerLineSymbolLayer()) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) s3.symbolLayer(0).setAverageAngleLength(0) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('markerline_exterioronly', 'markerline_exterioronly', rendered_image) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.InteriorRingsOnly) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('markerline_interioronly', 'markerline_interioronly', rendered_image)
def testForceRHR(self): # test forcing right hand rule during rendering s = QgsFillSymbol() s.deleteSymbolLayer(0) s.appendSymbolLayer( QgsSimpleFillSymbolLayer(color=QColor(255, 0, 0), strokeColor=QColor(0, 255, 0))) self.assertFalse(s.forceRHR()) s.setForceRHR(True) self.assertTrue(s.forceRHR()) s.setForceRHR(False) self.assertFalse(s.forceRHR()) s.setForceRHR(True) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertTrue(s2.forceRHR()) # rendering test s3 = QgsFillSymbol() s3.deleteSymbolLayer(0) s3.appendSymbolLayer( QgsSimpleFillSymbolLayer(color=QColor(255, 200, 200), strokeColor=QColor(0, 255, 0), strokeWidth=2)) marker_line = QgsMarkerLineSymbolLayer(True) marker_line.setPlacement(QgsMarkerLineSymbolLayer.FirstVertex) marker = QgsSimpleMarkerSymbolLayer( QgsSimpleMarkerSymbolLayer.Triangle, 4) marker.setColor(QColor(255, 0, 0)) marker.setStrokeStyle(Qt.NoPen) marker_symbol = QgsMarkerSymbol() marker_symbol.changeSymbolLayer(0, marker) marker_line.setSubSymbol(marker_symbol) s3.appendSymbolLayer(marker_line) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('force_rhr_off', 'polygon_forcerhr_off', rendered_image) s3.setForceRHR(True) rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('force_rhr_on', 'polygon_forcerhr_on', rendered_image)
def testRingFilter(self): # test filtering rings during rendering s = QgsFillSymbol() s.deleteSymbolLayer(0) s.appendSymbolLayer( QgsSimpleLineSymbolLayer(color=QColor(255, 0, 0), width=2)) self.assertEqual( s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.AllRings) s.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) self.assertEqual( s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) s2 = s.clone() self.assertEqual( s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertEqual( s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) # rendering test s3 = QgsFillSymbol() s3.deleteSymbolLayer(0) s3.appendSymbolLayer( QgsSimpleLineSymbolLayer(color=QColor(255, 0, 0), width=2)) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('simpleline_exterioronly', 'simpleline_exterioronly', rendered_image) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.InteriorRingsOnly) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('simpleline_interioronly', 'simpleline_interioronly', rendered_image)
def testRingFilter(self): # test filtering rings during rendering s = QgsFillSymbol() s.deleteSymbolLayer(0) hash_line = QgsHashedLineSymbolLayer(True) hash_line.setPlacement(QgsTemplatedLineSymbolLayerBase.Interval) hash_line.setInterval(6) simple_line = QgsSimpleLineSymbolLayer() simple_line.setColor(QColor(0, 255, 0)) simple_line.setWidth(1) line_symbol = QgsLineSymbol() line_symbol.changeSymbolLayer(0, simple_line) hash_line.setSubSymbol(line_symbol) hash_line.setHashLength(10) hash_line.setAverageAngleLength(0) s.appendSymbolLayer(hash_line.clone()) self.assertEqual(s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.AllRings) s.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) self.assertEqual(s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) s2 = s.clone() self.assertEqual(s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertEqual(s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) # rendering test s3 = QgsFillSymbol() s3.deleteSymbolLayer(0) s3.appendSymbolLayer( hash_line.clone()) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) g = QgsGeometry.fromWkt('Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))') rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('hashline_exterioronly', 'hashline_exterioronly', rendered_image) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.InteriorRingsOnly) g = QgsGeometry.fromWkt('Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))') rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('hashline_interioronly', 'hashline_interioronly', rendered_image)
def testRingFilter(self): # test filtering rings during rendering s = QgsFillSymbol() s.deleteSymbolLayer(0) marker_line = QgsMarkerLineSymbolLayer(True) marker_line.setPlacement(QgsMarkerLineSymbolLayer.FirstVertex) marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Triangle, 4) marker.setColor(QColor(255, 0, 0)) marker.setStrokeStyle(Qt.NoPen) marker_symbol = QgsMarkerSymbol() marker_symbol.changeSymbolLayer(0, marker) marker_line.setSubSymbol(marker_symbol) s.appendSymbolLayer(marker_line.clone()) self.assertEqual(s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.AllRings) s.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) self.assertEqual(s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) s2 = s.clone() self.assertEqual(s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertEqual(s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) # rendering test s3 = QgsFillSymbol() s3.deleteSymbolLayer(0) s3.appendSymbolLayer( QgsMarkerLineSymbolLayer()) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) s3.symbolLayer(0).setAverageAngleLength(0) g = QgsGeometry.fromWkt('Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))') rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('markerline_exterioronly', 'markerline_exterioronly', rendered_image) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.InteriorRingsOnly) g = QgsGeometry.fromWkt('Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))') rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('markerline_interioronly', 'markerline_interioronly', rendered_image)
def testSaveRestore(self): """ Test saving and restoring base symbol layer properties to xml""" layer = QgsSimpleFillSymbolLayer() layer.setEnabled(False) layer.setLocked(True) layer.setRenderingPass(5) symbol = QgsFillSymbol() symbol.changeSymbolLayer(0, layer) doc = QDomDocument("testdoc") elem = QgsSymbolLayerUtils.saveSymbol('test', symbol, doc, QgsReadWriteContext()) restored_symbol = QgsSymbolLayerUtils.loadSymbol(elem, QgsReadWriteContext()) restored_layer = restored_symbol.symbolLayer(0) self.assertFalse(restored_layer.enabled()) self.assertTrue(restored_layer.isLocked()) self.assertEqual(restored_layer.renderingPass(), 5)
def testForceRHR(self): # test forcing right hand rule during rendering s = QgsFillSymbol() s.deleteSymbolLayer(0) s.appendSymbolLayer( QgsSimpleFillSymbolLayer(color=QColor(255, 0, 0), strokeColor=QColor(0, 255, 0))) self.assertFalse(s.forceRHR()) s.setForceRHR(True) self.assertTrue(s.forceRHR()) s.setForceRHR(False) self.assertFalse(s.forceRHR()) s.setForceRHR(True) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertTrue(s2.forceRHR()) # rendering test s3 = QgsFillSymbol() s3.deleteSymbolLayer(0) s3.appendSymbolLayer( QgsSimpleFillSymbolLayer(color=QColor(255, 200, 200), strokeColor=QColor(0, 255, 0), strokeWidth=2)) marker_line = QgsMarkerLineSymbolLayer(True) marker_line.setPlacement(QgsMarkerLineSymbolLayer.FirstVertex) marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Triangle, 4) marker.setColor(QColor(255, 0, 0)) marker.setStrokeStyle(Qt.NoPen) marker_symbol = QgsMarkerSymbol() marker_symbol.changeSymbolLayer(0, marker) marker_line.setSubSymbol(marker_symbol) s3.appendSymbolLayer(marker_line) g = QgsGeometry.fromWkt('Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))') rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('force_rhr_off', 'polygon_forcerhr_off', rendered_image) s3.setForceRHR(True) rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('force_rhr_on', 'polygon_forcerhr_on', rendered_image)
def testDashTweaks(self): s = QgsLineSymbol.createSimple({'outline_color': '#ff0000', 'outline_width': '0.6'}) self.assertFalse(s.symbolLayer(0).alignDashPattern()) self.assertFalse(s.symbolLayer(0).tweakDashPatternOnCorners()) s.symbolLayer(0).setAlignDashPattern(True) s.symbolLayer(0).setTweakDashPatternOnCorners(True) s2 = s.clone() self.assertTrue(s2.symbolLayer(0).alignDashPattern()) self.assertTrue(s2.symbolLayer(0).tweakDashPatternOnCorners()) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertTrue(s2.symbolLayer(0).alignDashPattern()) self.assertTrue(s2.symbolLayer(0).tweakDashPatternOnCorners())
def testRingFilter(self): # test filtering rings during rendering s = QgsFillSymbol() s.deleteSymbolLayer(0) s.appendSymbolLayer( QgsSimpleLineSymbolLayer(color=QColor(255, 0, 0), width=2)) self.assertEqual(s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.AllRings) s.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) self.assertEqual(s.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) s2 = s.clone() self.assertEqual(s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertEqual(s2.symbolLayer(0).ringFilter(), QgsLineSymbolLayer.ExteriorRingOnly) # rendering test s3 = QgsFillSymbol() s3.deleteSymbolLayer(0) s3.appendSymbolLayer( QgsSimpleLineSymbolLayer(color=QColor(255, 0, 0), width=2)) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.ExteriorRingOnly) g = QgsGeometry.fromWkt('Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))') rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('simpleline_exterioronly', 'simpleline_exterioronly', rendered_image) s3.symbolLayer(0).setRingFilter(QgsLineSymbolLayer.InteriorRingsOnly) g = QgsGeometry.fromWkt('Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))') rendered_image = self.renderGeometry(s3, g) assert self.imageCheck('simpleline_interioronly', 'simpleline_interioronly', rendered_image)
def testSimple(self): s = QgsFillSymbol() s.deleteSymbolLayer(0) random_fill = QgsRandomMarkerFillSymbolLayer(10, seed=481523) marker = QgsSimpleMarkerSymbolLayer( QgsSimpleMarkerSymbolLayer.Triangle, 4) marker.setColor(QColor(255, 0, 0)) marker.setStrokeStyle(Qt.NoPen) marker_symbol = QgsMarkerSymbol() marker_symbol.changeSymbolLayer(0, marker) random_fill.setSubSymbol(marker_symbol) s.appendSymbolLayer(random_fill.clone()) self.assertEqual(s.symbolLayer(0).pointCount(), 10) self.assertEqual(s.symbolLayer(0).seed(), 481523) s.symbolLayer(0).setPointCount(5) s.symbolLayer(0).setSeed(42) self.assertEqual(s.symbolLayer(0).pointCount(), 5) self.assertEqual(s.symbolLayer(0).seed(), 42) s2 = s.clone() self.assertEqual(s2.symbolLayer(0).pointCount(), 5) self.assertEqual(s2.symbolLayer(0).seed(), 42) doc = QDomDocument() context = QgsReadWriteContext() element = QgsSymbolLayerUtils.saveSymbol('test', s, doc, context) s2 = QgsSymbolLayerUtils.loadSymbol(element, context) self.assertEqual(s2.symbolLayer(0).pointCount(), 5) self.assertEqual(s2.symbolLayer(0).seed(), 42) # rendering test s3 = QgsFillSymbol() s3.deleteSymbolLayer(0) s3.appendSymbolLayer(random_fill.clone()) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) self.assertTrue( self.imageCheck('randommarkerfill', 'randommarkerfill', rendered_image)) s3.symbolLayer(0).setPointCount(3) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) self.assertTrue( self.imageCheck('randommarkerfill_3', 'randommarkerfill_3', rendered_image)) s3.symbolLayer(0).setSeed(12783) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) self.assertTrue( self.imageCheck('randommarkerfill_seed', 'randommarkerfill_seed', rendered_image)) # random seed s3.symbolLayer(0).setSeed(0) g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) self.assertFalse( self.imageCheck('randommarkerfill_seed', 'randommarkerfill_seed', rendered_image, expect_fail=True)) # density-based count s3.symbolLayer(0).setSeed(1) s3.symbolLayer(0).setCountMethod( QgsRandomMarkerFillSymbolLayer.DensityBasedCount) s3.symbolLayer(0).setPointCount(5) s3.symbolLayer(0).setDensityArea(250) # 250 square millimeter g = QgsGeometry.fromWkt( 'Polygon((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1),(8 8, 9 8, 9 9, 8 9, 8 8))' ) rendered_image = self.renderGeometry(s3, g) self.assertTrue( self.imageCheck('randommarkerfill_densitybasedcount', 'randommarkerfill_densitybasedcount', rendered_image))