Subgroup: Symbol

Class: QgsSymbol

class qgis.core.QgsSymbol(type: QgsSymbol.SymbolType, layers: object)

Bases: sip.wrapper

Methods

appendSymbolLayer Append symbol layer at the end of the list Ownership will be transferred.
asImage Generate symbol as image
bigSymbolPreviewImage Returns a large (roughly 100x100 pixel) preview image for the symbol.
changeSymbolLayer delete layer at specified index and set a new one
clipFeaturesToExtent Returns whether features drawn by the symbol will be clipped to the render context’s extent.
clone Gets a deep copy of this symbol.
cloneLayers Retrieve a cloned list of all layers that make up this symbol.
color
defaultSymbol Returns new default symbol for specified geometry type
deleteSymbolLayer delete symbol layer at specified index
drawPreviewIcon Draw icon of the symbol that occupyies area given by size using the painter.
dump
exportImage export symbol as image format.
hasDataDefinedProperties Returns whether the symbol utilizes any data defined properties.
insertSymbolLayer Insert symbol layer to specified index Ownership will be transferred.
layer
mapUnitScale
opacity Returns the opacity for the symbol.
outputUnit Returns the units to use for sizes and widths within the symbol.
renderFeature Render a feature.
renderHints Returns the rendering hint flags for the symbol.
renderUsingLayer Renders a context using a particular symbol layer without passing in a geometry.
renderVertexMarker Render editing vertex marker at specified point
setClipFeaturesToExtent Sets whether features drawn by the symbol should be clipped to the render context’s extent.
setColor
setLayer
setMapUnitScale
setOpacity Sets the opacity for the symbol.
setOutputUnit Sets the units to use for sizes and widths within the symbol.
setRenderHints Sets rendering hint flags for the symbol.
startRender Begins the rendering process for the symbol.
stopRender Ends the rendering process.
symbolLayer Returns a specific symbol layers contained in the symbol.
symbolLayerCount Returns total number of symbol layers contained in the symbol.
symbolLayers Returns list of symbol layers contained in the symbol.
symbolRenderContext Returns the symbol render context.
takeSymbolLayer Remove symbol layer from the list and return pointer to it.
toSld
type
usedAttributes Returns a list of attributes required to render this feature.

Signals

Attributes

DynamicRotation
Fill
Hybrid
Line
Marker
ScaleArea
ScaleDiameter
DynamicRotation = 2
Fill = 2
Hybrid = 3
Line = 1
Marker = 0
class RenderHint

Bases: int

class RenderHints

Bases: sip.wrapper

QgsSymbol.RenderHints(Union[QgsSymbol.RenderHints, QgsSymbol.RenderHint]) QgsSymbol.RenderHints(QgsSymbol.RenderHints)

ScaleArea = 0
ScaleDiameter = 1
class ScaleMethod

Bases: int

class SymbolType

Bases: int

appendSymbolLayer(self, layer: QgsSymbolLayer) → bool

Append symbol layer at the end of the list Ownership will be transferred.

Parameters:layer – The layer to add
Returns:True if the layer is added, False if the layer is bad
asImage(self, size: QSize, customContext: QgsRenderContext = None) → QImage

Generate symbol as image

bigSymbolPreviewImage(self, expressionContext: QgsExpressionContext = None) → QImage

Returns a large (roughly 100x100 pixel) preview image for the symbol.

Parameters:expressionContext – optional expression context, for evaluation of data defined symbol properties
changeSymbolLayer(self, index: int, layer: QgsSymbolLayer) → bool

delete layer at specified index and set a new one

clipFeaturesToExtent(self) → bool

Returns whether features drawn by the symbol will be clipped to the render context’s extent. If this option is enabled then features which are partially outside the extent will be clipped. This speeds up rendering of the feature, but may have undesirable side effects for certain symbol types.

Returns:true if features will be clipped

New in version 2.9.

clone(self) → QgsSymbol

Gets a deep copy of this symbol. Needs to be reimplemented by subclasses. Ownership is transferred to the caller.

cloneLayers(self) → object

Retrieve a cloned list of all layers that make up this symbol. Ownership is transferred to the caller.

color(self) → QColor
defaultSymbol(geomType: QgsWkbTypes.GeometryType) → QgsSymbol

Returns new default symbol for specified geometry type

deleteSymbolLayer(self, index: int) → bool

delete symbol layer at specified index

drawPreviewIcon(self, painter: QPainter, size: QSize, customContext: QgsRenderContext = None)

Draw icon of the symbol that occupyies area given by size using the painter. Optionally custom context may be given in order to get rendering of symbols that use map units right.

New in version 2.6.

dump(self) → str
exportImage(self, path: str, format: str, size: QSize)

export symbol as image format. PNG and SVG supported

hasDataDefinedProperties(self) → bool

Returns whether the symbol utilizes any data defined properties.

New in version 2.12.

insertSymbolLayer(self, index: int, layer: QgsSymbolLayer) → bool

Insert symbol layer to specified index Ownership will be transferred.

Parameters:
  • index – The index at which the layer should be added
  • layer – The symbol layer to add
Returns:

True if the layer is added, False if the index or the layer is bad

layer(self) → QgsVectorLayer
mapUnitScale(self) → QgsMapUnitScale
opacity(self) → float

Returns the opacity for the symbol.

Returns:opacity value between 0 (fully transparent) and 1 (fully opaque)

See also

setOpacity()

outputUnit(self) → QgsUnitTypes.RenderUnit

Returns the units to use for sizes and widths within the symbol. Individual symbol layer definitions will interpret this in different ways, e.g., a marker symbol may use it to specify the units for the marker size, while a line symbol may use it to specify the units for the line width.

Returns:output unit, or QgsUnitTypes.RenderUnknownUnit if the symbol contains mixed units

See also

setOutputUnit()

renderFeature(self, feature: QgsFeature, context: QgsRenderContext, layer: int = -1, selected: bool = False, drawVertexMarker: bool = False, currentVertexMarkerType: int = 0, currentVertexMarkerSize: int = 0)

Render a feature. Before calling this the startRender() method should be called to initialize the rendering process. After rendering all features stopRender() must be called.

renderHints(self) → QgsSymbol.RenderHints

Returns the rendering hint flags for the symbol.

See also

setRenderHints()

renderUsingLayer(self, layer: QgsSymbolLayer, context: QgsSymbolRenderContext)

Renders a context using a particular symbol layer without passing in a geometry. This is used as fallback, if the symbol being rendered is not compatible with the specified layer. In such a case, this method can be called and will call the layer’s rendering method anyway but the geometry passed to the layer will be empty. This is required for layers that generate their own geometry from other information in the rendering context.

renderVertexMarker(self, pt: Union[QPointF, QPoint], context: QgsRenderContext, currentVertexMarkerType: int, currentVertexMarkerSize: int)

Render editing vertex marker at specified point

New in version 2.16.

setClipFeaturesToExtent(self, clipFeaturesToExtent: bool)

Sets whether features drawn by the symbol should be clipped to the render context’s extent. If this option is enabled then features which are partially outside the extent will be clipped. This speeds up rendering of the feature, but may have undesirable side effects for certain symbol types.

Parameters:clipFeaturesToExtent – set to true to enable clipping (defaults to true)

New in version 2.9.

setColor(self, color: Union[QColor, Qt.GlobalColor])
setLayer(self, layer: QgsVectorLayer)

Note

the layer will be NULL after stopRender

setMapUnitScale(self, scale: QgsMapUnitScale)
setOpacity(self, opacity: float)

Sets the opacity for the symbol.

Parameters:opacity – opacity value between 0 (fully transparent) and 1 (fully opaque)

See also

opacity()

setOutputUnit(self, unit: QgsUnitTypes.RenderUnit)

Sets the units to use for sizes and widths within the symbol. Individual symbol definitions will interpret this in different ways, e.g., a marker symbol may use it to specify the units for the marker size, while a line symbol may use it to specify the units for the line width.

Parameters:unit – output units

See also

outputUnit()

setRenderHints(self, hints: Union[QgsSymbol.RenderHints, QgsSymbol.RenderHint])

Sets rendering hint flags for the symbol.

See also

renderHints()

startRender(self, context: QgsRenderContext, fields: QgsFields = QgsFields())

Begins the rendering process for the symbol. This must be called before renderFeature(), and should be followed by a call to stopRender().

Parameters:
  • context – render context which symbol will be drawn using
  • fields – fields for features to be rendered (usually the associated vector layer’s fields). Required for correct calculation of data defined overrides.

See also

stopRender()

stopRender(self, context: QgsRenderContext)

Ends the rendering process. This should be called after rendering all desired features.

Parameters:context – render context, must match the context specified when startRender() was called.

See also

startRender()

symbolLayer(self, layer: int) → QgsSymbolLayer

Returns a specific symbol layers contained in the symbol.

Parameters:layer – layer number
Returns:corresponding symbol layer

See also

symbolLayers()

New in version 2.7.

symbolLayerCount(self) → int

Returns total number of symbol layers contained in the symbol.

Returns:count of symbol layers

See also

symbolLayers()

See also

symbolLayer()

New in version 2.7.

symbolLayers(self) → object

Returns list of symbol layers contained in the symbol.

Returns:symbol layers list

See also

symbolLayer()

New in version 2.7.

symbolRenderContext(self) → QgsSymbolRenderContext

Returns the symbol render context. Only valid between startRender and stopRender calls.

Returns:The symbol render context
takeSymbolLayer(self, index: int) → QgsSymbolLayer

Remove symbol layer from the list and return pointer to it. Ownership is handed to the caller.

Parameters:index – The index of the layer to remove
Returns:A pointer to the removed layer
toSld(self, doc: QDomDocument, element: QDomElement, props: Dict[str, str])
type(self) → QgsSymbol.SymbolType
usedAttributes(self, context: QgsRenderContext) → Set[str]

Returns a list of attributes required to render this feature. This should include any attributes required by the symbology including the ones required by expressions.