Class: QgsFeatureRenderer¶
- class qgis.core.QgsFeatureRenderer(type: str)¶
Bases:
sip.wrapper
Methods
Accepts the specified symbology
visitor
, causing it to visit all symbols associated with the renderer.Returns details about internals of this renderer.
item in symbology was checked
Create a deep copy of this renderer.
Clones generic renderer data to another renderer.
Returns a new renderer - used by default in vector layers
Returns debug information about this renderer
Returns the current embedded renderer (subrenderer) for this feature renderer.
If a renderer does not require all the features this method may be overridden and return an expression used as where clause.
Returns
True
if this renderer requires the geometry to apply the filter.Returns whether the renderer must render as a raster.
If supported by the renderer, return classification attribute for the use in legend
Returns legend keys matching a specified feature.
items of symbology items in legend is checked
Returns a list of symbology items for the legend
items of symbology items in legend should be checkable
create a renderer from XML element
Create a new renderer according to the information contained in the UserStyle element of a SLD style document
Allows for a renderer to modify the extent of a feature request prior to rendering
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 symbol for feature.
Equivalent of
originalSymbolsForFeature()
call extended to support renderers that may use more symbols per feature - similar tosymbolsForFeature()
Returns the current paint effect for the renderer.
Returns the symbology reference scale.
Render a feature using this renderer in the given context.
Render the
feature
with thesymbol
usingcontext
.render editing vertex marker at specified point
render editing vertex marker for a polygon
render editing vertex marker for a polyline
Stores renderer properties to an XML element.
Saves generic renderer data into the specified
element
.Sets an embedded renderer (subrenderer) for this feature renderer.
Sets whether the renderer should be rendered to a raster destination.
Sets the symbol to be used for a legend symbol item.
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
.- param usingSymbolLevels
Sets type and size of editing vertex markers for subsequent rendering
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.
To be overridden
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
- rtype
str
Returns a list of attributes required by this renderer.
Returns
True
if the renderer uses embedded symbols for features.- rtype
bool
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
Attributes
- class Capabilities¶
- class Capabilities(Union[QgsFeatureRenderer.Capabilities, QgsFeatureRenderer.Capability])
- class Capabilities(QgsFeatureRenderer.Capabilities)
Bases:
sip.wrapper
- class Capability¶
Bases:
int
- Filter = 8¶
- MoreSymbolsPerFeature = 4¶
- ScaleDependent = 16¶
- SymbolLevels = 1¶
- accept(self, visitor: QgsStyleEntityVisitorInterface) 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, orFalse
if visiting should be canceled.New in version 3.10.
- Parameters
visitor (QgsStyleEntityVisitorInterface) –
- 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
- checkLegendSymbolItem(self, key: str, state: bool = True)¶
item in symbology was checked
New in version 2.5.
- Parameters
key (str) –
state (bool = True) –
- clone(self) QgsFeatureRenderer ¶
Create a deep copy of this renderer. Should be implemented by all subclasses and generate a proper subclass.
- Return type
- 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
- Parameters
symbol (QgsSymbol) –
field (str) –
- convertSymbolSizeScale(symbol: QgsSymbol, method: Qgis.ScaleMethod, field: str)¶
Note
this function is used to convert old sizeScale expressions to symbol level DataDefined size
- Parameters
symbol (QgsSymbol) –
method (Qgis.ScaleMethod) –
field (str) –
- copyRendererData(self, destRenderer: QgsFeatureRenderer)¶
Clones generic renderer data to another renderer.
Currently clones
Order by
Paint effect
Reference scale
Symbol levels enabled/disabled
Force raster render enabled/disabled
- Parameters
destRenderer (QgsFeatureRenderer) – destination renderer for copied effect
New in version 3.22.
- defaultRenderer(geomType: QgsWkbTypes.GeometryType) QgsFeatureRenderer ¶
Returns a new renderer - used by default in vector layers
- Parameters
geomType (QgsWkbTypes.GeometryType) –
- Return type
- dump(self) str ¶
Returns debug information about this renderer
- Return type
str
- 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
.See also
New in version 2.16.
- Return type
- 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 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()) –
- 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.
See also
New in version 2.12.
- Return type
bool
- legendClassificationAttribute(self) str ¶
If supported by the renderer, return classification attribute for the use in legend
New in version 2.6.
- Return type
str
- legendKeysForFeature(self, feature: QgsFeature, context: QgsRenderContext) Set[str] ¶
Returns legend keys matching a specified feature.
New in version 2.14.
- Parameters
feature (QgsFeature) –
context (QgsRenderContext) –
- Return type
Set[str]
- legendSymbolItemChecked(self, key: str) bool ¶
items of symbology items in legend is checked
New in version 2.5.
- Parameters
key (str) –
- Return type
bool
- legendSymbolItems(self) List[QgsLegendSymbolItem] ¶
Returns a list of symbology items for the legend
New in version 2.6.
- Return type
List[QgsLegendSymbolItem]
- legendSymbolItemsCheckable(self) bool ¶
items of symbology items in legend should be checkable
New in version 2.5.
- Return type
bool
- load(symbologyElem: QDomElement, context: QgsReadWriteContext) QgsFeatureRenderer ¶
create a renderer from XML element
- Parameters
symbologyElem (QDomElement) –
context (QgsReadWriteContext) –
- Return type
- 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 (QDomNode) – the node in the SLD document whose the UserStyle element is a child
geomType (QgsWkbTypes.GeometryType) – the geometry type of the features, used to convert Symbolizer elements
errorMessage (str) – it will contain the error message if something went wrong
- Return type
- 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
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()
isFalse
See also
New in version 2.14.
- Return type
- orderByEnabled(self) bool ¶
Returns whether custom ordering will be applied before features are processed by this renderer.
See also
See also
New in version 2.14.
- Return type
bool
- 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.
- Parameters
feature (QgsFeature) –
context (QgsRenderContext) –
- Return type
- originalSymbolsForFeature(self, feature: QgsFeature, context: QgsRenderContext) List[QgsSymbol] ¶
Equivalent of
originalSymbolsForFeature()
call extended to support renderers that may use more symbols per feature - similar tosymbolsForFeature()
New in version 2.12.
- Parameters
feature (QgsFeature) –
context (QgsRenderContext) –
- Return type
List[QgsSymbol]
- paintEffect(self) QgsPaintEffect ¶
Returns the current paint effect for the renderer.
- Return type
- Returns
paint effect
See also
New in version 2.9.
- 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.
See also
New 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()
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, context: QgsRenderContext, layer: int, selected: bool, drawVertexMarker: bool)¶
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 (QgsSymbol) –
context (QgsRenderContext) –
layer (int) –
selected (bool) –
drawVertexMarker (bool) –
- renderVertexMarker(self, pt: Union[QPointF, QPoint], context: QgsRenderContext)¶
render editing vertex marker at specified point
- Parameters
pt (Union[QPointF) –
context (QgsRenderContext) –
- renderVertexMarkerPolygon(self, pts: QPolygonF, rings: Iterable[QPolygonF], context: QgsRenderContext)¶
render editing vertex marker for a polygon
- Parameters
pts (QPolygonF) –
rings (Iterable[QPolygonF]) –
context (QgsRenderContext) –
- renderVertexMarkerPolyline(self, pts: QPolygonF, context: QgsRenderContext)¶
render editing vertex marker for a polyline
- Parameters
pts (QPolygonF) –
context (QgsRenderContext) –
- 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
doc (QDomDocument) –
context (QgsReadWriteContext) –
- 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 DOMelement
.New in version 3.22.
- Parameters
doc (QDomDocument) –
element (QDomElement) –
context (QgsReadWriteContext) –
- 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 (QgsFeatureRenderer) – the embedded renderer. Ownership will be transferred.
See also
New in version 2.16.
- 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.
See also
New in version 2.12.
- setLegendSymbolItem(self, key: str, symbol: QgsSymbol)¶
Sets the symbol to be used for a legend symbol item.
- Parameters
key (str) – rule key for legend symbol
symbol (QgsSymbol) – 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()
isFalse
See also
New in version 2.14.
- 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
See also
New in version 2.14.
- setPaintEffect(self, effect: QgsPaintEffect)¶
Sets the current paint effect for the renderer.
- Parameters
effect (QgsPaintEffect) – paint effect. Ownership is transferred to the renderer.
See also
New in version 2.9.
- 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
New 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
type (Qgis.VertexMarkerType) –
size (float) –
- 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 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.
- 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 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) –
- symbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) QgsSymbol ¶
To be overridden
Must be called between
startRender()
andstopRender()
calls.- Parameters
feature (QgsFeature) – feature
context (QgsRenderContext) – render context
- Return type
- Returns
returns pointer to symbol or 0 if symbol was not found
New in version 2.12.
- symbols(self, context: QgsRenderContext) List[QgsSymbol] ¶
Returns list of symbols used by the renderer.
- Parameters
context (QgsRenderContext) – render context
New in version 2.12.
- 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()
New in version 2.12.
- Parameters
feature (QgsFeature) –
context (QgsRenderContext) –
- 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 returnsFalse
.New 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()
andstopRender()
calls. Default implementation usessymbolForFeature()
.New in version 2.12.
- Parameters
feature (QgsFeature) –
context (QgsRenderContext) –
- Return type
bool
- writeSld(self, doc: QDomDocument, styleName: str, props: Dict[str, Any] = {}) QDomElement ¶
create the SLD UserStyle element following the SLD v1.1 specs with the given name
New in version 2.8.
- Parameters
doc (QDomDocument) –
styleName (str) –
props (Dict[str) –
- Return type
QDomElement