Wednesday 30 November 2016

qgis - Label display based on cluster size


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



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: 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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...