Subgroup: Rule
Class: QgsRuleBasedRenderer¶
-
class
qgis.core.
QgsRuleBasedRenderer
(root: QgsRuleBasedRenderer.Rule)¶ Bases:
qgis._core.QgsFeatureRenderer
Constructs the renderer from given tree of rules (takes ownership)
QgsRuleBasedRenderer(defaultSymbol: QgsSymbol) Constructor for convenience. Creates a root rule and adds a default rule with symbol (takes ownership)
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
dump
filter
filterNeedsGeometry
legendKeysForFeature
legendSymbolItemChecked
legendSymbolItems
legendSymbolItemsCheckable
originalSymbolsForFeature
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
setLegendSymbolItem
startRender
stopRender
symbolForFeature
return symbol for current feature. symbols
symbolsForFeature
toSld
usedAttributes
willRenderFeature
Signals
Attributes
FeatDrawMarkers
FeatIsSelected
-
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
(symbol: QgsSymbol, maximumScale: int = 0, minimumScale: int = 0, filterExp: str = '', label: str = '', description: str = '', elseRule: bool = False)¶ Bases:
sip.wrapper
Constructor takes ownership of the symbol
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¶
-