Tuesday, 12 November 2019

qgis - Why does QgsSpatialIndex.nearestNeighbor(point, 1) sometimes return 2 lines?


I'm trying to get the closest line to a point using PyQGIS in a plugin. The active code file is this: http://pastebin.com/TDzmsKVM


When I request the closest line (only 1)



nearestIds = self.spIndex.nearestNeighbor(self.feat2.geometry().centroid().asPoint(),1)

I sometimes get a list with two lines and the first one is not the closest but as far as I can see the second one is. Why is this?


Does QgsSpatialIndex use only boundingboxes for lines? How do I get the real closest line always, not only most of the time?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...