View Ticket
Not logged in
Ticket Hash: 6fa0670c7bdf44be72babdec1f262c59b9e697d8
Title: KNN2 returns rows where the radius is greater than that specified.
Status: Closed Type: Code_Defect
Severity: Minor Priority: Immediate
Subsystem: Resolution: Works_As_Designed
Last Modified: 2023-07-24 15:10:32
Version Found In: 5.1.0
User Comments:
anonymous added on 2023-02-08 01:05:04:

KNN2 returns rows where the radius is greater than that specified.

$ git clone https://github.com/captain-igloo/knn2-bug.git

$ cd knn2-bug

$ docker build -t knn2-bug .

$ docker run knn2-bug "select * from knn2 where f_table_name = 'test' AND ref_geometry = MakePoint(1746260, 5427154) AND radius = 100 AND max_items = 1;"

MAIN|test|shape||100.0|1|0|1|1|122.347864713692|122.347864713692

A row is returned that is outside the 100 m radius specified.


sandro added on 2023-07-24 15:10:32:

as it's clearly stated in the documentation [1] the RADIUS passed to KNN2 is just a first coarse extimate of the area to be searched.

[1] https://www.gaia-gis.it/fossil/libspatialite/wiki?name=KNN2

if not enough point are found a new search will be performed by doubling the RADIUS, and so on until the requested number of points will be found.

so there is absolutely nothing strange if a KNN2 search identifies some points with a distance exceeding the RADIUS, it's exactly what the algorithm is expected to do