I would like to change the stroke width from mm to map units. The code below is mainly taken from ThomasG77's answer from a previous question. I only found a way to change the units of Labels unfortunately.
Use colums in attribute table to set colors and line thickness directly automatic
layer = iface.activeLayer()
Get colors in rgb codes from Attribute table
layer.renderer().symbol().symbolLayer(0).dataDefinedProperties().property(QgsSymbolLayer.PropertyStrokeColor).setExpressionString(""Farben" || ',255'")
layer.renderer().symbol().symbolLayer(0).dataDefinedProperties().property(QgsSymbolLayer.PropertyStrokeColor).setActive(True)
Get Stroke width from Attribute table
layer.renderer().symbol().symbolLayer(0).dataDefinedProperties().property(QgsSymbolLayer.PropertyStrokeWidth).setExpressionString(""Linien"")
layer.renderer().symbol().symbolLayer(0).dataDefinedProperties().property(QgsSymbolLayer.PropertyStrokeWidth).setActive(True)
Refresh rendering of the layer
layer.triggerRepaint()
Here is how I used your suggestion: for a in layers_fimport: #print (a.name()) # get the layer's features as an iterator features = table.getFeatures() # Seach for a specific Layer in the table for feat in features: attrs = feat.attributes() if attrs[0] == a.name(): R = attrs(https://
– Theodora Vasileiou
Apr 05 '22 at 14:41