I have polygon layer containing overlapping features (service areas for several years) and I want their symbology to
- use a color ramp in QgsCategorizedSymbolRenderer applied for each year
- use a transparent fill and apply their former fill color to the outline.
For the first part I successfully use this code:
categories= for u in layer.uniqueValues(fieldIndex): symbol = QgsSymbol.defaultSymbol(layer.geometryType()) category = QgsRendererCategory(u, symbol, str(u)) categories.append(category) renderer = QgsCategorizedSymbolRenderer("year",categories) style = QgsStyle().defaultStyle() ramp = style.colorRamp('Greens') renderer.updateColorRamp(ramp) layer.setRenderer(renderer) layer.triggerRepaint()
How do I get each symbol's fill color after having applied the color ramp in order to make it the outline color for each symbol according to the ramp's gradient? Could there be a way to do so in the loop beforehand and then apply the ramp directly on the outlines?
Sidenote: I am really puzzled that using a feature's outline for symbology apparently requires some tinkering everytime...