2

In QGIS 3.0, I am using the new clustering style.

enter image description here

I want to display labels based on cluster size.

What I tried in expression field:

 case
 when @cluster_size>5 then  "label_name" 
 end

enter image description here

  • I doubt it can work: the cluster regroup several points together, but you ask to label using a column, so a value from each individual feature. If it can be done at all, you would need to aggregate/summarize the column values to a single one – JGH May 10 '18 at 11:22
  • @JGH All ponctual markers of each cluster have distance of 0. For example, in my data, I have 163 markers for "Nantes" place. So I expect 163 "Nantes "labels overlapping. – Wilcar May 10 '18 at 11:53
  • Sometimes an if() expression works better than a case-when statement. I have no idea if it will help here, but it won't take long to try: if(@cluster_size>5, "label_name", null). – csk May 11 '18 at 15:38
  • @csk Thank you for helping. Unfortunately not working...(no labels displayed) – Wilcar May 11 '18 at 15:44
3

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: enter image description here

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)

enter image description here

Use an expression like

if(@cluster_size>5, "label_name", '')

enter image description here

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.