Wednesday 22 February 2017

symbology - How to change visibility of a particular layer category in PyQGIS?


I've got one layer with its symbol MARKER, categorized by an expression in 4 colors. The colors depends on a value of a column. So from the TOC, I'm able to click and enable/disable, as they were different layers, and show one category a time.


From python script, I want to do the same, with a loop: show/hide in the map the different existing categories one each time (for printing separated the 4 jpg),


I tried to show the active layers, and categories aren't not showing as a proper layer. So, I thought that the proper layer was a group tree, but when I ask for QgsLayerTreeGroup always show no group.


How can I obtain categories for changing their visibility in the map?


root = QgsProject.instance().layerTreeRoot()
for child in root.children():
if isinstance(child, QgsLayerTreeGroup):
print "- group: " + child.name()
if child.name() == "rara": #to check subgroups within test group

print "rara"
for subChild in child.children():
print "child"
if isinstance(subChild, QgsLayerTreeGroup):
subChild.name()
else:
print "no group: " + root.name()


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...