I have to point layers:
- Boreholes (with 100 features)
- Trees (with 300 features)
The tree layer has three attributes:
I would like to find the closest tree (based on "Tree_ID"
) to each borehole, using the Field Calculator. Traditionally, we use the "Distance Matrix" tool and set K = 1. I have done that, here is the result table:
However, I am wondering if this is possible using the Expression Engine in Field Calculator. I already have calculated the distance to the closest tree for each borehole using this expression:
aggregate(
layer:= 'Trees',
aggregate:= 'minimum',
expression:= round(distance(@geometry, geometry(@parent)), 2)
)
I created a new field for the boreholes, to show the distance to the nearest tree. Here is the result:
Now I would like to find out if I can use the Field Calculator expression engine to find the Tree_ID of the nearest tree. Is it possible to use the expression engine in the Field Calculator to get the ID of the closest tree?