Issue
I want to have a red-star symbol for some points, and a green-circle symbol for others, depending on a column in my data called star.
This, https://docs.qgis.org/3.4/en/docs/pyqgis_developer_cookbook/vector.html#categorized-symbol-renderer
talks about a "Categorized Symbol Renderer" just doesn't give any detail as to how to make it at all.
Solution
My column name is "star" and I wanted to use a circle symbol if the value was 0 and a star if it was anything else.
This took way too long to figure out since I couldn't find any examples and the documentation to write these few lines was a bit painful, here are the docs I figured it out from eventually: https://qgis.org/pyqgis/master/core/QgsRendererCategory.html
circle_symbol = QgsMarkerSymbol.createSimple({'color': 'green', 'size': '3', 'outline_color': 'black'})
star_symbol = QgsMarkerSymbol.createSimple({'color': '#ff0000', 'size': '5', 'outline_color': '#ff0000', 'name' : 'star'})
c1 = QgsRendererCategory(0,circle_symbol,"No Star",True)
c2 = QgsRendererCategory(None,star_symbol,"Star Note",True)
renderer = QgsCategorizedSymbolRenderer("star", [c1,c2])
myQgisVectorLayer.setRenderer(renderer)
myQgisVectorLayer.triggerRepaint()
Answered By - J L
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.