Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two layers with points, call them 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 so this in ArcGIS: right click layer A>joins and relates>joins, then join data based on spatial location and choose to join attributes from nearest point.

I could not find similar functionality in QGIS. Any pointers?

share|improve this question
up vote 20 down vote accepted

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

share|improve this answer
@underdark +1 Many thanks! Very clear and helpful. – Fred Jun 22 '11 at 22:11
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: – Celia Feb 21 '12 at 17:31
This is not an answer to the question, but a request to elaborte on the answers given. In what units are the distances computed in? Or more specifically, how do I determine distance in meters/kilometers? Thank you. – n1kn0k Apr 7 '12 at 7:31
@user1078934 Distance is given in the units of the CRS the layers are in. If you want distance in meters, you have to reproject to a CRS in meters before calculating the distance matrix. – underdark Apr 7 '12 at 10:43
@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. May 22 '13 at 16:37

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.

share|improve this answer

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.

share|improve this answer

Using QGIS 1.7 Vector >Data Management> Join Attributes by Location

enter image description here

share|improve this answer
I thought of this, too, but when I tested it out, it only worked for exact matches, such as point-polygon. It did not find the nearest point to another point. Tested in v1.7 – RyanDalton Jun 22 '11 at 21:48
I got zero matches. This does not work. – Fred Jun 22 '11 at 21:55

protected by whuber Mar 31 '14 at 14:18

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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