Class: QgsFeatureRenderer

class qgis.core.QgsFeatureRenderer(type: str)

Bases: sip.wrapper

Enums

Methods

capabilities Returns details about internals of this renderer.
checkLegendSymbolItem item in symbology was checked
clone Create a deep copy of this renderer.
convertSymbolRotation
convertSymbolSizeScale
copyRendererData Clones generic renderer data to another renderer.
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
legendKeysForFeature Returns legend keys matching a specified feature.
legendSymbolItemChecked items of symbology items in legend is checked
legendSymbolItems Returns a list of symbology items for the legend
legendSymbolItemsCheckable items of symbology items in legend should be 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.
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 store renderer info to XML element
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.
setUsingSymbolLevels
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
usedAttributes Returns a list of attributes required by this renderer.
usingSymbolLevels
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

Signals

Attributes

Filter
MoreSymbolsPerFeature
ScaleDependent
SymbolLevels
class Capabilities

Bases: sip.wrapper

QgsFeatureRenderer.Capabilities(Union[QgsFeatureRenderer.Capabilities, QgsFeatureRenderer.Capability]) QgsFeatureRenderer.Capabilities(QgsFeatureRenderer.Capabilities)

class Capability

Bases: int

Filter = 8
MoreSymbolsPerFeature = 4
ScaleDependent = 16
SymbolLevels = 1
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()
checkLegendSymbolItem(self, key: str, state: bool = True)

item in symbology was checked

New in version 2.5.

clone(self) → QgsFeatureRenderer

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

Returns:A copy of this renderer
convertSymbolRotation(symbol: QgsSymbol, field: str)

Note

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

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

Note

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

copyRendererData(self, destRenderer: QgsFeatureRenderer)

Clones generic renderer data to another renderer. Currently clones * Order By * Paint Effect

Parameters:destRenderer – destination renderer for copied effect
defaultRenderer(geomType: QgsWkbTypes.GeometryType) → QgsFeatureRenderer

Returns a new renderer - used by default in vector layers

dump(self) → str

Returns debug information about this renderer

embeddedRenderer(self) → QgsFeatureRenderer

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

New in version 2.16.

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.

Returns:An expression used as where clause
filterNeedsGeometry(self) → bool

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

forceRasterRender(self) → bool

Returns whether the renderer must render as a raster.

New in version 2.12.

legendClassificationAttribute(self) → str

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

New in version 2.6.

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

Returns legend keys matching a specified feature.

New in version 2.14.

legendSymbolItemChecked(self, key: str) → bool

items of symbology items in legend is checked

New in version 2.5.

legendSymbolItems(self) → object

Returns a list of symbology items for the legend

New in version 2.6.

legendSymbolItemsCheckable(self) → bool

items of symbology items in legend should be checkable

New in version 2.5.

load(symbologyElem: QDomElement, context: QgsReadWriteContext) → QgsFeatureRenderer

create a renderer from XML element

loadSld(node: QDomNode, geomType: QgsWkbTypes.GeometryType, errorMessage: str) → QgsFeatureRenderer

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

Parameters:
  • node – the node in the SLD document whose the UserStyle element is a child
  • geomType – the geometry type of the features, used to convert Symbolizer elements
  • errorMessage – it will contain the error message if something went wrong
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 – reference to request’s filter extent. Modify extent to change the extent of feature request
  • context – render context

New in version 2.7.

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()

New in version 2.14.

orderByEnabled(self) → bool

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

See also

orderBy()

New in version 2.14.

originalSymbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) → QgsSymbol

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.

New in version 2.12.

originalSymbolsForFeature(self, feature: QgsFeature, context: QgsRenderContext) → object

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

New in version 2.12.

paintEffect(self) → QgsPaintEffect

Returns the current paint effect for the renderer.

Returns:paint effect

See also

setPaintEffect()

New in version 2.9.

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 particula layer from symbols (in order to support symbol level rendering).

See also

startRender()

See also

stopRender()

renderFeatureWithSymbol(self, feature: QgsFeature, symbol: QgsSymbol, 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.

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

render editing vertex marker at specified point

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

render editing vertex marker for a polygon

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

render editing vertex marker for a polyline

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

store renderer info to XML element

setEmbeddedRenderer(self, subRenderer: QgsFeatureRenderer)

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 – the embedded renderer. Ownership will be transferred.

New in version 2.16.

setForceRasterRender(self, forceRaster: bool)

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

Parameters:forceRaster – 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.

New in version 2.12.

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

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

Parameters:
  • key – rule key for legend symbol
  • symbol – new symbol for legend item. Ownership is transferred to renderer.

New in version 2.14.

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

New in version 2.14.

setOrderByEnabled(self, enabled: bool)

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

Parameters:enabled – set to True to enable custom feature ordering

See also

setOrderBy()

See also

orderByEnabled()

New in version 2.14.

setPaintEffect(self, effect: QgsPaintEffect)

Sets the current paint effect for the renderer.

Parameters:effect – paint effect. Ownership is transferred to the renderer.

See also

paintEffect()

New in version 2.9.

setUsingSymbolLevels(self, usingSymbolLevels: bool)
setVertexMarkerAppearance(self, type: int, size: float)

Sets type and size of editing vertex markers for subsequent rendering

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 – Additional information passed to the renderer about the job which will be rendered
  • fields – 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()

symbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) → QgsSymbol

To be overridden

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

Parameters:
  • feature – feature
  • context – render context
Returns:

returns pointer to symbol or 0 if symbol was not found

New in version 2.12.

symbols(self, context: QgsRenderContext) → object

Returns list of symbols used by the renderer.

Parameters:context – render context

New in version 2.12.

symbolsForFeature(self, feature: QgsFeature, context: QgsRenderContext) → object

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

New in version 2.12.

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

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

type(self) → 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.

Returns:A set of attributes
usingSymbolLevels(self) → 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().

New in version 2.12.

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

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

New in version 2.8.