In QGIS 3.0, I am using the new clustering style.
I want to display labels based on cluster size.
What I tried in expression field:
case
when @cluster_size>5 then "label_name"
end
Answer
The variables @cluster_color
and @cluster_size
only exist in the context of the cluster renderer. They cannot be used in expressions for labeling. To label point clusters based on these variables, we can use a font marker as part of the cluster symbol.
Change the Cluster symbol in layer style panel:
Add a new symbol layer, symbol layer type: font marker (1)
Add an offset so the font marker appears to the side of the marker instead of directly on top of it (2)
Use data-defined settings to control the text of the font marker (3)
Use an expression like
if(@cluster_size>5, "label_name", '')
The third parameter in the above expression is two single quotation marks, not one double quotation mark. This represents an empty string, resulting in no label being displayed when the "label_name" field has a null value.
I originally used the expression if(@cluster_size>5, "label_name", null)
. With this expression, a default text label (A) will be displayed when the field value is null.
No comments:
Post a Comment