1

I am new to QGIS and QField

I have a layer of created points with numbers.

I need that when a user comes to a point at a distance of 5-10 meters and creates a new point, the number of the nearest point (from the layer of already created points) is written in the field of a new point. I tried using overlay_nearest('1', name, max_distance:=10) but it didn't work.

enter image description here

1 Answer 1

1

I've had to make some assumptions because your question lacks detail. I assume your point layer is '1', and the attribute you're trying to retrieve from that layer is "name". For future reference it helps potential responders to make this explicit.

If that's the case, it may be because your function currently returns an array. Given that it is the nearest neighbour that array should only contain 1 member, but it's still an array. Try getting the first member of the array (zero based index) using

overlay_nearest('1', name, max_distance:=10)[0]

I have prepared an example.

Existing point layer is named 'tree_pt'. It has an attribute "num".

In the GIF there are four features labelled T1, T2, T3 and T4 (The 'T' is simply a label prefix, i.e. 'T'||num. As I add points, you will see the attribute "Label" of the new point layer is populated with "num" of the nearest neighbour in tree_pt. In the layer properties_attribute form, I have set the default value of "Label" to

overlay_nearest('tree_pt', num, max_distance:=10)[0]

Here is the GIF of it working... enter image description here

3
  • You got it right. Sorry for not giving all the details. overlay_nearest('1', name, max_distance:=10)[0] - No changes :( I don't fully understand if this function will help me solve my task or not. The layer with the points is just the coordinates, names and fid(treid use fid too). Maybe some other information is needed?
    – Danil
    Feb 9, 2023 at 14:59
  • This works for me - I will edit my post above and added a GIF of it working...
    – Oisin
    Feb 9, 2023 at 15:15
  • Thank you very much, the problem was solved. The problem was in the encoding of the layer (maybe because import from mapinfo) and in the spaces in the layer name.
    – Danil
    Feb 15, 2023 at 7:14

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.