public class KdTree extends Object
This implementation supports detecting and snapping points which are closer than a given distance tolerance. If the same point (up to tolerance) is inserted more than once, it is snapped to the existing node. In other words, if a point is inserted which lies within the tolerance of a node already in the index, it is snapped to that node. When a point is snapped to a node then a new node is not created but the count of the existing node is incremented. If more than one node in the tree is within tolerance of an inserted point, the closest and then lowest node is snapped to.
| Constructor and Description |
|---|
KdTree()
Creates a new instance of a KdTree with a snapping tolerance of 0.0.
|
KdTree(double tolerance)
Creates a new instance of a KdTree, specifying a snapping distance tolerance.
|
| Modifier and Type | Method and Description |
|---|---|
KdNode |
insert(Coordinate
Inserts a new point in the kd-tree, with no data.
|
KdNode |
insert(Coordinate
Inserts a new point into the kd-tree.
|
boolean |
isEmpty()
Tests whether the index contains any items.
|
List |
query(Envelope
Performs a range search of the points in the index.
|
void |
query(Envelope
Performs a range search of the points in the index and visits all nodes found.
|
void |
query(Envelope
Performs a range search of the points in the index.
|
static Coordinate |
toCoordinates(Collection
Converts a collection of
KdNodes to an array of
Coordinates.
|
static Coordinate |
toCoordinates(Collection
Converts a collection of
KdNodes to an array of
Coordinates, specifying whether repeated nodes should be represented by multiple coordinates.
|
public KdTree()
public KdTree(double tolerance)
tolerance - the tolerance distance for considering two points equal
public static Coordinate[] toCoordinates(Collection kdnodes)
KdNodes to an array of
Coordinates.
kdnodes - a collection of nodes
public static Coordinate[] toCoordinates(Collection kdnodes, boolean includeRepeated)
KdNodes to an array of
Coordinates, specifying whether repeated nodes should be represented by multiple coordinates.
kdnodes - a collection of nodes
includeRepeated - true if repeated nodes should be included multiple times
public boolean isEmpty()
public KdNodeinsert(Coordinate p)
p - the point to insert
public KdNodeinsert(Coordinate p, Object data)
p - the point to insert
data - a data item for the point
public void query(EnvelopequeryEnv, KdNodeVisitor visitor)
queryEnv - the range rectangle to query
a - visitor to visit all nodes found by the search
public Listquery(Envelope queryEnv)
queryEnv - the range rectangle to query