Class: QgsFeatureRenderer

class qgis.core.QgsFeatureRenderer(type: str | None)

Bases: sip.wrapper

Enums

Property

Bases: enum.IntEnum

Methods

accept

Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer.

canSkipRender

Returns True if the renderer can be entirely skipped, i.e. if it is known in advance that no features will be rendered.

capabilities

Returns details about internals of this renderer.

checkLegendSymbolItem

Sets whether the legend symbology item with the specified ley should be checked.

clone

Create a deep copy of this renderer.

convertSymbolRotation

convertSymbolSizeScale

copyRendererData

Clones generic renderer data to another renderer.

createLegendNodes

Returns a list of legend nodes to be used for the legend for the renderer.

dataDefinedProperties

Returns a reference to the renderer's property collection, used for data defined overrides.

defaultRenderer

Returns a new renderer - used by default in vector layers

dump

Returns debug information about this renderer

embeddedRenderer

Returns the current embedded renderer (subrenderer) for this feature renderer.

filter

If a renderer does not require all the features this method may be overridden and return an expression used as where clause.

filterNeedsGeometry

Returns True if this renderer requires the geometry to apply the filter.

forceRasterRender

Returns whether the renderer must render as a raster.

legendClassificationAttribute

If supported by the renderer, return classification attribute for the use in legend

legendKeyToExpression

Attempts to convert the specified legend rule key to a QGIS expression matching the features displayed using that key.

legendKeys

Returns the set of all legend keys used by the renderer.

legendKeysForFeature

Returns legend keys matching a specified feature.

legendSymbolItemChecked

Returns True if the legend symbology item with the specified key is checked.

legendSymbolItems

Returns a list of symbology items for the legend

legendSymbolItemsCheckable

Returns True if symbology items in legend are checkable.

load

create a renderer from XML element

loadSld

Create a new renderer according to the information contained in the UserStyle element of a SLD style document

modifyRequestExtent

Allows for a renderer to modify the extent of a feature request prior to rendering

orderBy

Gets the order in which features shall be processed by this renderer.

orderByEnabled

Returns whether custom ordering will be applied before features are processed by this renderer.

originalSymbolForFeature

Returns symbol for feature.

originalSymbolsForFeature

Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbols per feature - similar to symbolsForFeature()

paintEffect

Returns the current paint effect for the renderer.

propertyDefinitions

Returns the symbol property definitions.

referenceScale

Returns the symbology reference scale.

renderFeature

Render a feature using this renderer in the given context.

renderFeatureWithSymbol

Render the feature with the symbol using context.

renderVertexMarker

render editing vertex marker at specified point

renderVertexMarkerPolygon

render editing vertex marker for a polygon

renderVertexMarkerPolyline

render editing vertex marker for a polyline

save

Stores renderer properties to an XML element.

saveRendererData

Saves generic renderer data into the specified element.

setDataDefinedProperties

Sets the renderer's property collection, used for data defined overrides.

setDataDefinedProperty

Sets a data defined property for the renderer.

setEmbeddedRenderer

Sets an embedded renderer (subrenderer) for this feature renderer.

setForceRasterRender

Sets whether the renderer should be rendered to a raster destination.

setLegendSymbolItem

Sets the symbol to be used for a legend symbol item.

setOrderBy

Define the order in which features shall be processed by this renderer.

setOrderByEnabled

Sets whether custom ordering should be applied before features are processed by this renderer.

setPaintEffect

Sets the current paint effect for the renderer.

setReferenceScale

Sets the symbology reference scale.

setUsingSymbolLevels

param usingSymbolLevels:

setVertexMarkerAppearance

Sets type and size of editing vertex markers for subsequent rendering

startRender

Must be called when a new render cycle is started.

stopRender

Must be called when a render cycle has finished, to allow the renderer to clean up.

symbolForFeature

To be overridden

symbols

Returns list of symbols used by the renderer.

symbolsForFeature

Returns list of symbols used for rendering the feature.

toSld

used from subclasses to create SLD Rule elements following SLD v1.1 specs

type

rtype:

str

usedAttributes

Returns a list of attributes required by this renderer.

usesEmbeddedSymbols

Returns True if the renderer uses embedded symbols for features.

usingSymbolLevels

rtype:

bool

willRenderFeature

