[GIS] Connect points to a line with shortest distance using QGIS

qgisshortest path

On the picture below, I want to let my point connect to the line with the shortest distance and show the distance to me.

enter image description here

I tried NNjoin, MMQGIS, v.distance But I still can't get the distance.

How do I connect them and get the shortest distance?

enter image description here

After that, I used the field calculator, but I think the distance is wrong

enter image description here

I measured it by myself, is any details can tell me to calculate the distance?

Best Answer

It is possible to create a line that joins points and line using the Geometry generator.

In the point layer symbology, select the Geometry generator and use this expression to create the shortest line between the two geometries

shortest_line($geometry, aggregate('Line0', 'collect', $geometry))

0

To know the distance between the two geometries, AKA the length of the shortest line, you can use this expression in the label expressions or use it in the Field calculator to create a new field with this information

length(shortest_line($geometry, aggregate('Line0', 'collect', $geometry))
)

enter image description here

Related Question