Skip to content

Instantly share code, notes, and snippets.

@thbaumann
Created November 20, 2020 09:16
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 thbaumann/318f4771ef7030183de09200ef65f682 to your computer and use it in GitHub Desktop.
Save thbaumann/318f4771ef7030183de09200ef65f682 to your computer and use it in GitHub Desktop.
from qgis.core import *
from qgis.gui import *
@qgsfunction(args='auto', group='Custom')
def eindeutige_legende1( layername, feature, parent,context):
try:
project = QgsProject.instance()
ausgabe=None
legendenlayer = QgsExpressionContextUtils.projectScope(project).variable('eindeutig')
if legendenlayer is None:
legendenlayer=[]
if layername in legendenlayer:
print('false')
ausgabe=False
else:
ausgabe=True
print('true')
legendenlayer.append(layername)
QgsExpressionContextUtils.setProjectVariable(project,'eindeutig',legendenlayer)
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
return (ausgabe)
@thbaumann
Copy link
Author

Beim Atlas-Druck muss man noch die Projektvariable nach jeder Seite leeren.
Das geht wiederum über eine benutzerdefinierte Funktion, die man im Reiter "Atlas" z.B. bei "Seitenname" oder "Ausgabedateiausdruck" übergibt...

alles recht umständlich aber es geht. Beispielhaft umgesetzt am Layer Schnittgrenze:
grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment