Skip to content

Instantly share code, notes, and snippets.

@pigreco
Created February 2, 2022 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pigreco/8db7551974fee667858e07deff1f629d to your computer and use it in GitHub Desktop.
Save pigreco/8db7551974fee667858e07deff1f629d to your computer and use it in GitHub Desktop.
# Korto19 2022
# Crea file CSV con i nomi dei Gruppi e delle espressioni
# lanciare nella console di Python di QGIS
from qgis.core import QgsExpression
import csv
#creo due dizionari
gruppi_funzioni = {}
gruppi = {}
#popolo il primo con le coppie funzione, gruppo
#ed il secondo con gruppo e contatore
for i in range(0, len(QgsExpression.Functions())):
gruppi[QgsExpression.Functions()[i].group()] = 1
gruppi_funzioni[QgsExpression.Functions()[i].name()] = QgsExpression.Functions()[i].group()
#uso il secondo gruppo per classificare il primo e conto
for key, value in gruppi_funzioni.items():
#print(key, ' : ', value)
gruppi[value] = gruppi[value] + 1
#riordino per gruppo
ordered = {k: v for k, v in sorted(gruppi_funzioni.items(), key=lambda item: item[1])}
#apro un file csv, directory da inserire!!
f = open('C:/gruppi_espressioni.csv', 'w', newline='')
writer = csv.writer(f)
data = ["Gruppo", "Espressione"]
writer.writerow(data)
for keys,values in ordered.items():
data = [values, keys]
writer.writerow(data)
#chiudo il file
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment