View Ticket
Not logged in
Ticket Hash: bbc3575db2790061c5fca3be230c4e4b50328ebc
Title: KNN2 results for "tied" values of distances
Status: Fixed Type: Documentation
Severity: Important Priority: Immediate
Subsystem: Resolution: Fixed
Last Modified: 2023-09-02 18:03:56
Version Found In: 5.1.1-rc0
User Comments:
anonymous added on 2023-08-14 12:26:39:
In the wiki page
https://www.gaia-gis.it/fossil/libspatialite/wiki?name=KNN2

there is no information about the behaviour of the algorithm in case of tied values.

When a user chooses a value for max_items and for the max value there are more than one points at the same distance, the algorithm chooses only 1 point and discharges all the others with no message to the user about this choice so that the user doesn't know that some information have been discharged.


Here the output of Spatialite for a specific point 

id_pun 	pos 	fid 	        distance_m
153652 	1 	770170000019 	0.000000
153652 	2 	770170000015 	37.826619
153652 	3 	770170000007 	57.641897
153652 	4 	770170000039 	64.489781
153652 	5 	770170000009 	90.035088
153652 	6 	770170000010 	131.027696

Here an example of the output of QGIS 3.28 for the same point where there are 3 points with n = 6,7,8  at the same distance 

id_pun 	id_sez 	        n 	distance
153652 	770170000019 	1 	0.000000
153652 	770170000015 	2 	37.826619
153652 	770170000007 	3 	57.641897
153652 	770170000039 	4 	64.489781
153652 	770170000009 	5 	90.035088
153652 	770170000011 	6 	131.027696
153652 	770170000010 	7 	131.027696
153652 	770170000013 	8 	131.027696

and here is part of the logfile generated by QGIS to communicate to the user the existence of extra points 

"Multiple matching features found at same distance from search feature, found 8 features instead of 6"


It would be useful for Spatialite users to find in the documentation of KNN2 a reference at the possibility of potentially discarged pieces of information based on the choice of keeping only the first of n points.

sandro added on 2023-09-02 18:03:56:

I agree: although it may be a rather rare eventuality, it is certainly regrettable to apply a completely arbitrary truncation to the returned resultset.

it seems preferable to possibly exceed the limit set by max_items in order to continue to insert into the resultset all items at the same distance.

the changes are already in the Fossil repository and will be released with the next version