Skip to content

How to use strtree to find an element nearest to it but not its own? #1106

@liunx7594

Description

@liunx7594

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions