public class Quadtree extends Objectimplements SpatialIndex , Serializable
Geometrys can be indexed by using their
Envelopes. Any type of Object can also be indexed as long as it has an extent that can be represented by an
Envelope.
This Quadtree index provides a primary filter for range rectangle queries. The various query methods return a list of all items which may intersect the query rectangle. Note that it may thus return items which do not in fact intersect the query rectangle. A secondary filter is required to test for actual intersection between the query rectangle and the envelope of each candidate item. The secondary filter may be performed explicitly, or it may be provided implicitly by subsequent operations executed on the items (for instance, if the index query is followed by computing a spatial predicate between the query geometry and tree items, the envelope intersection check is performed automatically.
This implementation does not require specifying the extent of the inserted items beforehand. It will automatically expand to accomodate any extent of dataset.
This data structure is also known as an MX-CIF quadtree following the terminology of Samet and others.
| Constructor and Description |
|---|
Quadtree()
Constructs a Quadtree with zero items.
|
| Modifier and Type | Method and Description |
|---|---|
int |
depth()
Returns the number of levels in the tree.
|
static Envelope |
ensureExtent(Envelope
Ensure that the envelope for the inserted item has non-zero extents.
|
void |
insert(Envelope
Adds a spatial item with an extent specified by the given
Envelope to the index
|
boolean |
isEmpty()
Tests whether the index contains any items.
|
List |
query(Envelope
Queries the tree and returns items which may lie in the given search envelope.
|
void |
query(Envelope
Queries the tree and visits items which may lie in the given search envelope.
|
List |
queryAll()
Return a list of all items in the Quadtree
|
boolean |
remove(Envelope
Removes a single item from the tree.
|
int |
size()
Returns the number of items in the tree.
|
public static EnvelopeensureExtent(Envelope itemEnv, double minExtent)
public int depth()
public boolean isEmpty()
public int size()
public void insert(EnvelopeitemEnv, Object item)
SpatialIndex
Envelope to the index
public boolean remove(EnvelopeitemEnv, Object item)
remove in interface
SpatialIndex
itemEnv - the Envelope of the item to be removed
item - the item to remove
true if the item was found (and thus removed)
public Listquery(Envelope searchEnv)
query in interface
SpatialIndex
searchEnv - the envelope of the desired query area.
public void query(EnvelopesearchEnv, ItemVisitor visitor)
query in interface
SpatialIndex
searchEnv - the envelope of the desired query area.
visitor - a visitor object which is passed the visited items
public ListqueryAll()