In QGIS I am trying to calculate the distance from a point layer to a polyline layer for the n nearest polylines. I have figured out how to calculate this distance to the centroid of the polylines using the point to hub tool, but I need the distance to the edge of the closest polylines - not centroids. I can calculate the nearest polyline by dumping the polylines to nodes and calculating to nearest point, but that method falls apart for the n nearest calculation.

Any thoughts?

2 Answers 2


You can use the NNJoin plugin to calculate the distance between points and its nearest line. You can download the plugin via Plugins > Manage and Install Plugins....

It is recommended, however, to not use this plugin on large datasets containing lines as it does not use a spatial index for lines.

  • This doesn't solve the problem for me unfortunately. I am not trying to join the nearest line I am trying to join the N nearest lines. The nearest neighbor is easy in QGIS, but I need the 5 nearest neighbors. Oct 14, 2014 at 17:29

To get the nearest points go to Processing, search for Nearest, then Join attributes by nearest. You can then input your two vector layers and specify the max nearest neighbours to 5. It will show the distance between the vector layers too.

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.