You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to use strtree to find an element nearest to it but not its own?My code is as follows, what I expect to find is (1,1), not (0,0).
If I want to start from (0,0), find the nearest point (1,1), and then find the second nearest point (2,2), how do I operate?
Steps to reproduce the problem.
from shapely.strtree import STRtree
from shapely.geometry import Point
points=[Point(0,0),Point(1,1),Point(2,2)]
tree=STRtree(points)
pos=tree.nearest(Point(0,0))
print(pos)
#POINT (0 0)
Operating system
windows 10 20H2
python3.7.0 64-bit (conda)
Shapely version and provenance
Shapely-1.7.1 from pip install
The text was updated successfully, but these errors were encountered:
I'm sorry to say @liunx7594 that the tree's nearest() method is behaving correctly here. However, I do have an idea for adding a new method to the STRtree API in version 1.8.0, one that would allow you to exclude the query geometry from the result. See #1094 .
Expected behavior and actual behavior.
How to use strtree to find an element nearest to it but not its own?My code is as follows, what I expect to find is (1,1), not (0,0).
If I want to start from (0,0), find the nearest point (1,1), and then find the second nearest point (2,2), how do I operate?
Steps to reproduce the problem.
from shapely.strtree import STRtree
from shapely.geometry import Point
points=[Point(0,0),Point(1,1),Point(2,2)]
tree=STRtree(points)
pos=tree.nearest(Point(0,0))
print(pos)
#POINT (0 0)
Operating system
windows 10 20H2
python3.7.0 64-bit (conda)
Shapely version and provenance
Shapely-1.7.1 from pip install
The text was updated successfully, but these errors were encountered: