I'm using QGIS 2.8's Distance Matrix tool to find distances to nearest neighboring points on a single layer. I've followed roughly the instructions on this site and adapted it to my needs. However, I'm having issues with the resulting data. In my example, I've used myLayer as both input and target layers to find the three nearest points. I then added the resulting CSV to QGIS and selected all elements whose InputID = TargetID in order to find the points who were matched with themselves. The strange this, is these distances are not 0.

I get this sort of result:

InputID TargetID Distance
PointA   PointA   23.023
PointB   PointB   4.532

Can someone please explain to me where this distance comes from? My ultimate goal is to find the distance for each point to it's two nearest neighbors (not including itself).

closed as off-topic by underdark Feb 4 '17 at 22:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – underdark
If this question can be reworded to fit the rules in the help center, please edit the question.


It is difficult to explain your results without seeing your dataset. You may have a problem with your attribute data (non-unique InputID / TargetID?).

I tested Distance Matrix in QGIS 2.8.2 using a Shapefile format layer with a projected CRS.

Only neighbour points with a distance greater than 0 to the "reference point" were included in the output CSV file.

So if you use the same layer for both input and output, you should get the two closest neighbours by using the "Linear (N*k x 3)" output type with k=3. The neighbour points with distance 0 are not reported, but they seem to be "counted", so with k=3 you will get the two nearest points.

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