Created
June 2, 2022 10:23
-
-
Save pigreco/a6c519073c30f3dc276489c4ff198728 to your computer and use it in GitHub Desktop.
Funzione personalizzata per il field calc, estrae i valori delle label dei simboli categorizzati
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qgis.core import * | |
from qgis.gui import * | |
from qgis.utils import iface | |
@qgsfunction(args='auto', group='Custom') | |
def get_catg_label(value_in, feature, parent): | |
""" | |
Restituisce il testo della legenda dell'elemento categorizzato: | |
<br> | |
<p><b>il campo in input e' quello utilizzato per la categorizzazione</b> | |
<br> | |
<h2>Example usage:</h2> | |
<ul> | |
<li>get_catg_label("Area") -> 'Parcheggio'</li> | |
</ul> | |
""" | |
layer = iface.activeLayer() | |
renderer = layer.renderer() | |
if layer.renderer().type() == "categorizedSymbol": | |
for cat in renderer.categories(): | |
#print('val ', type(cat.value()), type(value_in)) | |
if str(value_in) == str(cat.value()): | |
#print('res ',cat.value(), value_in) | |
cat_label_out = cat.label() | |
break | |
else: | |
cat_label_out = '' | |
return cat_label_out | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment