9

I'm using QGIS 3.16 Hannover. I've got a hexagon grid layer and I want to create, with the field calculator, a new field with the id's of the surrounding polygons. I've adapted the following expression from this tutorial:

aggregate( layer:='grid', 
           aggregate:= 'concatenate', 
           expression:= "id", 
           filter:= touches($geometry,geometry(@parent)), 
           concatenator:=', ')

But it returns an error

An error occurred while evaluating the calculation string:
Could not calculate aggregate for: id

Why is that?

2 Answers 2

7

There is also a slightly easier way to generate an expression for this, using the overlay functions introduced in QGIS 3.16. This expression works regardless of the name of your layer as it uses the variable @layer which refers to the current layer:

array_to_string (overlay_touches( @layer, "id"))
0
5

You have to change line 3: expression:= to_string("id"),. To concatenate, you need a string as input and to_string() converts your "id" to a string.

The tutorial used a field that already was formatted as string, so that's why there was no need to convert it first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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