Returns whether the renderer will render a feature or not.

writeSld

create the SLD UserStyle element following the SLD v1.1 specs with the given name

Attributes

Filter

MoreSymbolsPerFeature

ScaleDependent

SymbolLevels

class Capabilities
class Capabilities(f: QgsFeatureRenderer.Capabilities | QgsFeatureRenderer.Capability)
class Capabilities(a0: QgsFeatureRenderer.Capabilities)

Bases: sip.wrapper

class Capability

Bases: int

Filter = 8
MoreSymbolsPerFeature = 4
class Property(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: enum.IntEnum

Data definable properties for renderers.

Added in version 3.38.

  • HeatmapRadius: Heatmap renderer radius

  • HeatmapMaximum: Heatmap maximum value

HeatmapMaximum = 1
HeatmapRadius = 0
ScaleDependent = 16
SymbolLevels = 1
accept(self, visitor: QgsStyleEntityVisitorInterface | None) bool

Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer.

Returns True if the visitor should continue visiting other objects, or False if visiting should be canceled.

Added in version 3.10.

Parameters:

visitor (Optional[QgsStyleEntityVisitorInterface])

Return type:

bool

canSkipRender(self) bool

Returns True if the renderer can be entirely skipped, i.e. if it is known in advance that no features will be rendered.

Warning

Must be called between startRender() and stopRender() calls.

Added in version 3.30.

Return type:

bool

capabilities(self) QgsFeatureRenderer.Capabilities

Returns details about internals of this renderer.

E.g. if you only want to deal with visible features:

if not renderer.capabilities().testFlag(QgsFeatureRenderer.Filter) or renderer.willRenderFeature(feature, context):
    deal_with_my_feature()
else:
    skip_the_curren_feature()
Return type:

QgsFeatureRenderer.Capabilities

checkLegendSymbolItem(self, key: str | None, state: bool = True)

Sets whether the legend symbology item with the specified ley should be checked.

See also

legendKeys()

Parameters:
  • key (Optional[str])

  • state (bool = True)

clone(self) QgsFeatureRenderer | None

Create a deep copy of this renderer. Should be implemented by all subclasses and generate a proper subclass.

Return type:

Optional[QgsFeatureRenderer]

Returns:

A copy of this renderer

convertSymbolRotation(symbol: QgsSymbol | None, field: str | None)

Note

this function is used to convert old rotations expressions to symbol level DataDefined angle

Parameters:
  • symbol (Optional[QgsSymbol])

  • field (Optional[str])

convertSymbolSizeScale(symbol: QgsSymbol | None, method: Qgis.ScaleMethod, field: str | None)

Note

this function is used to convert old sizeScale expressions to symbol level DataDefined size

Parameters:
copyRendererData(self, destRenderer: QgsFeatureRenderer | None)

Clones generic renderer data to another renderer.

Currently clones

  • Order by

  • Paint effect

  • Reference scale

  • Symbol levels enabled/disabled

  • Force raster render enabled/disabled

  • Data defined properties

Parameters:

destRenderer (Optional[QgsFeatureRenderer]) – destination renderer for copied effect

Added in version 3.22.

createLegendNodes(self, nodeLayer: QgsLayerTreeLayer | None) List[QgsLayerTreeModelLegendNode]

Returns a list of legend nodes to be used for the legend for the renderer.

Ownership is transferred to the caller.

The default implementation creates a legend node for each symbol item returned by legendSymbolItems()

Added in version 3.38.

Parameters:

nodeLayer (Optional[QgsLayerTreeLayer])

Return type:

List[QgsLayerTreeModelLegendNode]

dataDefinedProperties(self) QgsPropertyCollection

Returns a reference to the renderer’s property collection, used for data defined overrides.

See also

Property

Added in version 3.38.

Return type:

QgsPropertyCollection

defaultRenderer(geomType: Qgis.GeometryType) QgsFeatureRenderer | None

Returns a new renderer - used by default in vector layers

Parameters:

geomType (Qgis.GeometryType)

Return type:

Optional[QgsFeatureRenderer]

dump(self) str

Returns debug information about this renderer

Return type:

str

embeddedRenderer(self) QgsFeatureRenderer | None

Returns the current embedded renderer (subrenderer) for this feature renderer. The base class implementation does not use subrenderers and will always return None.

Return type:

Optional[QgsFeatureRenderer]

filter(self, fields: QgsFields = QgsFields()) str

If a renderer does not require all the features this method may be overridden and return an expression used as where clause. This will be called once after startRender() and before the first call to renderFeature(). By default this returns a null string and all features will be requested. You do not need to specify the extent in here, this is taken care of separately and will be combined with a filter returned from this method.

Return type:

str

Returns:

An expression used as where clause

Parameters:

fields (QgsFields = QgsFields())

filterNeedsGeometry(self) bool

Returns True if this renderer requires the geometry to apply the filter.

Return type:

bool

forceRasterRender(self) bool

Returns whether the renderer must render as a raster.

Return type:

bool

legendClassificationAttribute(self) str

If supported by the renderer, return classification attribute for the use in legend

Return type:

str

legendKeyToExpression(self, key: str | None, layer: QgsVectorLayer | None)

Attempts to convert the specified legend rule key to a QGIS expression matching the features displayed using that key.

Parameters:
  • key (Optional[str]) – legend key

  • layer (Optional[QgsVectorLayer]) -> (str) – associated vector layer

Returns:

  • QGIS expression string for matching features with the specified key

  • ok: will be set to True if legend key was successfully converted to a filter expression

See also

legendKeys()

Added in version 3.26.

legendKeys(self) Set[str]

Returns the set of all legend keys used by the renderer.

Added in version 3.32.

Return type:

Set[str]

legendKeysForFeature(self, feature: QgsFeature, context: QgsRenderContext) Set[str]

Returns legend keys matching a specified feature.

Parameters:
Return type:

Set[str]

legendSymbolItemChecked(self, key: str | None) bool

Returns True if the legend symbology item with the specified key is checked.

See also

legendKeys()

Parameters:

key (Optional[str])

Return type:

bool

legendSymbolItems(self) List[QgsLegendSymbolItem]

Returns a list of symbology items for the legend

See also

legendKeys()

Return type:

List[QgsLegendSymbolItem]

legendSymbolItemsCheckable(self) bool

Returns True if symbology items in legend are checkable.

Return type:

bool

load(symbologyElem: QDomElement, context: QgsReadWriteContext) QgsFeatureRenderer | None

create a renderer from XML element

Parameters:
Return type:

Optional[QgsFeatureRenderer]

loadSld(node: QDomNode, geomType: Qgis.GeometryType, errorMessage: str | None) QgsFeatureRenderer | None

Create a new renderer according to the information contained in the UserStyle element of a SLD style document

Parameters:
  • node (QDomNode) – the node in the SLD document whose the UserStyle element is a child

  • geomType (Qgis.GeometryType) – the geometry type of the features, used to convert Symbolizer elements

  • errorMessage (Optional[str]) – it will contain the error message if something went wrong

Return type:

Optional[QgsFeatureRenderer]

Returns:

the renderer

modifyRequestExtent(self, extent: QgsRectangle, context: QgsRenderContext)

Allows for a renderer to modify the extent of a feature request prior to rendering

Parameters:
  • extent (QgsRectangle) – reference to request’s filter extent. Modify extent to change the extent of feature request

  • context (QgsRenderContext) – render context

orderBy(self) QgsFeatureRequest.OrderBy

Gets the order in which features shall be processed by this renderer.

Note

this property has no effect if orderByEnabled() is False

See also

orderByEnabled()

Return type:

QgsFeatureRequest.OrderBy

orderByEnabled(self) bool

Returns whether custom ordering will be applied before features are processed by this renderer.

See also

orderBy()

Return type:

bool

originalSymbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) QgsSymbol | None

