I want to add new rules for a layer. However when I add them previous one(s) are deleted. Here is my code:
layer = iface.activeLayer()
symbol = QgsSymbol.defaultSymbol(layer.geometryType())
renderer = QgsRuleBasedRenderer(symbol)
# get the root rule
root_rule = renderer.rootRule()
# create clone of the default rule
rule = root_rule.children()[0].clone()
# set the label, expression and color
rule.setLabel("Akarsu Kutlesi")
rule.setFilterExpression(""""Subbasin" IN (2,4,6)""")
rule.symbol().setColor(QColor("orange"))
# append the rule to the list of rules
root_rule.appendtChild(rule)
# apply the renderer
layer.setRenderer(renderer)
Here is existing rules of layer:
No comments:
Post a Comment