Skip to main content
Tweeted twitter.com/StackGIS/status/1341986985217568768
Became Hot Network Question
edited tags; edited title
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Is there a way to automate Automating classification of symbology in PyQGIS?

edited body; edited title
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

Is there a way to automate classification of symbology in pyqgisPyQGIS?

I have created this code to categorize my layer symbology based on the attribute "plant_allo"plant_allo. However I still have to press the classify button which I also want to automate in pyqgisPyQGIS. Can anyone help me with this last step?

enter image description here

Here is my code:

year = 2030
allocated_regions = QgsVectorLayer(output_folder + "regions_w_plant_alloc_" + str(year) + ".shp", "allocated_regions_" + str(year), "ogr")
QgsProject.instance().addMapLayer(allocated_regions)

# Field name
expression = 'plant_allo'
# Set the categorized renderer
renderer = QgsCategorizedSymbolRenderer(expression)
allocated_regions.setRenderer(renderer)
allocated_regions.triggerRepaint()

Is there a way to automate classification of symbology in pyqgis?

I have created this code to categorize my layer symbology based on the attribute "plant_allo". However I still have to press the classify button which I also want to automate in pyqgis. Can anyone help me with this last step?

enter image description here

Here is my code:

year = 2030
allocated_regions = QgsVectorLayer(output_folder + "regions_w_plant_alloc_" + str(year) + ".shp", "allocated_regions_" + str(year), "ogr")
QgsProject.instance().addMapLayer(allocated_regions)

# Field name
expression = 'plant_allo'
# Set the categorized renderer
renderer = QgsCategorizedSymbolRenderer(expression)
allocated_regions.setRenderer(renderer)
allocated_regions.triggerRepaint()

Is there a way to automate classification of symbology in PyQGIS?

I have created this code to categorize my layer symbology based on the attribute plant_allo. However I still have to press the classify button which I also want to automate in PyQGIS. Can anyone help me with this last step?

enter image description here

Here is my code:

year = 2030
allocated_regions = QgsVectorLayer(output_folder + "regions_w_plant_alloc_" + str(year) + ".shp", "allocated_regions_" + str(year), "ogr")
QgsProject.instance().addMapLayer(allocated_regions)

# Field name
expression = 'plant_allo'
# Set the categorized renderer
renderer = QgsCategorizedSymbolRenderer(expression)
allocated_regions.setRenderer(renderer)
allocated_regions.triggerRepaint()
Source Link

Is there a way to automate classification of symbology in pyqgis?

I have created this code to categorize my layer symbology based on the attribute "plant_allo". However I still have to press the classify button which I also want to automate in pyqgis. Can anyone help me with this last step?

enter image description here

Here is my code:

year = 2030
allocated_regions = QgsVectorLayer(output_folder + "regions_w_plant_alloc_" + str(year) + ".shp", "allocated_regions_" + str(year), "ogr")
QgsProject.instance().addMapLayer(allocated_regions)

# Field name
expression = 'plant_allo'
# Set the categorized renderer
renderer = QgsCategorizedSymbolRenderer(expression)
allocated_regions.setRenderer(renderer)
allocated_regions.triggerRepaint()