Returns symbol for feature. The difference compared to symbolForFeature() is that it returns original symbol which can be used as an identifier for renderer’s rule - the former may return a temporary replacement of a symbol for use in rendering.

Parameters:
Return type:

Optional[QgsSymbol]

originalSymbolsForFeature(self, feature: QgsFeature, context: QgsRenderContext) List[QgsSymbol]

Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbols per feature - similar to symbolsForFeature()

Parameters:
Return type:

List[QgsSymbol]

paintEffect(self) QgsPaintEffect | None

Returns the current paint effect for the renderer.

Return type:

Optional[QgsPaintEffect]

Returns:

paint effect

See also

setPaintEffect()

propertyDefinitions() Dict[int, QgsPropertyDefinition]

Returns the symbol property definitions.

Added in version 3.18.

Return type:

Dict[int, QgsPropertyDefinition]

referenceScale(self) float

Returns the symbology reference scale.

This represents the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render. A value of -1 indicates that symbology scaling by reference scale is disabled.

The symbology reference scale is an optional property which specifies the reference scale at which symbology in paper units (such a millimeters or points) is fixed to. For instance, if the scale is 1000 then a 2mm thick line will be rendered at exactly 2mm thick when a map is rendered at 1:1000, or 1mm thick when rendered at 1:2000, or 4mm thick at 1:500.

