In a vector layer is it possible to tune up/scripting the style columns attributes to map "Label" column to a specific attribute field/column instead of being populated with same content as the "Value" column? I'm working on QGIS 2.14.
We have symbology by categories and symbols in a XML created based on a key field ("ID_UCF" [type integer]) which is used to classify the style attributes – match to symbols from file – but this way we have the legend of the map taking the "ID_UCF" codes as symbol labels and we need those labels as a description of those codes. This description/text is given by a column present in the attribute table of the label ("DSCR_UCF" [type text]).
How can we change the content of style column "Label" – in this case "Legend" to assume the descriptions?
We have been looking at qgis.core such as rendererV2 class but could not find how to deal with the issue.
Best Answer
Hoping I have understood well your issue, you may set the text from a specified field as Legend by directly creating the categorized style.
Assuming to start from this self-explanatory Attribute Table:
you may assign the
"DSCR_UCF"
field as Legend for the"ID_UCF"
values using the following code from the Python Console:You will get this result:
EDIT
If you want to keep the original colors unchanged, you may run the following code (assuming you previously assigned a custom categorized renderer with custom colors):