I have a unique layer with different polygon features. The symbology for each one is a simple fill with a random color, except if the name of the feature starts with "UR". In this case, the color is still random but the filling must be a Line Pattern.
I have to do it for QGIS using Python but I have to admit that I am a starter in programming.
I know the simple fill can be done by QgsFillSymbol.createSimple()
, but how can I get the line pattern filling? I have used the QgsLinePatternFillSymbolLayer.create()
, but I am sure I am missing something...
Is there a way to do it using Categorized Symbols?
Here is a little example of what I have. I know it has mistakes, but as I told you, I am just a starter and this is only the "chassis" of what I am trying to do.
if name.startswith("UR"):
symb = QgsLinePatternFillSymbolLayer.create( { 'angle' : 30, 'distance' : 2.0, 'width' : 0.5, 'color' : color } )
symb.setlineAngle(angle)symb.setDistance(distance)
symb.setLineWidth(width)
symb.setcolor(color)
else:
symb = QgsFillSymbol.createSimple( { 'color' : color, 'outline_color' :'gray' } )