Added in version 3.22.

Return type:

float

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

Render a feature using this renderer in the given context. Must be called between startRender() and stopRender() calls. Default implementation renders a symbol as determined by symbolForFeature() call. Returns True if the feature has been returned (this is used for example to determine whether the feature may be labelled).

If layer is not -1, the renderer should draw only a particular layer from symbols (in order to support symbol level rendering).

See also

startRender()

See also

stopRender()

Parameters:
Return type:

bool

renderFeatureWithSymbol(self, feature: QgsFeature, symbol: QgsSymbol | None, context: QgsRenderContext, layer: int, selected: bool, drawVertexMarker: bool)

Render the feature with the symbol using context. Use layer to specify the symbol layer, selected to specify if it should be rendered as selected and drawVertexMarker to specify if vertex markers should be rendered.

Parameters:
renderVertexMarker(self, pt: QPointF | QPoint, context: QgsRenderContext)

render editing vertex marker at specified point

Parameters:
renderVertexMarkerPolygon(self, pts: QPolygonF, rings: Iterable[QPolygonF] | None, context: QgsRenderContext)

render editing vertex marker for a polygon

Parameters:
  • pts (QPolygonF)

  • rings (Optional[Iterable[QPolygonF]])

  • context (QgsRenderContext)

renderVertexMarkerPolyline(self, pts: QPolygonF, context: QgsRenderContext)

render editing vertex marker for a polyline

Parameters:
save(self, doc: QDomDocument, context: QgsReadWriteContext) QDomElement

Stores renderer properties to an XML element.

Subclasses which override this method should call saveRendererData() as part of their implementation in order to store all common base class properties in the returned DOM element.

Parameters:
Return type:

QDomElement

saveRendererData(self, doc: QDomDocument, element: QDomElement, context: QgsReadWriteContext)

Saves generic renderer data into the specified element.

This method should be called in a subclass’ save() implementation in order to store all common base class properties in the DOM element.

Added in version 3.22.

Parameters:
setDataDefinedProperties(self, collection: QgsPropertyCollection)

Sets the renderer’s property collection, used for data defined overrides.

Parameters:

collection (QgsPropertyCollection) – property collection. Existing properties will be replaced.

Added in version 3.38.

setDataDefinedProperty(self, key: QgsFeatureRenderer.Property, property: QgsProperty)

Sets a data defined property for the renderer. Any existing property with the same key will be overwritten.

See also

Property

Added in version 3.38.

Parameters:
setEmbeddedRenderer(self, subRenderer: QgsFeatureRenderer | None)

Sets an embedded renderer (subrenderer) for this feature renderer. The base class implementation does nothing with subrenderers, but individual derived classes can use these to modify their behavior.

Parameters:

subRenderer (Optional[QgsFeatureRenderer]) – the embedded renderer. Ownership will be transferred.

setForceRasterRender(self, forceRaster: bool)

Sets whether the renderer should be rendered to a raster destination.

Parameters:

forceRaster (bool) – set to True if renderer must be drawn on a raster surface. This may be desirable for highly detailed layers where rendering as a vector would result in a large, complex vector output.

setLegendSymbolItem(self, key: str | None, symbol: QgsSymbol | None)

Sets the symbol to be used for a legend symbol item.

Parameters:
  • key (Optional[str]) – rule key for legend symbol

  • symbol (Optional[QgsSymbol]) – new symbol for legend item. Ownership is transferred to renderer.

See also

legendKeys()

setOrderBy(self, orderBy: QgsFeatureRequest.OrderBy)

Define the order in which features shall be processed by this renderer.

Note

this property has no effect if orderByEnabled() is False

