I'm trying to programatically render bunch of vector lines that have an attribute 'route_id' which specifies which route they belong to, as well as an attribute 'ranking'. Some features overlap, and the 'ranking' attribute specifies the order in which they should be offset (ranking==1 -> offset by n * 1, ranking==2 -> offset by n * 2 etc.) so via rule-based symbology it should be possible to render them the way I need.
I'm however struggling to access the offset parameter via PyQGIS. As far as I can tell there are only methods for setting width and color.
layer = iface.activeLayer() symbol = QgsSymbol.defaultSymbol(layer.geometryType()) renderer = QgsRuleBasedRenderer(symbol) expression_1 = '"route_id" = \'109\' AND "ranking" = \'2\'' width = 0.86 def rule_based_style(layer, symbol, renderer, label, expression, color, width): root_rule = renderer.rootRule() rule = root_rule.children().clone() rule.setLabel(label) rule.setFilterExpression(expression) rule.symbol().setColor(QColor(color)) rule.symbol().setWidth(width) root_rule.appendChild(rule) layer.setRenderer(renderer) layer.triggerRepaint() iface.layerTreeView().refreshLayerSymbology(layer.id()) rule_based_style(layer, symbol, renderer, 'Rule_1', expression_1, 'red', width)
Is there any way I can specify the offset?