3

From a layer of overlapping points (identical coordinates) containing the field "RC", I'm using the following expression to make the label of unique values:

array_to_string(array_distinct(array_prepend(overlay_equals(@layer, "RC"), "RC")),'RC')

And to avoid duplicates I use the following expression in the labeling option 'Show label'.

$id=array_agg($id, "XCOORD"||"YCOORD")[0]

enter image description here

I would like, if possible, to reuse the labeling expression, to format the list of values to appear in a series of 2 columns of 2 records:

Simulation

enter image description here

3
  • 1
    Hi ha un màxim de 4 punts per coordenada?
    – Albert
    Commented Jun 28 at 11:40
  • 1
    El número de punts per coordenada pot ser 1 o >1 . English translation: The number of points per coordinate can be 1 or >1 . This means that in some cases there can be only 1 point (1 record) and in some cases there can be, for example, 15 points (15 records) with the same coordinate and with duplicated or unique "RC" values Commented Jun 28 at 12:20
  • 2
    Ok, I was answering a solution for just 4 unique values but I adapted it a bit and now should work for more
    – Albert
    Commented Jun 28 at 13:04

1 Answer 1

5

I think the following approach could work:

with_variable(
'values', array_remove_all(array_distinct(array_prepend(overlay_equals(@layer, "RC"), "RC")), NULL),
with_variable(
    'num_values', array_length(@values),
    with_variable(
        'rows', ceil(@num_values / 2),
        with_variable(
            'labels', array_foreach(
                generate_series(0, @rows - 1),
                with_variable(
                    'row_index', @element * 2,
                    @values[@row_index] || ' ' || if(@num_values > @row_index + 1, @values[@row_index + 1], '')
                )
            ),
            array_to_string(@labels, '\n')
        )
    )
)

The "show label" expression you are using I think is fine.

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.