Bug report #4761
Distance matrix: k becomes k-1 when working with one layer.
|Affected QGIS version:||master||Regression?:|
|Operating System:||Easy fix?:|
|Pull Request or Patch supplied:||No||Resolution:|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||14625|
In order to replicate: use one layer (target point layer = input point layer), and k=2. Run any analysis.
It finds k=2 points: the input point itself and a second point. The first point is (correctly) dropped, so k becomes 1 instead of 2.
#10 Updated by vinayan Parameswaran over 7 years ago
This is a bug that has been there since Qgis 1.8. I can't share a shapefile now. In fact, it will not work for any file.
How to replicate:
- Create a point layer with 4 point features.Populate Id field with unique values.
- In distance matrix dialog, set input layer and target layer as the same layer.
- set id field as input and output unique fields.
- Output Matrix Type -> select Linear Matrix. Enable the checkbox 'use only nearest(k) points' and set its value to 1.
- now ideally it should create a CSV file with four records because we chose a single neighbour only.
- But the resulting CSV is blank
- Now try increasing the nearest(k) value to 2.
- now for each feature in the shapefile, there should be two rows in the csv. so there should be 8 rows. But you can see that there are only four rows.
I have submitted a pull request that addresses this issue here.