# geos::index::quadtree::Quadtree Class Reference

A Quadtree is a spatial index structure for efficient querying of 2D rectangles. If other kinds of spatial objects need to be indexed they can be represented by their envelopes. More...

`#include <Quadtree.h>`

Inheritance diagram for geos::index::quadtree::Quadtree:

List of all members.

## Public Member Functions

| Quadtree ()
| Constructs a Quadtree with zero items.
int | depth ()
| Returns the number of levels in the tree.
int | size ()
| Returns the number of items in the tree.
void | insert (const geom::Envelope *itemEnv, void *item)
| Adds a spatial item with an extent specified by the given Envelope to the index.
void | query (const geom::Envelope *searchEnv, std::vector< void * > &ret)
| Queries the index for all items whose extents intersect the given search Envelope.
void | query (const geom::Envelope *searchEnv, ItemVisitor &visitor)
| Queries the index for all items whose extents intersect the given search Envelope and applies an ItemVisitor to them.
bool | remove (const geom::Envelope *itemEnv, void *item)
std::vector< void * > * | queryAll ()
| Return a list of all items in the Quadtree.
std::string | toString () const

## Static Public Member Functions

static geom::Envelope * | ensureExtent (const geom::Envelope *itemEnv, double minExtent)
| Ensure that the envelope for the inserted item has non-zero extents.

## Detailed Description

A Quadtree is a spatial index structure for efficient querying of 2D rectangles. If other kinds of spatial objects need to be indexed they can be represented by their envelopes.

The quadtree structure is used to provide a primary filter for range rectangle queries. The query() method returns a list of all objects which may intersect the query rectangle. Note that it may return objects which do not in fact intersect. A secondary filter is required to test for exact intersection. Of course, this secondary filter may consist of other tests besides intersection, such as testing other kinds of spatial relationships.

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 usage of Samet and others.

## Member Function Documentation

static geom::Envelope* geos::index::quadtree::Quadtree::ensureExtent | ( | const geom::Envelope * | itemEnv,
|  | double | minExtent |
| ) |  |  | `[static]`

Ensure that the envelope for the inserted item has non-zero extents.

Use the current minExtent to pad the envelope, if necessary. Can return a new Envelope or the given one (casted to non-const).

void geos::index::quadtree::Quadtree::query | ( | const geom::Envelope * | searchEnv,
|  | std::vector< void * > & |  |
| ) |  |  | `[virtual]`

Queries the index for all items whose extents intersect the given search Envelope.

Note that some kinds of indexes may also return objects which do not in fact intersect the query envelope.

Parameters:

  | searchEnv | the envelope to query for

Returns:
  a list of the items found by the query in a newly allocated vector

Implements geos::index::SpatialIndex.

void geos::index::quadtree::Quadtree::query | ( | const geom::Envelope * | searchEnv,
|  | ItemVisitor & | visitor |
| ) |  |  | `[inline, virtual]`

Queries the index for all items whose extents intersect the given search Envelope and applies an ItemVisitor to them.

Note that some kinds of indexes may also return objects which do not in fact intersect the query envelope.

Parameters:

  | searchEnv | the envelope to query for
  | visitor | a visitor object to apply to the items found

Implements geos::index::SpatialIndex.

bool geos::index::quadtree::Quadtree::remove | ( | const geom::Envelope * | itemEnv,
|  | void * | item |
| ) |  |  | `[virtual]`

Removes a single item from the tree.

Parameters:

  | itemEnv | the Envelope of the item to remove
  | item | the item to remove

Returns:
  `true` if the item was found

Implements geos::index::SpatialIndex.

The documentation for this class was generated from the following file:

- Quadtree.h