I have a point layer with some overlapping points but I want to display only one label per symbol. For line and polygon symbology there is the "Merged features" option to agglomerate overlapping geometries, but not for points. Is there another way to do it ?
Asked
Active
Viewed 186 times
1 Answers
5
If the geometries of the overlapping points are identical, you can use this expression as the label value:
case
when $id = array_min(array_agg($id, group_by:= $x || ', ' || $y))
then "code" -- the field or label expression
end
The points are grouped by their geometry and then the label is rendered for only the point with the lowest id within the group (labels are skipped for all other points in the group).
If the geometries are not identical then a different approach to grouping will be required, but the logic remains the same.
Note: grouping by $geometry directly does not seem to work - the group for each feature contains all points in the layer. Hence, concatenating the x and y coordinates to group by.
Matt
- 16,843
- 3
- 21
- 52

geom_to_wkt(@geometry)and using that in the "show label" data defined override rather than in the label expression itself (which can be returned to letting the user use drop down field values). cf this answer I wrote sometime back https://gis.stackexchange.com/a/448175/98784 – she_weeds Jan 29 '24 at 01:25