Subgroup: Rule
Class: QgsRuleBasedRenderer¶
-
class
qgis.core.
QgsRuleBasedRenderer
¶ Bases:
qgis._core.QgsFeatureRenderer
When drawing a vector layer with rule-based renderer, it goes through the rules and draws features with symbols from rules that match.
Methods
capabilities
checkLegendSymbolItem
clone
convertFromRenderer
creates a QgsRuleBasedRenderer from an existing renderer. convertSymbolRotation
convertSymbolSizeScale
convertToDataDefinedSymbology
helper function to convert the size scale and rotation fields present in some other renderers to data defined symbology copyRendererData
create
Creates a new rule-based renderer instance from XML createFromSld
defaultRenderer
return a new renderer - used by default in vector layers dump
embeddedRenderer
Returns the current embedded renderer (subrenderer) for this feature renderer. filter
filterNeedsGeometry
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
legendSymbolItemChecked
legendSymbolItems
legendSymbolItemsCheckable
load
create a renderer from XML element loadSld
Create a new renderer according to the information contained in modifyRequestExtent
Allows for a renderer to modify the extent of a feature request prior to rendering orderBy
Get 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
Return symbol for feature. originalSymbolsForFeature
paintEffect
Returns the current paint effect for the renderer. refineRuleCategories
take a rule and create a list of new rules based on the categories from categorized symbol renderer refineRuleRanges
take a rule and create a list of new rules based on the ranges from graduated symbol renderer refineRuleScales
take a rule and create a list of new rules with intervals of scales given by the passed scale denominators renderFeature
renderFeatureWithSymbol
renderVertexMarker
renderVertexMarkerPolygon
renderVertexMarkerPolyline
rootRule
save
setEmbeddedRenderer
Sets an embedded renderer (subrenderer) for this feature renderer. setForceRasterRender
Sets whether the renderer should be rendered to a raster destination. setLegendSymbolItem
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
set type and size of editing vertex markers for subsequent rendering startRender
stopRender
symbolForFeature
return symbol for current feature. Should not be used individually: there could be more symbols for a feature symbols
symbolsForFeature
toSld
type
usedAttributes
usingSymbolLevels
willRenderFeature
writeSld
create the SLD UserStyle element following the SLD v1.1 specs with the given name Attributes
FeatDrawMarkers
FeatIsSelected
Filter
MoreSymbolsPerFeature
ScaleDependent
SymbolLevels
-
FeatDrawMarkers
= 2¶
-
FeatIsSelected
= 1¶
-
class
FeatureFlags
¶ Bases:
int
-
class
FeatureToRender
(_f: QgsFeature, _flags: int)¶ Bases:
sip.wrapper
QgsRuleBasedRenderer.FeatureToRender(QgsRuleBasedRenderer.FeatureToRender)
-
feat
¶
-
flags
¶
-
-
class
RenderJob
(_ftr: QgsRuleBasedRenderer.FeatureToRender, _s: QgsSymbol)¶ Bases:
sip.wrapper
QgsRuleBasedRenderer.RenderJob(QgsRuleBasedRenderer.RenderJob)
-
ftr
¶
-
symbol
¶
-
-
class
RenderLevel
(z: int)¶ Bases:
sip.wrapper
QgsRuleBasedRenderer.RenderLevel(other: QgsRuleBasedRenderer.RenderLevel)
-
jobs
¶
-
zIndex
¶
-
-
class
Rule
¶ Bases:
sip.wrapper
This class keeps data about a rules for rule-based renderer. A rule consists of a symbol, filter expression and range of scales. If filter is empty, it matches all features. If scale range has both values zero, it matches all scales. If one of the min/max scale denominators is zero, there is no lower/upper bound for scales. A rule matches if both filter and scale range match.
-
Filtered
= 0¶
-
Inactive
= 1¶
-
class
RenderResult
¶ Bases:
int
-
Rendered
= 2¶
-
active
(self) → bool¶ Returns if this rule is active
Returns: True if the rule is active
-
appendChild
(self, rule: QgsRuleBasedRenderer.Rule)¶ add child rule, take ownership, sets this as parent
-
children
(self) → object¶ Return all children rules of this rule
Returns: A list of rules
-
clone
(self) → QgsRuleBasedRenderer.Rule¶ clone this rule, return new instance
-
collectZLevels
(self) → object¶ get all used z-levels from this rule and children
-
create
(ruleElem: QDomElement, symbolMap: object) → QgsRuleBasedRenderer.Rule¶ Create a rule from an XML definition
Parameters: - ruleElem – The XML rule element
- symbolMap – Symbol map
Returns: A new rule
-
createFromSld
(element: QDomElement, geomType: QgsWkbTypes.GeometryType) → QgsRuleBasedRenderer.Rule¶ Create a rule from the SLD provided in element and for the specified geometry type.
-
dependsOnScale
(self) → bool¶
-
descendants
(self) → object¶ Returns all children, grand-children, grand-grand-children, grand-gra… you get it
Returns: A list of descendant rules
-
description
(self) → str¶ A human readable description for this rule
Returns: Description
-
dump
(self, indent: int = 0) → str¶ Dump for debug purpose
Parameters: indent – How many characters to indent. Will increase by two with every of the recursive calls Returns: A string representing this rule
-
filter
(self) → QgsExpression¶ A filter that will check if this rule applies
Returns: An expression
-
filterExpression
(self) → str¶ A filter that will check if this rule applies
Returns: An expression
-
findRuleByKey
(self, key: str) → QgsRuleBasedRenderer.Rule¶ Try to find a rule given its unique key
New in version 2.6.
-
initFilter
(self)¶
-
insertChild
(self, i: int, rule: QgsRuleBasedRenderer.Rule)¶ add child rule, take ownership, sets this as parent
-
isElse
(self) → bool¶ Check if this rule is an ELSE rule
Returns: True if this rule is an else rule
-
isFilterOK
(self, f: QgsFeature, context: QgsRenderContext = None) → bool¶ Check if a given feature shall be rendered by this rule
Parameters: - f – The feature to test
- context – The context in which the rendering happens
Returns: True if the feature shall be rendered
-
isScaleOK
(self, scale: float) → bool¶ Check if this rule applies for a given
scale
. Thescale
value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. If set to 0, it will always return true.Returns: If the rule will be evaluated at this scale
-
label
(self) → str¶
-
legendKeysForFeature
(self, feat: QgsFeature, context: QgsRenderContext = None) → Set[str]¶ Returns which legend keys match the feature
New in version 2.14.
-
legendSymbolItems
(self, currentLevel: int = -1) → object¶ New in version 2.6.
-
maximumScale
(self) → float¶ Returns the maximum map scale (i.e. most “zoomed in” scale) at which the rule will be active. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no maximum scale visibility.
See also
See also
New in version 3.0.
-
minimumScale
(self) → float¶ Returns the minimum map scale (i.e. most “zoomed out” scale) at which the rule will be active. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no minimum scale visibility.
See also
See also
New in version 3.0.
-
needsGeometry
(self) → bool¶ Returns true if this rule or one of its chilren needs the geometry to be applied.
-
parent
(self) → QgsRuleBasedRenderer.Rule¶ The parent rule
Returns: Parent rule
-
removeChild
(self, rule: QgsRuleBasedRenderer.Rule)¶ delete child rule
-
removeChildAt
(self, i: int)¶ delete child rule
-
renderFeature
(self, featToRender: QgsRuleBasedRenderer.FeatureToRender, context: QgsRenderContext, renderQueue: object) → QgsRuleBasedRenderer.Rule.RenderResult¶ Render a given feature, will recursively call subclasses and only render if the constraints apply.
Parameters: - featToRender – The feature to render
- context – The rendering context
- renderQueue – The rendering queue to which the feature should be added
Returns: The result of the rendering. In explicit if the feature is added to the queue or
the reason for not rendering the feature.
-
ruleKey
(self) → str¶ Unique rule identifier (for identification of rule within renderer)
New in version 2.6.
-
rulesForFeature
(self, feat: QgsFeature, context: QgsRenderContext = None) → object¶ tell which rules will be used to render the feature
-
save
(self, doc: QDomDocument, symbolMap: object) → QDomElement¶
-
setActive
(self, state: bool)¶ Sets if this rule is active
Parameters: state – Determines if the rule should be activated or deactivated
-
setDescription
(self, description: str)¶ Set a human readable description for this rule
Parameters: description – Description
-
setFilterExpression
(self, filterExp: str)¶ Set the expression used to check if a given feature shall be rendered with this rule
Parameters: filterExp – An expression
-
setIsElse
(self, iselse: bool)¶ Sets if this rule is an ELSE rule
Parameters: iselse – If true, this rule is an ELSE rule
-
setLabel
(self, label: str)¶
-
setMaximumScale
(self, scale: float)¶ Sets the maximum map
scale
(i.e. most “zoomed in” scale) at which the rule will be active. Thescale
value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. Ascale
of 0 indicates no maximum scale visibility.See also
See also
-
setMinimumScale
(self, scale: float)¶ Sets the minimum map
scale
(i.e. most “zoomed out” scale) at which the rule will be active. Thescale
value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. Ascale
of 0 indicates no minimum scale visibility.See also
See also
-
setRuleKey
(self, key: str)¶ Override the assigned rule key (should be used just internally by rule-based renderer)
New in version 2.6.
-
setSymbol
(self, sym: QgsSymbol)¶ set a new symbol (or NULL). Deletes old symbol.
-
startRender
(self, context: QgsRenderContext, fields: QgsFields, filter: str) → bool¶ prepare the rule for rendering and its children (build active children array)
-
stopRender
(self, context: QgsRenderContext)¶ Stop a rendering process. Used to clean up the internal state of this rule
Parameters: context – The rendering context
-
symbol
(self) → QgsSymbol¶
-
symbols
(self, context: QgsRenderContext = QgsRenderContext()) → object¶ Note
available in Python bindings as symbol2
-
symbolsForFeature
(self, feat: QgsFeature, context: QgsRenderContext = None) → object¶ tell which symbols will be used to render the feature
-
takeChild
(self, rule: QgsRuleBasedRenderer.Rule) → QgsRuleBasedRenderer.Rule¶ take child rule out, set parent as null
-
takeChildAt
(self, i: int) → QgsRuleBasedRenderer.Rule¶ take child rule out, set parent as null
-
toSld
(self, doc: QDomDocument, element: QDomElement, props: Dict[str, str])¶
-
usedAttributes
(self, context: QgsRenderContext) → Set[str]¶ Return the attributes used to evaluate the expression of this rule
Returns: A set of attribute names
-
willRenderFeature
(self, feat: QgsFeature, context: QgsRenderContext = None) → bool¶ only tell whether a feature will be rendered without actually rendering it
-
-
capabilities
(self) → QgsFeatureRenderer.Capabilities¶
-
checkLegendSymbolItem
(self, key: str, state: bool = True)¶
-
clone
(self) → QgsRuleBasedRenderer¶
-
convertFromRenderer
(renderer: QgsFeatureRenderer) → QgsRuleBasedRenderer¶ creates a QgsRuleBasedRenderer from an existing renderer.
Returns: a new renderer if the conversion was possible, otherwise 0. New in version 2.5.
-
convertSymbolRotation
()¶
-
convertSymbolSizeScale
()¶
-
convertToDataDefinedSymbology
(symbol: QgsSymbol, sizeScaleField: str, rotationField: str = '')¶ helper function to convert the size scale and rotation fields present in some other renderers to data defined symbology
-
copyRendererData
()¶
-
create
(element: QDomElement, context: QgsReadWriteContext) → QgsFeatureRenderer¶ Creates a new rule-based renderer instance from XML
-
createFromSld
(element: QDomElement, geomType: QgsWkbTypes.GeometryType) → QgsFeatureRenderer¶
-
dump
(self) → str¶
-
filter
(self, fields: QgsFields = QgsFields()) → str¶
-
filterNeedsGeometry
(self) → bool¶
-
legendKeysForFeature
(self, feature: QgsFeature, context: QgsRenderContext) → Set[str]¶
-
legendSymbolItemChecked
(self, key: str) → bool¶
-
legendSymbolItems
(self) → object¶
-
legendSymbolItemsCheckable
(self) → bool¶
-
originalSymbolsForFeature
(self, feat: QgsFeature, context: QgsRenderContext) → object¶
-
refineRuleCategories
(initialRule: QgsRuleBasedRenderer.Rule, r: QgsCategorizedSymbolRenderer)¶ take a rule and create a list of new rules based on the categories from categorized symbol renderer
-
refineRuleRanges
(initialRule: QgsRuleBasedRenderer.Rule, r: QgsGraduatedSymbolRenderer)¶ take a rule and create a list of new rules based on the ranges from graduated symbol renderer
-
refineRuleScales
(initialRule: QgsRuleBasedRenderer.Rule, scales: Iterable[int])¶ take a rule and create a list of new rules with intervals of scales given by the passed scale denominators
-
renderFeature
(self, feature: QgsFeature, context: QgsRenderContext, layer: int = -1, selected: bool = False, drawVertexMarker: bool = False) → bool¶
-
renderFeatureWithSymbol
()¶
-
renderVertexMarker
()¶
-
renderVertexMarkerPolygon
()¶
-
renderVertexMarkerPolyline
()¶
-
rootRule
(self) → QgsRuleBasedRenderer.Rule¶
-
save
(self, doc: QDomDocument, context: QgsReadWriteContext) → QDomElement¶
-
setLegendSymbolItem
(self, key: str, symbol: QgsSymbol)¶
-
startRender
(self, context: QgsRenderContext, fields: QgsFields)¶
-
stopRender
(self, context: QgsRenderContext)¶
-
symbolForFeature
(self, feature: QgsFeature, context: QgsRenderContext) → QgsSymbol¶ return symbol for current feature. Should not be used individually: there could be more symbols for a feature
-
symbols
(self, context: QgsRenderContext) → object¶
-
symbolsForFeature
(self, feat: QgsFeature, context: QgsRenderContext) → object¶
-
toSld
(self, doc: QDomDocument, element: QDomElement, props: Dict[str, str] = {})¶
-
usedAttributes
(self, context: QgsRenderContext) → Set[str]¶
-
willRenderFeature
(self, feat: QgsFeature, context: QgsRenderContext) → bool¶
-