I have two layer of points: 'Measure' (> 2000 points) and 'Control' (5 points).

For each control and measure point, I have a "depth" attribute. I would like to display on symbology of "depth" attribute with the closest point.

For now I can draw a line to the closest point:


Using this geometry expression inside 'Control' symbology:

make_line ( 

Now I want to display the difference of depth on this line (Sorry it is in french): 2

But i don t know how to extract the attribute "depth" from the geometry point I have in expression:


In this screen, 'resultPoints_e74212d8_6062_4c65_bdda_cfebd8bd679f' is my 'Measure' layer.

The real question is: How to extract attribute from a geometry point ?

In reality, i need to replace the 0 in this formula with the depth attribute of the closest point:

'XY:'||round(length(transform(make_line ( $geometry, overlay_nearest('resultPoints_e74212d8_6062_4c65_bdda_cfebd8bd679f', $geometry, limit:=2)[1]),
'EPSG:2832')),2)||'m - Z:'||round(0-"depth")||'m'
  • 2
    I didn't quite understand everything, but in the expression overlay_nearest instead of $geometry (which extract geometry) did you try to put the field Depth?
    – pigreco
    Commented Oct 16, 2022 at 15:46
  • Yes, i have NULL as result with formula: overlay_nearest('resultPoints_e74212d8_6062_4c65_bdda_cfebd8bd679f', "depth")[0] Commented Oct 16, 2022 at 15:51
  • 1
    This works for me, but you have to remove limit: = 2 and take the first value of the array [0]
    – pigreco
    Commented Oct 16, 2022 at 16:21
  • Working in blank example but not in my project. Thank you a lot for the usage of overlay_nearest that i missed! Commented Oct 16, 2022 at 16:55
  • 1
    Ok, the issue was EPSG code. With same EPSG code, there is no problem! Commented Oct 16, 2022 at 18:20

1 Answer 1


(The credit of the answer go to @pigreco) (You can copy paste the answer and i will delete this one)

To get the attribute 'depth' of the nearest point of another layer in a qgis expression:

overlay_nearest('<my_layer_id>', "depth")[0]

Replace <my_layer_id> in the formula with your layer id to compare.

To avoid issues try to have same EPSG codes in your two layers.

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.