<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi,<br>
<br>
I am trying to generate a proportional symbol symbology using data
defined symbol size in a QGIS 3 python plugin.<br>
<br>
Here is the working code :<br>
<br>
# Symbol creation<br>
symbolLayer = QgsSimpleMarkerSymbolLayer()<br>
symbolLayer.setShape(QgsSimpleMarkerSymbolLayer.Circle)<br>
symbolLayer.setSize(2.0)<br>
symbolLayer.setColor(QColor(31, 120, 180)<br>
symbolLayer.setStrokeColor(QColor(255, 255, 255)<br>
symbolLayer.setStrokeWidth(0.4)<br>
<br>
symbol = QgsMarkerSymbol.createSimple({})<br>
symbol.changeSymbolLayer(0, symbolLayer)<br>
<br>
# Size definition (Flannery method)<br>
# layer is a QgsSingleSymbolRenderer<br>
strExp = 'coalesce(scale_exp("value", 0.0, 150, 1, 20, 0.57), 0)'<br>
symbol.setDataDefinedSize(QgsProperty.fromExpression(strExp))<br>
layer.renderer().setSymbol(symbol)<br>
<br>
The problem is the legend. This code :<br>
<br>
# Legend<br>
lgd = QgsDataDefinedSizeLegend()<br>
lgd.setLegendType(QgsDataDefinedSizeLegend.LegendCollapsed)<br>
lgd.setClasses([<br>
QgsDataDefinedSizeLegend.SizeClass(150, '150'),<br>
QgsDataDefinedSizeLegend.SizeClass(75, '75'),<br>
QgsDataDefinedSizeLegend.SizeClass(15, '15')<br>
])<br>
<br>
layer.renderer().setDataDefinedSizeLegend(lgd)<br>
<br>
produces an enormous legend symbol :<br>
<img src="https://i.stack.imgur.com/xvTgU.png"
alt="https://i.stack.imgur.com/xvTgU.png" class="transparent"><br>
<br>
However, if I open the layer properties dialog and update parameters
with
datadefined size assistant, the legend is refreshed with the correct
size :<br>
<img src="https://i.stack.imgur.com/h3Ok2.png"
alt="https://i.stack.imgur.com/h3Ok2.png" class="transparent"><br>
<br>
What am I missing ?<br>
<br>
Thanks for any hint,<br>
<pre class="moz-signature" cols="72">--
Christophe Damour
</pre>
<br>
</body>
</html>