Using QGIS 2.10.1 I need to determine the distance from each feature in layer A to its nearest feature in layer(s) B or C or...

ESRI has this capability with their "Near" tool:


Is there a QGIS equivalent?

I have

  • a point layer of 1269 boreholes
  • stream lines
  • lake polygons

I need to know, for each borehole, the single nearest distance to water (either stream or lake). In addition, I need to know whether that nearest water is stream or lake.

After completing the analysis, I envision the point layer's attribute table would contain 3 new fields:

  1. the nearest distance to water
  2. the layer (stream or lake) responsible for the nearest distance, and
  3. the stream or lake feature ID responsible for the nearest distance.
  • 3
    how about Vector menu > Analysis Tools > Distance Matrix Commented Oct 28, 2015 at 15:18
  • What are your features? Polygons, lines, points? I think most in-built QGIS functions deal with points to another feature type. In PostGIS, you could use st_shortestline coupled with the st_distance function to calculate distances between nearest features.
    – Joseph
    Commented Oct 28, 2015 at 15:25
  • 2
    Thanks for the quick responses. Unfortunately the Distance Matrix only works with point features, while the ESRI Near tool works with any combination of point, line and poly.
    – Stu Smith
    Commented Oct 28, 2015 at 18:56
  • 1
    Please clarify your requirements. While there might not be an exact equivalent of the tool, there might be something that fits your needs.
    – underdark
    Commented Oct 28, 2015 at 19:17
  • 2
    The NNJoin QGIS Plugin is what you are looking for. For each point, it finds the closest line. The resulting point layer will for each point contain the distance to the closest line and all of the attributes of that line. Commented Mar 25, 2017 at 11:14

1 Answer 1


The NNJoin QGIS Plugin finds the closest line for each point. The resulting point layer will for each point contain the distance to the closest line and all of the attributes of that line.

NNJoin calculates the single nearest feature to each input feature. NNJoin works both between two different layers and within a single layer. To find the nearest distances between an input layer and multiple join layers, run the tool once for each join layer. Then join the resulting output layers to the input layer.

-Copied and paraphrased from comments made by @StuSmith and @HåvardTveite

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.