Getting currentfeature's color in Expression Builder of QGIS?
In QGIS >= 2.14 you can use the symbol_color variable. Eg, set a data defined override for your label color to the expression @symbol_color
Can it be done. Of couse with QGIS the answer is normally yes.
Lets take our vector layer with some normal labels and symbols:
Now add a data defined color for the buffer:
Click on Edit and select the function editor.
Click new file and give it a name (called mine colorfuncs)
Paste the following code
from qgis.core import *
from qgis.gui import *
@qgsfunction(args='auto', group='Custom')
def symbol_color(layername, feature, parent):
layer = QgsMapLayerRegistry.instance().mapLayersByName(layername)[0]
r = layer.rendererV2()
symbol = r.symbolForFeature(feature)
values = symbol.color().getRgb()
return "{}, {}, {}, {}".format(*values)
Should look like this:
Hit Run Script
Jump back over to the expressions tab and use the new function:
symbol_color('Pits')
We have to give it the name because expressions don't know about the layer only the feature.
Hit OK and Apply. BAM!
hmm almost. We just have to tweak the transparecny of the buffer:
BAM!