I am having a problem with last part of defining values in geopackage.

I have created relation values based on field values (drop-down values). Last one I want to create, is to make relation based on geometry (intersection with another layer).

I have points layer (imeGC as field I want to be populated), and polygon layer gc (with imeGC as field I want to use values to populate point layer).

So, when I add new point, I want to imeGC field to automatically be populated with values from gc polygon layer, when the point is within (intersects) that layer.

enter image description here

I tried with variations from this answer, but with no luck. I used variation of this code.

intersects($geometry, buffer(geometry(get_feature('node_layer','node_id',current_value('node'))),0.5))

EDIT: I will replicate this also with line layer (Roads), so the code should be applicable to that also.

EDIT 2: The only answer which is near my wanted solution is this code:

array_first(overlay_nearest('LAYER_B',"FIELD_OF_LAYER_B", limit:=1, max_distance:=2))

But with this code, I get the wanted value in brackets:


My next questions are, how to get a value without brackets, and how to limit the results to 3 nearest?

  • 1
    If you use QGIS 3.16+ you can use overlay_intersects().
    – MrXsquared
    Jun 30, 2022 at 8:08
  • I tried that, but I do not know how to integrate it with buffer. It works with polygons, but not with lines, when I need buffer.
    – Dean7
    Jun 30, 2022 at 8:13

1 Answer 1


Just extract the first array element, e.g. using bracket notation:

overlay_nearest( 'LAYER_B',"FIELD_OF_LAYER_B" )[0]

See the expression description for additional filter and ordering options.

Not sure what you intend to do with the 3 nearest neighbors, but you can add limit:=3 to have the engine retrieve the FIELD_OF_LAYER_B values from the 3 nearest features of each layer in order.

While this expression is favorable for lines, it is likely unwanted for when intersection with a polygon is a required predicate.
Now, you can (and probably want to) add a max_distance value to the above expression to find candidates only in the given proximity (much like with a buffer) for both layers, or just define a different expression for the polygon layer:

overlay_intersects( 'LAYER_B',"FIELD_OF_LAYER_B" )[0]

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.