# Connect points to a line with shortest distance using QGIS?

On the picture below, I want to let my point connect to the line with the shortest distance and show the distance to me. I tried NNjoin, MMQGIS, v.distance But I still can't get the distance.

How do I connect them and get the shortest distance? After that, I used the field calculator, but I think the distance is wrong I measured it by myself, is any details can tell me to calculate the distance?

• did you try v.net.connect? Oct 22, 2018 at 8:27
• Hi PieterB, thanks for your reply. I tried , it connected to the nearest place, but I want to get the distance ,
– Jack
Oct 22, 2018 at 8:49
• then you have to add a field to calculatie the length. You can do that with the fieldcalculator. Oct 22, 2018 at 9:04
• Hey PieterB,I got some problem,how to messure the distance?
– Jack
Oct 22, 2018 at 9:18
• in your 1st picture I notice a layer called 'gps1'. I think this will be in wgs84. In the last picture I see in the measure-tool 'OTF off'. I think you are measuring in the wrongs crs, namely wgs84. This will give you the wrong results! Can you say which crs you are using? Oct 22, 2018 at 14:48

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))
`````` 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))
)
`````` 