Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kategorisierter Stil per PyQGIS: größtenteils basierend auf: https://gis.stackexchange.com/a/382742/67477
# Code für die QGIS Konsole:
styling_layer = iface.activeLayer() # Hinweis: im Plugin self.iface.activeLayer()
spalten_name = 'DRUCKSTUFE'
rampen_name = 'Greens'
field_index = styling_layer.fields().indexFromName(spalten_name)
unique_values = styling_layer.uniqueValues(field_index)
# Kategorien anhand der eindeutigen Werte erzeugen
category_list = []
for value in unique_values:
symbol = QgsSymbol.defaultSymbol(styling_layer.geometryType())
category = QgsRendererCategory(value, symbol, str(value))
category_list.append(category)
# Renderer erzeugen mit Kategorien
renderer = QgsCategorizedSymbolRenderer(spalten_name, category_list)
style = QgsStyle().defaultStyle()
ramp = style.colorRamp(rampen_name)
renderer.updateColorRamp(ramp)
styling_layer.setRenderer(renderer)
styling_layer.triggerRepaint()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment