3

In a layer with point geometry, I have the house number label. Each geometry has the HOUSENUM, PARCEL and STREET fields. In some cases the geometry is duplicated (equal geometry), in some cases the house number attribute could be also duplicated.

I am using the following expression to get the labels avoiding duplicates. But I need to be more precise and take into consideration the groupings by PARCEL and STREET. At the same time this function is not working well as it seems to duplicate labels in some cases.

array_to_string(string_to_array(aggregate(
  layer:='HOUSE',
  aggregate:='concatenate_unique',
  expression:="HOUSENUM",
  concatenator:='\n',
  filter:=intersects($geometry, geometry(@parent))
)),',')

I am sending a screenshot of the result I am getting at the moment with the display of the attribute table for three different PARCELS, so that you can see the structure of the table and the duplicate values:

PARCEL 00001 and STREET A and B: enter image description here

PARCEL 00002 and STREET A: enter image description here

PARCEL 00004 and STREET A and B and C: enter image description here

And I send screenshot of the expected result. I am interested in solving the conflict of duplicated geometries and filtering without duplicates the HOUSENUM texts according to the PARCEL and the STREET to which they belong. Regarding the Placement expected, just show the position to understand the problem.

enter image description here

3
  • 1
    Would cleaning up your data be an option? If not, how do you decide which feature to label?
    – Erik
    Commented Mar 21, 2023 at 10:52
  • In this case it is not an option since the layer with point geometry is generated from a table of full addresses table of municipalities. This duplicated geometry allows to run another expression to count how many addresses there are in a HOUSENUM
    – Acperience
    Commented Mar 21, 2023 at 10:57
  • 1
    You appear to be asking two questions (removing duplicate labels and positioning the label next to the street). You will have to ask a new question for the second, else your question is likely to be closed for needing more focus.
    – Matt
    Commented Mar 21, 2023 at 11:10

1 Answer 1

8

To prevent the duplicated labels, you can try this to render the label only once per PARCEL|STREET group.

case
    -- render the label for only the first feature of the group
    when $id = array_min(array_agg($id, group_by:="PARCEL"||'|'||"STREET"))
    then
        array_to_string(string_to_array(aggregate(
            layer:='HOUSE',
            aggregate:='concatenate_unique',
            expression:="HOUSENUM",
            concatenator:='\n',
            filter:=intersects($geometry, geometry(@parent))
        )),',')
end
2
  • This solution only partially solves the problem. There are PARCELS that have the same HOUSENUM for two different STREETS. For example, in this case the HOUSENUM '40' would have to appear twice, once for STREET A and once for STREET B
    – Acperience
    Commented Mar 21, 2023 at 11:15
  • 2
    You can adapt the group_by parameter to include the street also. See my update. It concatenates the PARCEL with the STREET (separated by a | symbol)
    – Matt
    Commented Mar 21, 2023 at 11:17

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.