def testFixedColorFixedWidth(self): """ test that rendering a interpolated line with fixed width and fixed color""" interpolated_width = QgsInterpolatedLineWidth() interpolated_color = QgsInterpolatedLineColor() interpolated_width.setIsVariableWidth(False) interpolated_width.setFixedStrokeWidth(5) interpolated_color.setColor(QColor(255, 0, 0)) interpolated_color.setColoringMethod( QgsInterpolatedLineColor.SingleColor) self.renderImage(interpolated_width, interpolated_color, 'interpolatedlinesymbollayer_1')
def testRenderNoFeature(self): """ test that rendering a interpolated line outside of a map render works""" interpolated_width = QgsInterpolatedLineWidth() interpolated_color = QgsInterpolatedLineColor() interpolated_width.setIsVariableWidth(False) interpolated_width.setFixedStrokeWidth(5) interpolated_color.setColor(QColor(255, 0, 0)) interpolated_color.setColoringMethod( QgsInterpolatedLineColor.SingleColor) layer = QgsInterpolatedLineSymbolLayer() layer.setDataDefinedProperty( QgsSymbolLayer.PropertyLineStartWidthValue, QgsProperty.fromExpression('5')) layer.setDataDefinedProperty(QgsSymbolLayer.PropertyLineEndWidthValue, QgsProperty.fromExpression('1')) layer.setDataDefinedProperty( QgsSymbolLayer.PropertyLineStartColorValue, QgsProperty.fromExpression('2')) layer.setDataDefinedProperty(QgsSymbolLayer.PropertyLineEndColorValue, QgsProperty.fromExpression('6')) layer.setInterpolatedWidth(interpolated_width) layer.setInterpolatedColor(interpolated_color) symbol = QgsLineSymbol() symbol.changeSymbolLayer(0, layer) image = QImage(200, 200, QImage.Format_RGB32) image.fill(QColor(255, 255, 255)) painter = QPainter(image) context = QgsRenderContext.fromQPainter(painter) symbol.startRender(context) symbol.renderPolyline( QPolygonF([QPointF(30, 50), QPointF(100, 70), QPointF(150, 30)]), None, context) symbol.stopRender(context) painter.end() self.assertTrue( self.imageCheck('interpolatedlinesymbollayer_no_feature', 'interpolatedlinesymbollayer_no_feature', image))
def testFixedColorVaryingWidth(self): """ test that rendering a interpolated line with varying width and fixed color""" interpolated_width = QgsInterpolatedLineWidth() interpolated_color = QgsInterpolatedLineColor() interpolated_width.setIsVariableWidth(True) interpolated_width.setMinimumValue(1) interpolated_width.setMaximumValue(8) interpolated_width.setMinimumWidth(1) interpolated_width.setMaximumWidth(10) interpolated_color.setColor(QColor(0, 255, 0)) interpolated_color.setColoringMethod( QgsInterpolatedLineColor.SingleColor) self.renderImage(interpolated_width, interpolated_color, 'interpolatedlinesymbollayer_3')
def testVaryingColorFixedWidth(self): """ test that rendering a interpolated line with fixed width and varying color""" interpolated_width = QgsInterpolatedLineWidth() interpolated_color = QgsInterpolatedLineColor() interpolated_width.setIsVariableWidth(False) interpolated_width.setFixedStrokeWidth(5) color_ramp = QgsColorRampShader( 0, 7, QgsStyle.defaultStyle().colorRamp('Viridis'), QgsColorRampShader.Interpolated) color_ramp.classifyColorRamp(10) interpolated_color.setColor(color_ramp) interpolated_color.setColoringMethod( QgsInterpolatedLineColor.ColorRamp) self.renderImage(interpolated_width, interpolated_color, 'interpolatedlinesymbollayer_2')
def testVaryingColorVaryingWidthExact(self): """ test that rendering a interpolated line with varying width and varying color with exact color ramp """ interpolated_width = QgsInterpolatedLineWidth() interpolated_color = QgsInterpolatedLineColor() interpolated_width.setIsVariableWidth(True) interpolated_width.setMinimumValue(1) interpolated_width.setMaximumValue(8) interpolated_width.setMinimumWidth(1) interpolated_width.setMaximumWidth(10) color_ramp = QgsColorRampShader( 0, 10, QgsStyle.defaultStyle().colorRamp('Viridis'), QgsColorRampShader.Exact) color_ramp.classifyColorRamp(10) interpolated_color.setColor(color_ramp) interpolated_color.setColoringMethod( QgsInterpolatedLineColor.ColorRamp) self.renderImage(interpolated_width, interpolated_color, 'interpolatedlinesymbollayer_6')
def testVaryingColorVaryingWidthDiscrete(self): """ test that rendering a interpolated line with varying width and varying color with discrete color ramp """ interpolated_width = QgsInterpolatedLineWidth() interpolated_color = QgsInterpolatedLineColor() interpolated_width.setIsVariableWidth(True) interpolated_width.setMinimumValue(1) interpolated_width.setMaximumValue(8) interpolated_width.setMinimumWidth(1) interpolated_width.setMaximumWidth(10) color_ramp = QgsColorRampShader( 2, 7, QgsStyle.defaultStyle().colorRamp('RdGy'), QgsColorRampShader.Discrete) color_ramp.classifyColorRamp(5) interpolated_color.setColor(color_ramp) interpolated_color.setColoringMethod( QgsInterpolatedLineColor.ColorRamp) self.renderImage(interpolated_width, interpolated_color, 'interpolatedlinesymbollayer_5')