Class: QgsFeatureRenderer¶
Abstract base class for all 2D vector feature renderers.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: clone()
, symbolForFeature()
, usedAttributes()
Class Hierarchy¶
Subclasses¶
A vector renderer which represents 3D features in an isometric view. |
|
A feature renderer which represents features using a list of renderer categories. |
|
A vector feature renderer which uses embedded feature symbology to render per-feature symbols. |
|
A vector feature renderer which uses numeric attributes to classify features into different ranges. |
|
A renderer which draws points as a live heatmap. |
|
A polygon or line-only feature renderer used to render a set of features merged (or dissolved) into a single geometry. |
|
Null symbol renderer, which draws no symbols for features by default, but allows for labeling and diagrams for the layer. |
|
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers). |
|
Rule based renderer. |
|
A feature renderer which renders all features with the same symbol. |
Enums
Data definable properties for renderers. |
Abstract Methods
Create a deep copy of this renderer. |
|
To be overridden |
|
Returns a list of attributes required by this renderer. |
Methods
Clones generic renderer data to another renderer. |
|
Returns a reference to the renderer's property collection, used for data defined overrides. |
|
Returns the current embedded renderer (subrenderer) for this feature renderer. |
|
Returns whether the renderer must render as a raster. |
|
Returns the set of all legend keys used by the renderer. |
|
Returns the maximum extent buffer found in this renderer's symbols. |
|
Gets the order in which features shall be processed by this renderer. |
|
Returns whether custom ordering will be applied before features are processed by this renderer. |
|
Returns the current paint effect for the renderer. |
|
Returns the symbol property definitions. |
|
Returns the symbology reference scale. |
|
Render the feature with the symbol using context. |
|
render editing vertex marker at specified point |
|
render editing vertex marker for a polygon |
|
render editing vertex marker for a polyline |
|
Saves generic renderer data into the specified element. |
|
Sets the renderer's property collection, used for data defined overrides. |
|
Sets a data defined property for the renderer. |
|
Sets whether the renderer should be rendered to a raster destination. |
|
Define the order in which features shall be processed by this renderer. |
|
Sets whether custom ordering should be applied before features are processed by this renderer. |
|
Sets the current paint effect for the renderer. |
|
Sets the symbology reference scale. |
|
Sets type and size of editing vertex markers for subsequent rendering |
|
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsFeatureRenderer. See the FAQ for more details.
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer. |
|
Returns |
|
Returns details about internals of this renderer. |
|
Sets whether the legend symbology item with the specified ley should be checked. |
|
Returns a list of legend nodes to be used for the legend for the renderer. |
|
Returns debug information about this renderer |
|
If a renderer does not require all the features this method may be overridden and return an expression used as where clause. |
|
Returns |
|
Returns flags associated with the renderer. |
|
If supported by the renderer, return classification attribute for the use in legend |
|
Attempts to convert the specified legend rule key to a QGIS expression matching the features displayed using that key. |
|
Returns legend keys matching a specified feature. |
|
Returns |
|
Returns a list of symbology items for the legend |
|
Returns |
|
Allows for a renderer to modify the extent of a feature request prior to rendering |
|
Returns symbol for feature. |
|
Equivalent of |
|
Render a feature using this renderer in the given context. |
|
Stores renderer properties to an XML element. |
|
Sets an embedded renderer (subrenderer) for this feature renderer. |
|
Sets the symbol to be used for a legend symbol item. |
|
Must be called when a new render cycle is started. |
|
Must be called when a render cycle has finished, to allow the renderer to clean up. |
|
Returns list of symbols used by the renderer. |
|
Returns list of symbols used for rendering the feature. |
|
Used from subclasses to create SLD Rule elements following SLD v1.1 specs |
|
Returns |
|
Returns whether the renderer will render a feature or not. |
|
create the SLD UserStyle element following the SLD v1.1 specs with the given name |
Static Methods
Converts old rotation expressions to symbol level data defined angles. |
|
Converts old sizeScale expressions to symbol level data defined sizes. |
|
Returns a new renderer - used by default in vector layers |
|
create a renderer from XML element |
|
Create a new renderer according to the information contained in the UserStyle element of a SLD style document |
Attributes
- class qgis.core.QgsFeatureRenderer[source]¶
Bases:
object
- class Capabilities¶
- class Capabilities(f: QgsFeatureRenderer.Capabilities | QgsFeatureRenderer.Capability)
- class Capabilities(a0: QgsFeatureRenderer.Capabilities)
Bases:
object
- class Capability¶
Bases:
int
- Filter = 8¶
- MoreSymbolsPerFeature = 4¶
- class Property(*values)¶
Bases:
IntEnum
Data definable properties for renderers.
Added in version 3.38.
HeatmapRadius
: Heatmap renderer radiusHeatmapMaximum
: Heatmap maximum value
- HeatmapMaximum = 1¶
- HeatmapRadius = 0¶
- ScaleDependent = 16¶
- SymbolLevels = 1¶
- virtual accept(self, visitor: QgsStyleEntityVisitorInterface | None) bool [source]¶
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, orFalse
if visiting should be canceled.Added in version 3.10.
- Parameters:
visitor (Optional[QgsStyleEntityVisitorInterface])
- Return type:
bool
- virtual canSkipRender(self) bool [source]¶
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()
andstopRender()
calls.Added in version 3.30.
- Return type:
bool
- virtual capabilities(self) QgsFeatureRenderer.Capabilities [source]¶
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:
- virtual checkLegendSymbolItem(self, key: str | None, state: bool = True)[source]¶
Sets whether the legend symbology item with the specified
ley
should be checked.See also
See also
- Parameters:
key (Optional[str])
state (bool = True)
- abstract clone(self) QgsFeatureRenderer | None [source]¶
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
- static convertSymbolRotation(symbol: QgsSymbol | None, field: str | None)[source]¶
Converts old rotation expressions to symbol level data defined angles.
- Parameters:
symbol (Optional[QgsSymbol])
field (Optional[str])
- static convertSymbolSizeScale(symbol: QgsSymbol | None, method: Qgis.ScaleMethod, field: str | None)[source]¶
Converts old sizeScale expressions to symbol level data defined sizes.
- Parameters:
symbol (Optional[QgsSymbol])
method (Qgis.ScaleMethod)
field (Optional[str])
- copyRendererData(self, destRenderer: QgsFeatureRenderer | None)[source]¶
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.
- virtual 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()
See also
Added in version 3.38.
- Parameters:
nodeLayer (Optional[QgsLayerTreeLayer])
- Return type:
- dataDefinedProperties(self) QgsPropertyCollection ¶
Returns a reference to the renderer’s property collection, used for data defined overrides.
See also
See also
Property
Added in version 3.38.
- Return type:
- static defaultRenderer(geomType: Qgis.GeometryType) QgsFeatureRenderer | None [source]¶
Returns a new renderer - used by default in vector layers
- Parameters:
geomType (Qgis.GeometryType)
- Return type:
Optional[QgsFeatureRenderer]
- embeddedRenderer(self) QgsFeatureRenderer | None [source]¶
Returns the current embedded renderer (subrenderer) for this feature renderer. The base class implementation does not use subrenderers and will always return
None
.See also
- Return type:
Optional[QgsFeatureRenderer]
- virtual filter(self, fields: QgsFields = QgsFields()) str [source]¶
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 torenderFeature()
. 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())
- virtual filterNeedsGeometry(self) bool [source]¶
Returns
True
if this renderer requires the geometry to apply the filter.- Return type:
bool
- virtual flags(self) Qgis.FeatureRendererFlags [source]¶
Returns flags associated with the renderer.
Added in version 3.40.
- Return type:
- forceRasterRender(self) bool [source]¶
Returns whether the renderer must render as a raster.
See also
- Return type:
bool
- virtual legendClassificationAttribute(self) str [source]¶
If supported by the renderer, return classification attribute for the use in legend
- Return type:
str
- virtual legendKeyToExpression(self, key: str | None, layer: QgsVectorLayer | None)[source]¶
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:
True
if legend key was successfully converted to a filter expression
See also
Added in version 3.26.
- legendKeys(self) Set[str] ¶
Returns the set of all legend keys used by the renderer.
See also
Added in version 3.32.
- Return type:
Set[str]
- virtual legendKeysForFeature(self, feature: QgsFeature, context: QgsRenderContext) Set[str] ¶
Returns legend keys matching a specified feature.
- Parameters:
feature (QgsFeature)
context (QgsRenderContext)
- Return type:
Set[str]
- virtual legendSymbolItemChecked(self, key: str | None) bool [source]¶
Returns
True
if the legend symbology item with the specifiedkey
is checked.See also
See also
- Parameters:
key (Optional[str])
- Return type:
bool
- virtual legendSymbolItems(self) List[QgsLegendSymbolItem] [source]¶
Returns a list of symbology items for the legend
See also
See also
- Return type:
List[QgsLegendSymbolItem]
- virtual legendSymbolItemsCheckable(self) bool [source]¶
Returns
True
if symbology items in legend are checkable.- Return type:
bool
- static load(symbologyElem: QDomElement, context: QgsReadWriteContext) QgsFeatureRenderer | None [source]¶
create a renderer from XML element
- Parameters:
symbologyElem (QDomElement)
context (QgsReadWriteContext)
- Return type:
Optional[QgsFeatureRenderer]
- static loadSld(node: QDomNode, geomType: Qgis.GeometryType, errorMessage: str | None) QgsFeatureRenderer | None [source]¶
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
- maximumExtentBuffer(self, context: QgsRenderContext) float [source]¶
Returns the maximum extent buffer found in this renderer’s symbols.
Note
Returns 0 if the renderer doesn’t have any symbols.
Added in version 3.42.
- Parameters:
context (QgsRenderContext)
- Return type:
float
- virtual modifyRequestExtent(self, extent: QgsRectangle, context: QgsRenderContext)[source]¶
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 [source]¶
Gets the order in which features shall be processed by this renderer.
Note
this property has no effect if
orderByEnabled()
isFalse
See also
- Return type:
- orderByEnabled(self) bool [source]¶
Returns whether custom ordering will be applied before features are processed by this renderer.
See also
See also
- Return type:
bool
- virtual originalSymbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) QgsSymbol | None [source]¶
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:
feature (QgsFeature)
context (QgsRenderContext)
- Return type:
Optional[QgsSymbol]
- virtual originalSymbolsForFeature(self, feature: QgsFeature, context: QgsRenderContext) List[QgsSymbol] [source]¶
Equivalent of
originalSymbolsForFeature()
call extended to support renderers that may use more symbols per feature - similar tosymbolsForFeature()
- Parameters:
feature (QgsFeature)
context (QgsRenderContext)
- Return type:
List[QgsSymbol]
- paintEffect(self) QgsPaintEffect | None [source]¶
Returns the current paint effect for the renderer.
- Return type:
Optional[QgsPaintEffect]
- Returns:
paint effect
See also
- propertyDefinitions() Dict[int, QgsPropertyDefinition] ¶
Returns the symbol property definitions.
Added in version 3.18.
- Return type:
Dict[int, QgsPropertyDefinition]
- referenceScale(self) float [source]¶
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.
See also
Added in version 3.22.
- Return type:
float
- virtual renderFeature(self, feature: QgsFeature, context: QgsRenderContext, layer: int = -1, selected: bool = False, drawVertexMarker: bool = False) bool [source]¶
Render a feature using this renderer in the given context. Must be called between
startRender()
andstopRender()
calls. Default implementation renders a symbol as determined bysymbolForFeature()
call. ReturnsTrue
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
See also
- Parameters:
feature (QgsFeature)
context (QgsRenderContext)
layer (int = -1)
selected (bool = False)
drawVertexMarker (bool = False)
- Return type:
bool
- renderFeatureWithSymbol(self, feature: QgsFeature, symbol: QgsSymbol | None, context: QgsRenderContext, layer: int, selected: bool, drawVertexMarker: bool)[source]¶
Render the
feature
with thesymbol
usingcontext
. Uselayer
to specify the symbol layer,selected
to specify if it should be rendered as selected anddrawVertexMarker
to specify if vertex markers should be rendered.- Parameters:
feature (QgsFeature)
symbol (Optional[QgsSymbol])
context (QgsRenderContext)
layer (int)
selected (bool)
drawVertexMarker (bool)
- renderVertexMarker(self, pt: QPointF | QPoint, context: QgsRenderContext)[source]¶
render editing vertex marker at specified point
- Parameters:
pt (Union[QPointF, QPoint])
context (QgsRenderContext)
- renderVertexMarkerPolygon(self, pts: QPolygonF, rings: Iterable[QPolygonF] | None, context: QgsRenderContext)[source]¶
render editing vertex marker for a polygon
- Parameters:
pts (QPolygonF)
rings (Optional[Iterable[QPolygonF]])
context (QgsRenderContext)
- renderVertexMarkerPolyline(self, pts: QPolygonF, context: QgsRenderContext)[source]¶
render editing vertex marker for a polyline
- Parameters:
pts (QPolygonF)
context (QgsRenderContext)
- virtual save(self, doc: QDomDocument, context: QgsReadWriteContext) QDomElement [source]¶
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:
doc (QDomDocument)
context (QgsReadWriteContext)
- Return type:
QDomElement
- saveRendererData(self, doc: QDomDocument, element: QDomElement, context: QgsReadWriteContext)[source]¶
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 DOMelement
.Added in version 3.22.
- Parameters:
doc (QDomDocument)
element (QDomElement)
context (QgsReadWriteContext)
- setDataDefinedProperties(self, collection: QgsPropertyCollection)[source]¶
Sets the renderer’s property collection, used for data defined overrides.
- Parameters:
collection (QgsPropertyCollection) – property collection. Existing properties will be replaced.
See also
Added in version 3.38.
- setDataDefinedProperty(self, key: QgsFeatureRenderer.Property, property: QgsProperty)[source]¶
Sets a data defined property for the renderer. Any existing property with the same key will be overwritten.
See also
See also
Property
Added in version 3.38.
- Parameters:
property (QgsProperty)
- virtual setEmbeddedRenderer(self, subRenderer: QgsFeatureRenderer | None)[source]¶
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.
See also
- setForceRasterRender(self, forceRaster: bool)[source]¶
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.
See also
- virtual setLegendSymbolItem(self, key: str | None, symbol: QgsSymbol | None)[source]¶
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
- setOrderBy(self, orderBy: QgsFeatureRequest.OrderBy)[source]¶
Define the order in which features shall be processed by this renderer.
Note
this property has no effect if
orderByEnabled()
isFalse
See also
- Parameters:
orderBy (QgsFeatureRequest.OrderBy)
- setOrderByEnabled(self, enabled: bool)[source]¶
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
See also
- setPaintEffect(self, effect: QgsPaintEffect | None)[source]¶
Sets the current paint effect for the renderer.
- Parameters:
effect (Optional[QgsPaintEffect]) – paint effect. Ownership is transferred to the renderer.
See also
- setReferenceScale(self, scale: float)[source]¶
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
Added in version 3.22.
- Parameters:
scale (float)
- setVertexMarkerAppearance(self, type: Qgis.VertexMarkerType, size: float)[source]¶
Sets type and size of editing vertex markers for subsequent rendering
- Parameters:
type (Qgis.VertexMarkerType)
size (float)
- virtual startRender(self, context: QgsRenderContext, fields: QgsFields)[source]¶
Must be called when a new render cycle is started. A call to
startRender()
must always be followed by a corresponding call tostopRender()
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
Warning
This method is not thread safe. Before calling
startRender()
in a non-main thread, the renderer should instead be cloned andstartRender()
/stopRender()
called on the clone.
- virtual stopRender(self, context: QgsRenderContext)[source]¶
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 tostartRender()
.Warning
This method is not thread safe. Before calling
startRender()
in a non-main thread, the renderer should instead be cloned andstartRender()
/stopRender()
called on the clone.See also
- Parameters:
context (QgsRenderContext)
- abstract symbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) QgsSymbol | None [source]¶
To be overridden
Must be called between
startRender()
andstopRender()
calls.- Parameters:
feature (QgsFeature) – feature
context (QgsRenderContext) – render context
- Return type:
Optional[QgsSymbol]
- Returns:
returns pointer to symbol or 0 if symbol was not found
- virtual symbols(self, context: QgsRenderContext) List[QgsSymbol] [source]¶
Returns list of symbols used by the renderer.
- Parameters:
context (QgsRenderContext) – render context
- Return type:
List[QgsSymbol]
- virtual symbolsForFeature(self, feature: QgsFeature, context: QgsRenderContext) List[QgsSymbol] [source]¶
Returns list of symbols used for rendering the feature. For renderers that do not support MoreSymbolsPerFeature it is more efficient to use
symbolForFeature()
- Parameters:
feature (QgsFeature)
context (QgsRenderContext)
- Return type:
List[QgsSymbol]
- virtual toSld(self, doc: QDomDocument, element: QDomElement, props: Dict[str, Any] = {})[source]¶
Used from subclasses to create SLD Rule elements following SLD v1.1 specs
Deprecated since version 3.44: Use the version with
QgsSldExportContext
instead.- Parameters:
doc (QDomDocument)
element (QDomElement)
props (Dict[str, Any] = {})
- virtual toSld(self, doc: QDomDocument, element: QDomElement, context: QgsSldExportContext) bool [source]
Exports the renderer to SLD Rule elements following the SLD v1.1 specs.
Returns
True
if the renderer was exported to SLD successfully.Added in version 3.44.
- Parameters:
doc (QDomDocument)
element (QDomElement)
context (
QgsSldExportContext
)
- Return type:
bool
- abstract 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)
- virtual usesEmbeddedSymbols(self) bool [source]¶
Returns
True
if the renderer uses embedded symbols for features. The default implementation returnsFalse
.Added in version 3.20.
- Return type:
bool
- virtual willRenderFeature(self, feature: QgsFeature, context: QgsRenderContext) bool [source]¶
Returns whether the renderer will render a feature or not. Must be called between
startRender()
andstopRender()
calls. Default implementation usessymbolForFeature()
.- Parameters:
feature (QgsFeature)
context (QgsRenderContext)
- Return type:
bool
- virtual writeSld(self, doc: QDomDocument, styleName: str | None, props: Dict[str, Any] = {}) QDomElement [source]¶
create the SLD UserStyle element following the SLD v1.1 specs with the given name
- Parameters:
doc (QDomDocument)
styleName (Optional[str])
props (Dict[str, Any] = {})
- Return type:
QDomElement