1

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()

Tobias
  • 177
  • 8
  • I used your solution in a loop but for me it is not working. The units of the layer remain Milimeters. Even when I change manually the Map Units to something else and run the script it changes to Milimeters enter image description here 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

1 Answers1

2

I finally found it.

layer.renderer().symbol().symbolLayer(0).setWidthUnit(QgsUnitTypes.RenderMapUnits)

does the job

Tobias
  • 177
  • 8