3

I have two layers which I want to connect using the aggregate() function with the Field Calculator. I can do this using the processing tool:

processing.run("native:aggregate", {
    'INPUT' : 'XX.gpkg|layername=obj_flurname',
    'GROUP_BY' : '"Aufn_Nr"',
    'AGGREGATES': [
        {'aggregate': 'first_value','delimiter': ',','input': '"Aufn_Nr"','length': 50,'name': 'Aufn_Nr','precision': 0,'sub_type': 0,'type': 10,'type_name': 'text'},
        {'aggregate': 'concatenate_unique','delimiter': ', ','input': '"name"','length': 254,'name': 'name','precision': 0,'sub_type': 10,'type': 11,'type_name': 'stringlist'}],
    'OUTPUT' : 'TEMPORARY_OUTPUT'
    })

When I want to implement the same thing in the Field Calculator, I don't have the option to group_by like in the native:aggrregte function. Is it possible to add this group_by, or do I have to run this with the advanced field calculator (with Python)?

My efforts so far:

aggregate(
    layer:='XXX_1da2ccba_0147_4280_a0e9_439870e296c4',
    aggregate:='concatenate_unique',
    expression:="name",
    concatenator:=', '
    )

But this only aggregates all possible unique values to all rows. How could I change this so that it works?

1 Answer 1

3

Instead of the aggregate() function, use the concatenate_unique() function: there, you have the option to set a group_by argument.

4
  • 1
    Thank you very much. I will try this tomorrow. I am happy you answered so fast. I am a Student at UZH :) Commented Oct 21, 2023 at 19:02
  • 1
    Great! As UZH student, please also notice this: gis-hub.uzh.ch
    – Babel
    Commented Oct 21, 2023 at 19:49
  • 2
    Oh thats really cool. I did not know this about this hub. I will keep me updated. Ross, your collegue, is my professor at uni :D Thanks for your help & see you Commented Oct 21, 2023 at 20:07
  • 2
    It worked, thank you! Commented Oct 26, 2023 at 10:09

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.