I am trying to colorize all features in all layers in my QGIS 2.8.2-Document based on a color-value, that is being determined for every Feature individually. I do have a QtGui.QColor instance for every feature, but I still need to apply it to the Feature via a Renderer.
from PyQt4 import QtGui, QtCore canvas = qgis.utils.iface.mapCanvas() layers = canvas.layers() for layer in layers: iter = layer.getFeatures() for feature in iter: if feature['ELEM_NR'] != '' and feature['ELEM_NR'] != NULL: # color = QtGui.QColor() # ... # hexValue is being determined based on feature['ELEM_NR'] # ... color = QtGui.QColor(hexValue ) # how can I apply color to feature`?
Background (why I do not simply use graduated symbols):
Every Layer has an attribute that is kind of an id. I want that every Feature (no matter which layer it is in), that has the same attribute-value, is colored the same way.
Because the the number of features differs between layers and the value range of the attribute is quit big, neither the catgorized nor the graduatedSymbol-Renderer descibed here would bring the desired result (at least in my understanding).
Using a custom renderer as described in the documentation looks promising, but I can't figure how to include this.