I have a table (table1) containing 800 points that I want to join with a table (table2) containing only 10 points. The idea is that the points in table2 are assigned to the points in table 1 based on nearest neighbor analysis. This can be easily done using, for example, the NNJoin plugin in QGIS.

However, this plugin only adds a column containing the distances to the nearest points to table1. But that's not what I need, for I want to add multiple columns with information from table2 to table1 based on the nearest neighbor analysis.

So in short, how can I add multiple columns filled with data from table2 to table1, based on nearest neighbor analysis?


A small reformulation, to clarify things a bit: I want to add all attributes from table2 to table1, based on nearest neighbor analysis. So not only the distance, but also all other attributes from table 2.

  • The NNJoin plugin also adds the attributes of the joined dataset: "The result layer will contain all the attributes of both the input and join layers plus a new attribute “distance” that contains the distance between the joined features. The attributes from the join layer will get a prefix (the default is “join_”, but this can be set by the user). If a join prefix is not used, attributes from the join layer that have the same name as attributes in the input layer will not be included in the output layer." (arken.umb.no/~havatv/gis/qgisplugins/NNJoin) Commented Feb 26, 2016 at 1:22

1 Answer 1


You could use the Distance to nearest hub tool from:

Processing Toolbox > QGIS geoalgorithms > Vector analysis tools > Distance to nearest hub

Make sure you have a unique value for a field in table2 as this would be used to identify each point in this layer when calculating distances from points in table1

Distance to nearest hub

Then with the "Hub distance" output layer, do a Joins by going into Layer Properties > Joins and selecting table2 as the "Join layer". Select the same field with unique values as the "Join field" and HubName as the "Target field":


This should join the attributes of the "Hub distance" layer (which contains all attributes from table1) with the attributes of table2:

Joined attributes

  • 1
    Thank you, Joseph! This is exactly what I was looking for. Feels great to have learned something new about QGIS today.
    – flebbelep
    Commented Feb 24, 2016 at 21:08
  • @flebbelep - Most welcome buddy! I tend to learn something new quite often and yes, it does feel great =)
    – Joseph
    Commented Feb 25, 2016 at 11:42

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.