org.geotools.caching.spatialindex
Class AbstractSpatialIndex

java.lang.Object
  extended by org.geotools.caching.spatialindex.AbstractSpatialIndex
All Implemented Interfaces:
SpatialIndex
Direct Known Subclasses:
GridSpatialIndex

public abstract class AbstractSpatialIndex
extends java.lang.Object
implements SpatialIndex

This is a base class for implementing spatial indexes. It provides common routines useful for every type of indexes.

Author:
Christophe Rousson, SoC 2007, CRG-ULAVAL

Field Summary
static int ContainmentQuery
           
protected  int dimension
          Indexes can be n-dimensional, but queries and data should be consistent with regards to dimensions.
protected  Region infiniteRegion
           
static int IntersectionQuery
           
protected  NodeIdentifier root
          The node at the root of index.
protected  Node rootNode
           
protected  SpatialIndexStatistics stats
           
protected  Storage store
           
 
Fields inherited from interface org.geotools.caching.spatialindex.SpatialIndex
EPSILON, INDEX_TYPE_PROPERTY
 
Constructor Summary
AbstractSpatialIndex()
           
 
Method Summary
 void containmentQuery(Shape query, Visitor v)
          Traverse index to match data such as : query.contains(Data.getShape())
protected  void deleteNode(NodeIdentifier id)
           
 void flush()
          Cause pending write operations to happen immediately.
 Statistics getStatistics()
           
 Storage getStorage()
           
protected abstract  void insertData(NodeIdentifier n, java.lang.Object data, Shape shape)
          Insert new data into target node.
 void insertData(java.lang.Object data, Shape shape)
          Inserts data into the spatial index.
protected abstract  void insertDataOutOfBounds(java.lang.Object data, Shape shape)
          Insert new data with shape not contained in the current index.
 void intersectionQuery(Shape query, Visitor v)
          Traverse index to match data such as : query.intersects(Data.getShape())
 void nearestNeighborQuery(int k, Shape query, Visitor v)
           
 void nearestNeighborQuery(int k, Shape query, Visitor v, NearestNeighborComparator nnc)
           
 void pointLocationQuery(Point query, Visitor v)
          Traverse index to match data having query falling inside its shape, ie : Data.getShape().contains(query)
protected  void rangeQuery(int type, Shape query, Visitor v)
          Common algorithm used by both intersection and containment queries.
protected  Node readNode(NodeIdentifier id)
           
protected abstract  void visitData(Node n, Visitor v, Shape query, int type)
          Visit data associated with a node using given visitor.
protected  void writeNode(Node node)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.geotools.caching.spatialindex.SpatialIndex
clear, getIndexProperties, initializeFromStorage, isIndexValid
 

Field Detail

ContainmentQuery

public static final int ContainmentQuery
See Also:
Constant Field Values

IntersectionQuery

public static final int IntersectionQuery
See Also:
Constant Field Values

root

protected NodeIdentifier root
The node at the root of index. All others nodes should be direct or indirect children of this one.


rootNode

protected Node rootNode

store

protected Storage store

dimension

protected int dimension
Indexes can be n-dimensional, but queries and data should be consistent with regards to dimensions. This is the dimension of data shapes in the index, and should be considered final. (It is not because it makes things easier to initialize index from a serialized form).


infiniteRegion

protected Region infiniteRegion

stats

protected SpatialIndexStatistics stats
Constructor Detail

AbstractSpatialIndex

public AbstractSpatialIndex()
Method Detail

getStorage

public Storage getStorage()

intersectionQuery

public void intersectionQuery(Shape query,
                              Visitor v)
Description copied from interface: SpatialIndex
Traverse index to match data such as : query.intersects(Data.getShape())

Specified by:
intersectionQuery in interface SpatialIndex

containmentQuery

public void containmentQuery(Shape query,
                             Visitor v)
Description copied from interface: SpatialIndex
Traverse index to match data such as : query.contains(Data.getShape())

Specified by:
containmentQuery in interface SpatialIndex

pointLocationQuery

public void pointLocationQuery(Point query,
                               Visitor v)
Description copied from interface: SpatialIndex
Traverse index to match data having query falling inside its shape, ie : Data.getShape().contains(query)

Specified by:
pointLocationQuery in interface SpatialIndex

rangeQuery

protected void rangeQuery(int type,
                          Shape query,
                          Visitor v)
Common algorithm used by both intersection and containment queries.

Parameters:
type -
query -
v -

visitData

protected abstract void visitData(Node n,
                                  Visitor v,
                                  Shape query,
                                  int type)
Visit data associated with a node using given visitor. At this stage, we only know that node's MBR intersects query. This method is reponsible for iterating over node's data, if any, and for checking if data is actually part of the query result. Then it uses the visitor's visit() method on the selected data.

Parameters:
node - to visit
visitor - for callback
query -
type - of query, either containement or intersection (@see AbstractSpatialIndex)

nearestNeighborQuery

public void nearestNeighborQuery(int k,
                                 Shape query,
                                 Visitor v,
                                 NearestNeighborComparator nnc)
Specified by:
nearestNeighborQuery in interface SpatialIndex

nearestNeighborQuery

public void nearestNeighborQuery(int k,
                                 Shape query,
                                 Visitor v)
Specified by:
nearestNeighborQuery in interface SpatialIndex

insertData

public void insertData(java.lang.Object data,
                       Shape shape)
Inserts data into the spatial index.

Items with the same "data" and "shape" will be considered equal and only one copy of them will be added to the cache.

Specified by:
insertData in interface SpatialIndex
Parameters:
data - to insert
shape - associated with data
id - the id of the data

insertData

protected abstract void insertData(NodeIdentifier n,
                                   java.lang.Object data,
                                   Shape shape)
Insert new data into target node. Node may delegate to child nodes, if required. Implementation note : it is assumed arguments verify : node.getShape().contains(shape) So this must be checked before calling this method.

Parameters:
node - where to insert data
data -
shape - of data
id - of data

insertDataOutOfBounds

protected abstract void insertDataOutOfBounds(java.lang.Object data,
                                              Shape shape)
Insert new data with shape not contained in the current index. Some indexes may require to recreate the root or the index, depending on the type of index ...

Parameters:
data -
shape -
id -

getStatistics

public Statistics getStatistics()
Specified by:
getStatistics in interface SpatialIndex
Returns:
statistics about the index.

readNode

protected Node readNode(NodeIdentifier id)

writeNode

protected void writeNode(Node node)

deleteNode

protected void deleteNode(NodeIdentifier id)

flush

public void flush()
Description copied from interface: SpatialIndex
Cause pending write operations to happen immediately. Use this method to persist the index before disposal.

Specified by:
flush in interface SpatialIndex


Copyright © 1996-2010 Geotools. All Rights Reserved.