Parameters:

orderBy (QgsFeatureRequest.OrderBy)

setOrderByEnabled(self, enabled: bool)

Sets whether custom ordering should be applied before features are processed by this renderer.

Parameters:

enabled (bool) – set to True to enable custom feature ordering

See also

setOrderBy()

See also

orderByEnabled()

setPaintEffect(self, effect: QgsPaintEffect | None)

Sets the current paint effect for the renderer.

Parameters:

effect (Optional[QgsPaintEffect]) – paint effect. Ownership is transferred to the renderer.

See also

paintEffect()

setReferenceScale(self, scale: float)

Sets the symbology reference scale.

This should match the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render. Set to -1 to disable symbology scaling by reference scale.

The symbology reference scale is an optional property which specifies the reference scale at which symbology in paper units (such a millimeters or points) is fixed to. For instance, if scale is set to 1000 then a 2mm thick line will be rendered at exactly 2mm thick when a map is rendered at 1:1000, or 1mm thick when rendered at 1:2000, or 4mm thick at 1:500.

See also

referenceScale()

Added in version 3.22.

Parameters:

scale (float)

setUsingSymbolLevels(self, usingSymbolLevels: bool)
Parameters:

usingSymbolLevels (bool)

setVertexMarkerAppearance(self, type: Qgis.VertexMarkerType, size: float)

Sets type and size of editing vertex markers for subsequent rendering

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

Must be called when a new render cycle is started. A call to startRender() must always be followed by a corresponding call to stopRender() after all features have been rendered.

Parameters:
  • context (QgsRenderContext) – Additional information passed to the renderer about the job which will be rendered

  • fields (QgsFields) – The fields available for rendering

See also

stopRender()

Warning

This method is not thread safe. Before calling startRender() in a non-main thread, the renderer should instead be cloned and startRender()/stopRender() called on the clone.

stopRender(self, context: QgsRenderContext)

Must be called when a render cycle has finished, to allow the renderer to clean up.

Calls to stopRender() must always be preceded by a call to startRender().

Warning

This method is not thread safe. Before calling startRender() in a non-main thread, the renderer should instead be cloned and startRender()/stopRender() called on the clone.

See also

startRender()

Parameters:

context (QgsRenderContext)

symbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) QgsSymbol | None

To be overridden

Must be called between startRender() and stopRender() calls.

Parameters:
Return type:

Optional[QgsSymbol]

Returns:

returns pointer to symbol or 0 if symbol was not found

symbols(self, context: QgsRenderContext) List[QgsSymbol]

Returns list of symbols used by the renderer.

Parameters:

context (QgsRenderContext) – render context

Return type:

List[QgsSymbol]

symbolsForFeature(self, feature: QgsFeature, context: QgsRenderContext) List[QgsSymbol]

Returns list of symbols used for rendering the feature. For renderers that do not support MoreSymbolsPerFeature it is more efficient to use symbolForFeature()

Parameters:
Return type:

List[QgsSymbol]

toSld(self, doc: QDomDocument, element: QDomElement, props: Dict[str, Any] = {})

used from subclasses to create SLD Rule elements following SLD v1.1 specs

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • props (Dict[str)

type(self) str
Return type:

str

usedAttributes(self, context: QgsRenderContext) Set[str]

Returns a list of attributes required by this renderer. Attributes not listed in here may not have been requested from the provider at rendering time.

Return type:

Set[str]

Returns:

A set of attributes

Parameters:

context (QgsRenderContext)

usesEmbeddedSymbols(self) bool

Returns True if the renderer uses embedded symbols for features. The default implementation returns False.

Added in version 3.20.

Return type:

bool

usingSymbolLevels(self) bool
Return type:

bool

willRenderFeature(self, feature: QgsFeature, context: QgsRenderContext) bool

Returns whether the renderer will render a feature or not. Must be called between startRender() and stopRender() calls. Default implementation uses symbolForFeature().

Parameters:
Return type:

bool

writeSld(self, doc: QDomDocument, styleName: str | None, props: Dict[str, Any] = {}) QDomElement

create the SLD UserStyle element following the SLD v1.1 specs with the given name

Parameters:
  • doc (QDomDocument)

  • styleName (Optional[str])

  • props (Dict[str)

Return type:

QDomElement