I have two layers with points, A and B, each with different attributes.

For each point in A, I want to join all the attributes from the nearest point in B.

Ideally, this would also include a field measuring the distance between both points.

I know how to do this in ArcGIS: right-click layer A > joins and relates > joins, then join data based on spatial location and choose to join attributes from the nearest point.

Is there any similar functionality in QGIS?

6 Answers 6


Using "Distance Matrix" you can calculate the nearest point. Make sure that both layers are in the same CRS! Then, you can load the results and use them to join table A and B.

In "Distance matrix" chose: "Linear distance matrix" and "use only the nearest k target points: 1"

enter image description here

Load the CSV using "Add Vector Layer" and join the layers in Layer A's layer properties - join tab.

enter image description here

And the result:

enter image description here

  • If you want to have the distances between points within one layer using distance matrix you should change k=2, because of this known issue: hub.qgis.org/issues/4761
    – Celia
    Commented Feb 21, 2012 at 17:31
  • 1
    @underdark It seems this solution does not work anymore. I am able to create the matrix.csv and join it to my first layer. In your example you added a second join where you attach the second layer to the first, based on the TargetID from the matrix. But the joined fields are not show to me in the dialog, so I can't select the TargetID. Of course i can first save_as the layer and then do the second join ...
    – Bernd V.
    Commented May 22, 2013 at 16:37

The NNJoin Plugin should do the job. For each feature of the input layer it adds all the attributes of the nearest feature in the join layer and also adds a distance attribute with the distance to this feature.

  • Works perfectly. Faster than the accepted answer. Note that the accepted answer if from 2011.
    – juminet
    Commented Jun 9, 2017 at 11:54
  • At least, today is much better than the accepted answer. Much much faster. Commented Nov 17, 2017 at 18:27
  • 1
    See the other comments, too. There's now the 'Join attributes by nearest' tool
    – Vincé
    Commented Apr 12, 2022 at 15:08

In QGIS 3.8 and above the "Join attributes by nearest" native tool in Processing Toolbox does the job easily!


If you can live with just joining a single attribute from your "B" layer, take a look at the "Hub Distance" tool from the mmqgis plugin.

If you need the rest of the "B" attributes, you should then be able to join the rest of your "B" attributes back to this layer.

You can also optionally generate lines from the A to B if desired. This is helpful for visualizing the distances and directions between associated features.


Another approach using refFunctions plugin.

(1) Sample Dataset

enter image description here

(2) Open an attribute table of the layer which has more features (points_b layer in this example) so that no pairs are missed out. Create new fields.

  • ID field of the other layer: geomnearest('points_a', 'id_a')
  • Distance field of the detected pairs: geomnearest('points_a', '$distance')

enter image description here


Since release 3.8 (2019), and as pointed out in a comment above, you could use the tool 'Join Attributes by nearest', which will create a new vector layer based on 2 input vector layers. In the new layer there will be 1 or more new column(s) with the joint attribute.

You can set a maximum number of neighbours to consdier, as well as the maximum distance. As attributes to the output layer you will get also the closest point chosen to join the attributes.

  • 1
    This functionality was available in QGIS 3.8 released on 2019-06-21 and previously submitted answer has already referred this tool.
    – Dave
    Commented Apr 16 at 1:01
  • I thought this was worth an answer, which I will now modify.
    – brodegon
    Commented Apr 16 at 7:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.