public final class RTree extends Object
BoundedObject
is used here as
a decorator for the object we want to store in the r-tree.
public static class BoundedObject<T> { private finalEnvelope
m_envelope; private final T m_data; public BoundedObject(Envelope
envelope, T data) { m_envelope = envelope; m_data = data; } publicEnvelope
getEnvelope() { return m_envelope; } public T getData() { return m_data; } }
The r-tree requires a decorator that knows how to get the bounds of the stored object:
public static class BoundedObjectDecorator<T> implements IEnvelopeDecorator<BoundedObject<T>> {
public Envelope
getEnvelope(BoundedObject<T> o) {
return o.getEnvelope();
}
}
The BoundedObject
can now be stored in the r-tree:
// create the r-tree with the decorator IEnvelopeDecorator<BoundedObject<String
>> decorator = new BoundedObjectDecorator<>(); RTree<BoundedObject<String
>> rTree = new RTree<>(decorator); // add some objects to the r-treeSpatialInfo
spatialInfo =SpatialInfo
.create(CoordSysConstants
.longLatWGS84); rTree.add(new BoundedObject<>(newEnvelope
(-79.761933, 40.496604, -71.856138, 45.012508, spatialInfo), "New York")); rTree.add(new BoundedObject<>(newEnvelope
(-109.060278, 36.992442, -102.041495, 41.003444, spatialInfo), "Colorado")); rTree.add(new BoundedObject<>(newEnvelope
(-109.050191, 31.332216, -103.001970, 37.000317, spatialInfo), "New Mexico")); // retrieve the objects from the r-tree with an envelope search RTreeCursor<BoundedObject<String
>> cursor = rTree.search( new RTreeEnvelopeSearch(newEnvelope
(-104.743840, 34.705783, -99.889056, 37.902327, spatialInfo))); while (cursor.hasNext()) { BoundedObject<String
> o = cursor.next(); }
Constructor and Description |
---|
RTree(IEnvelopeDecorator decorator)
Creates a r-tree structure from the specified envelope decorator which help
getting envelope from the user-defined objects stored in the leaf node of
r-tree.
|
RTree(IEnvelopeDecorator decorator,
int maxCapacity,
int minCapacity)
Creates a r-tree structure with specified envelope decorator, maximum capacity
and minimum capacity.
|
RTree(IEnvelopeDecorator decorator,
IRTreeHelper helper)
Creates a r-tree implementation with the specified decorator and helper.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Object o)
Adds a data item into this tree.
|
void |
clear()
Clear up this tree.
|
Envelope |
getEnvelope()
Gets the entire envelope of this r-tree.
|
void |
remove(Object o)
Removes the specified data item from this tree.
|
RTreeCursor |
search(IRTreeEnvelopeSearch rs)
Gets a r-tree search curosr based on the specified search criteria.
|
public RTree(IEnvelopeDecorator decorator)
decorator
- decorator to get envelopes from user-defined objects in leaf node.public RTree(IEnvelopeDecorator decorator, int maxCapacity, int minCapacity)
decorator
- decorator to get envelopes from user-defined objects in leaf node.maxCapacity
- The maximum capacity of each node in this tree.minCapacity
- The minimum capacity of each node in this tree. Should not be
great than maxCapacity/2, otherwise it is set to maxCapacity/2.public RTree(IEnvelopeDecorator decorator, IRTreeHelper helper)
decorator
- decorator to get envelopes from user-defined objects in leaf node.helper
- The helper that handles the underlying structure of the r-tree data.public void remove(Object o)
o
- the data item will be deleted if can be found in this tree.public void add(Object o)
o
- the data item will be inserted to this tree.public RTreeCursor search(IRTreeEnvelopeSearch rs)
rs
- search criteria. An IRTreeEnvelopeSearch
instance.public Envelope getEnvelope()
Envelope
object.public void clear()
© 2007, 2022 Precisely. All rights reserved.