Class: QgsRuleBasedLabeling¶
Rule based labeling for a vector layer.
Class Hierarchy¶
Base classes¶
Abstract base class - its implementations define different approaches to the labeling of a vector layer.  | 
Methods
Static Methods
Create the instance from a DOM element with saved configuration  | 
- class qgis.core.QgsRuleBasedLabeling[source]¶
 Bases:
QgsAbstractVectorLayerLabeling- __init__(root: QgsRuleBasedLabeling.Rule | None)
 Constructs the labeling from given tree of rules (takes ownership)
- Parameters:
 root (Optional[QgsRuleBasedLabeling.Rule])
- class Rule[source]¶
 Bases:
objectA child rule for QgsRuleBasedLabeling.
QgsRuleBasedLabeling.Rule(settings: Optional[QgsPalLayerSettings], maximumScale: float = 0, minimumScale: float = 0, filterExp: Optional[str] = ‘’, description: Optional[str] = ‘’, elseRule: bool = False) takes ownership of settings, settings may be
None- Filtered = 0¶
 
- Inactive = 1¶
 
- class RegisterResult¶
 Bases:
int
- Registered = 2¶
 
- active(self) bool[source]¶
 Returns if this rule is active
- Return type:
 bool
- Returns:
 Trueif the rule is active
- appendChild(self, rule: QgsRuleBasedLabeling.Rule | None)[source]¶
 add child rule, take ownership, sets this as parent
- Parameters:
 rule (Optional[QgsRuleBasedLabeling.Rule])
- children(self) List[QgsRuleBasedLabeling.Rule]¶
 Returns all children rules of this rule
- Return type:
 - Returns:
 A list of rules
- static create(ruleElem: QDomElement, context: QgsReadWriteContext, reuseId: bool = True) QgsRuleBasedLabeling.Rule | None[source]¶
 Create a rule from an XML definition
- Parameters:
 ruleElem (QDomElement) – The XML rule element
context (QgsReadWriteContext) – reading context
reuseId (bool = True) – set to
Trueto create an exact copy of the original symbol orFalseto create a new rule with the same parameters as the original but a new uniqueruleKey(). (Since QGIS 3.30)
- Return type:
 Optional[QgsRuleBasedLabeling.Rule]
- Returns:
 A new rule
- dependsOnScale(self) bool[source]¶
 Determines if scale based labeling is active
- Return type:
 bool
- Returns:
 Trueif scale based labeling is active
- descendants(self) List[QgsRuleBasedLabeling.Rule][source]¶
 Returns all children, grand-children, grand-grand-children, grand-gra… you get it
- Return type:
 - Returns:
 A list of descendant rules
- description(self) str[source]¶
 A human readable description for this rule
- Return type:
 str
- Returns:
 Description
- filterExpression(self) str[source]¶
 A filter that will check if this rule applies
- Return type:
 str
- Returns:
 An expression
- findRuleByKey(self, key: str | None) QgsRuleBasedLabeling.Rule | None[source]¶
 Try to find a rule given its unique key
- Parameters:
 key (Optional[str])
- Return type:
 Optional[QgsRuleBasedLabeling.Rule]
- insertChild(self, i: int, rule: QgsRuleBasedLabeling.Rule | None)[source]¶
 add child rule, take ownership, sets this as parent
- Parameters:
 i (int)
rule (Optional[QgsRuleBasedLabeling.Rule])
- isElse(self) bool[source]¶
 Check if this rule is an ELSE rule
- Return type:
 bool
- Returns:
 Trueif this rule is an else rule
- maximumScale(self) float[source]¶
 Returns the maximum map scale (i.e. most “zoomed in” scale) at which the label 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
- Return type:
 float
- minimumScale(self) float[source]¶
 Returns the minimum map scale (i.e. most “zoomed out” scale) at which the label 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
- Return type:
 float
- parent(self) QgsRuleBasedLabeling.Rule | None[source]¶
 The parent rule
- Return type:
 Optional[QgsRuleBasedLabeling.Rule]
- Returns:
 Parent rule
- ruleKey(self) str[source]¶
 Unique rule identifier (for identification of rule within labeling, used as provider ID)
- Return type:
 str
- setActive(self, state: bool)[source]¶
 Sets if this rule is active
- Parameters:
 state (bool) – Determines if the rule should be activated or deactivated
- setDescription(self, description: str | None)[source]¶
 Set a human readable description for this rule
- Parameters:
 description (Optional[str]) – Description
- setFilterExpression(self, filterExp: str | None)[source]¶
 Set the expression used to check if a given feature shall be rendered with this rule
- Parameters:
 filterExp (Optional[str]) – An expression
- setIsElse(self, iselse: bool)[source]¶
 Sets if this rule is an ELSE rule
- Parameters:
 iselse (bool) – If
True, this rule is an ELSE rule
- setMaximumScale(self, scale: float)[source]¶
 Sets the maximum map
scale(i.e. most “zoomed in” scale) at which the rule will be active. Thescalevalue indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. Ascaleof 0 indicates no maximum scale visibility.See also
See also
- Parameters:
 scale (float)
- setMinimumScale(self, scale: float)[source]¶
 Sets the minimum map
scale(i.e. most “zoomed out” scale) at which the label rule will be active. Thescalevalue indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. Ascaleof 0 indicates no minimum scale visibility.See also
See also
- Parameters:
 scale (float)
- static create(element: QDomElement, context: QgsReadWriteContext) QgsRuleBasedLabeling | None[source]¶
 Create the instance from a DOM element with saved configuration
- Parameters:
 element (QDomElement)
context (QgsReadWriteContext)
- Return type:
 Optional[QgsRuleBasedLabeling]
- rootRule(self) QgsRuleBasedLabeling.Rule | None[source]¶
 - Return type:
 Optional[QgsRuleBasedLabeling.Rule]