I was searching for the shortest distance between a point (point layer with about 22000 points) and the nearest point of a line from another layer (MultiLineString). I tried Distance Matrix, nearest neighbour, distance to nearest hub. None with the expected result. But then I found something interesting on GIS SE, but only displaying the shortest line. (Find nearest line feature from point in QGIS by @babel) It goes:
make_line(
$geometry ,
closest_point(
geometry( get_feature_by_id ('bayern_25832gis_osm_waterways_free_1',
array_to_string( overlay_nearest ( 'bayern_25832gis_osm_waterways_free_1', "osm_id" )
)
)
),
$geometry ) )
It looked perfect, so I tried copying it in the field calculator by exchanging make_line by 'distance' and voila.
Could it be thus simple?
I am just a biologist and have really no clue about expressions, their functions and so on.
How can I verify my results?
By now I only looked at the data, labeled the distances and measured by hand but cannot do this for 22.000 features.


length ( )statement: so inside these brackets, insert your whole expression. Let's say your expression to create the lines looks like this (shortened):make_line ( [...] )- then use this to calculate the length:length ( make_line ( [...] ) )- you see: your initial expression is inside the brackets oflength()This does not output a line, but a value for the length. If it doesn't work, please add a screenshot showing your settings and add the exact expression you use. – Babel Sep 27 '21 at 09:30"osm_id"with$id(no single or double quotes!). – Babel Sep 27 '21 at 12:38