5

Without editing original data, I want to display a single symbol in the center for points which has identical attributes. I have an area with nine basements. To each basement belong several points. I've attached the image of my map:

area with basements

For labeling, I successfully used the centroid () expression and the geometry generator: enter image description here

I have not been able to transfer centroid expression to the symbols yet. Instead I used the code of MrXsquared to create a symbol for each basement (Labeling only one duplicate attribute without editing original data in QGIS). enter image description here

Case When array_find(array_agg( "id" ,group_by:= "gehoert_zu",filter:= "Ansicht" LIKE 'Draufsicht'),attribute($currentfeature,'id')) = 0 Then "gehoert_zu" LIKE '%Keller%' and "Ansicht" LIKE 'Draufsicht' Else '' END

But it is not in the center, because only the first feature within the array gets a label. non-centered symbols

Any idea on how to combine array_agg() and centroid()?

2
  • 2
    Why don't you use the same centroid() expression for the symbology?
    – Andre Geo
    Aug 15, 2023 at 10:34
  • I'd try with: A geometry generator that creates the centroids and then set each centroid's symbology using overrides (with expressions using its group), might be a bit tricky to get the group to the centroid geometries. Aug 15, 2023 at 10:46

2 Answers 2

4

I used the following to get a centroid geometry:

centroid(
    collect(
        $geometry,
        group_by:= <Group by attribute(s)>,
        filter:= attribute( 
get_feature_by_id(<layer>,$id),<Group by attribute(s)>)
    )
)

enter image description here You might need to adapt it to your data. I dummied up my points based on the original (numbered) polygons, using Random points inside polygons, and added a field/attribute to each point based on the polygon it was created from.

Original points in blue, centroids (of the blue points) in red.

enter image description here

4
  • Thank you Tom. Great solution! Didn't now the geometry generator for symbol function.
    – Janko
    Aug 15, 2023 at 13:08
  • 1
    One thing I'd note is that there are possibly simpler solutions - the Geometry Generator is powerful, but complex. Playing with the "Geometry by expression" tool can give you a better handle on how it works, as you can review the actual features created (and not just the symbols)! Aug 16, 2023 at 0:01
  • Also, if it solves your problem, or was the most useful solution, remember to accept the answer. Aug 16, 2023 at 2:18
  • Problem was solved by using geometry generator (like Tom Brennan said) and same geometry () expression which i used for labeling (suggestion by Andre Geo). To control the position of individual markers or labels, a data defined override can be used. To do this, call Placement -> Offset x,y -> Field calculator. Example for basement 4: CASE WHEN "gehort_zu" = 'Keller 4' and "Ansicht" ='Draufsicht' THEN 0,6 END. This moves the label/symbol 6 units to the south.
    – Janko
    Aug 24, 2023 at 19:35
3

You can use the same geometry generator expression to set the centroid symbol.

Create a new categorized symbology, select the group by variable (or expression in your case). Then, click on the symbol and change it to be a geometry generator and enter the centroid expression.

centroid(collect($geometry, group_by:="test"))

Go back, click classify and adjust the symbols as you wish.

If you want the same symbol for every centroid, just use the single symbol instead.

In the example below, the light gray points are from a copy of the original layer. enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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