Class AbstractSTRtree
- java.lang.Object
-
- org.locationtech.jts.index.strtree.AbstractSTRtree
-
- All Implemented Interfaces:
java.io.Serializable
public abstract class AbstractSTRtree extends java.lang.Object implements java.io.SerializableBase class for STRtree and SIRtree. STR-packed R-trees are described in: P. Rigaux, Michel Scholl and Agnes Voisard. Spatial Databases With Application To GIS. Morgan Kaufmann, San Francisco, 2002.This implementation is based on
Boundables rather thanAbstractNodes, because the STR algorithm operates on both nodes and data, both of which are treated as Boundables.This class is thread-safe. Building the tree is synchronized, and querying is stateless.
- Version:
- 1.7
- See Also:
STRtree,SIRtree, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceAbstractSTRtree.IntersectsOpA test for intersection between two bounds, necessary because subclasses of AbstractSTRtree have different implementations of bounds.
-
Field Summary
Fields Modifier and Type Field Description private booleanbuiltprivate static intDEFAULT_NODE_CAPACITYprivate java.util.ArrayListitemBoundablesSet to null when index is built, to avoid retaining memory.private intnodeCapacityprotected AbstractNoderootprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description AbstractSTRtree()Constructs an AbstractSTRtree with the default node capacity.AbstractSTRtree(int nodeCapacity)Constructs an AbstractSTRtree with the specified maximum number of child nodes that a node may have
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.util.ListboundablesAtLevel(int level)private voidboundablesAtLevel(int level, AbstractNode top, java.util.Collection boundables)voidbuild()Creates parent nodes, grandparent nodes, and so forth up to the root node, for the data that has been inserted into the tree.protected static intcompareDoubles(double a, double b)private AbstractNodecreateHigherLevels(java.util.List boundablesOfALevel, int level)Creates the levels higher than the given levelprotected abstract AbstractNodecreateNode(int level)protected java.util.ListcreateParentBoundables(java.util.List childBoundables, int newLevel)Sorts the childBoundables then divides them into groups of size M, where M is the node capacity.protected intdepth()protected intdepth(AbstractNode node)protected abstract java.util.ComparatorgetComparator()protected abstract AbstractSTRtree.IntersectsOpgetIntersectsOp()intgetNodeCapacity()Returns the maximum number of child nodes that a node may haveAbstractNodegetRoot()protected voidinsert(java.lang.Object bounds, java.lang.Object item)booleanisEmpty()Tests whether the index contains any items.java.util.ListitemsTree()Gets a tree structure (as a nested list) corresponding to the structure of the items and nodes in this tree.private java.util.ListitemsTree(AbstractNode node)protected AbstractNodelastNode(java.util.List nodes)protected java.util.Listquery(java.lang.Object searchBounds)Also builds the tree, if necessary.protected voidquery(java.lang.Object searchBounds, ItemVisitor visitor)Also builds the tree, if necessary.private voidqueryInternal(java.lang.Object searchBounds, AbstractNode node, java.util.List matches)private voidqueryInternal(java.lang.Object searchBounds, AbstractNode node, ItemVisitor visitor)protected booleanremove(java.lang.Object searchBounds, java.lang.Object item)Removes an item from the tree.private booleanremove(java.lang.Object searchBounds, AbstractNode node, java.lang.Object item)private booleanremoveItem(AbstractNode node, java.lang.Object item)protected intsize()protected intsize(AbstractNode node)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
root
protected AbstractNode root
-
built
private boolean built
-
itemBoundables
private java.util.ArrayList itemBoundables
Set to null when index is built, to avoid retaining memory.
-
nodeCapacity
private int nodeCapacity
-
DEFAULT_NODE_CAPACITY
private static final int DEFAULT_NODE_CAPACITY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractSTRtree
public AbstractSTRtree()
Constructs an AbstractSTRtree with the default node capacity.
-
AbstractSTRtree
public AbstractSTRtree(int nodeCapacity)
Constructs an AbstractSTRtree with the specified maximum number of child nodes that a node may have- Parameters:
nodeCapacity- the maximum number of child nodes in a node
-
-
Method Detail
-
build
public void build()
Creates parent nodes, grandparent nodes, and so forth up to the root node, for the data that has been inserted into the tree. Can only be called once, and thus can be called only after all of the data has been inserted into the tree.
-
createNode
protected abstract AbstractNode createNode(int level)
-
createParentBoundables
protected java.util.List createParentBoundables(java.util.List childBoundables, int newLevel)Sorts the childBoundables then divides them into groups of size M, where M is the node capacity.
-
lastNode
protected AbstractNode lastNode(java.util.List nodes)
-
compareDoubles
protected static int compareDoubles(double a, double b)
-
createHigherLevels
private AbstractNode createHigherLevels(java.util.List boundablesOfALevel, int level)
Creates the levels higher than the given level- Parameters:
boundablesOfALevel- the level to build onlevel- the level of the Boundables, or -1 if the boundables are item boundables (that is, below level 0)- Returns:
- the root, which may be a ParentNode or a LeafNode
-
getRoot
public AbstractNode getRoot()
-
getNodeCapacity
public int getNodeCapacity()
Returns the maximum number of child nodes that a node may have
-
isEmpty
public boolean isEmpty()
Tests whether the index contains any items. This method does not build the index, so items can still be inserted after it has been called.- Returns:
- true if the index does not contain any items
-
size
protected int size()
-
size
protected int size(AbstractNode node)
-
depth
protected int depth()
-
depth
protected int depth(AbstractNode node)
-
insert
protected void insert(java.lang.Object bounds, java.lang.Object item)
-
query
protected java.util.List query(java.lang.Object searchBounds)
Also builds the tree, if necessary.
-
query
protected void query(java.lang.Object searchBounds, ItemVisitor visitor)Also builds the tree, if necessary.
-
getIntersectsOp
protected abstract AbstractSTRtree.IntersectsOp getIntersectsOp()
- Returns:
- a test for intersection between two bounds, necessary because subclasses of AbstractSTRtree have different implementations of bounds.
- See Also:
AbstractSTRtree.IntersectsOp
-
queryInternal
private void queryInternal(java.lang.Object searchBounds, AbstractNode node, java.util.List matches)
-
queryInternal
private void queryInternal(java.lang.Object searchBounds, AbstractNode node, ItemVisitor visitor)
-
itemsTree
public java.util.List itemsTree()
Gets a tree structure (as a nested list) corresponding to the structure of the items and nodes in this tree.The returned
Lists contain eitherObjectitems, or Lists which correspond to subtrees of the tree Subtrees which do not contain any items are not included.Builds the tree if necessary.
- Returns:
- a List of items and/or Lists
-
itemsTree
private java.util.List itemsTree(AbstractNode node)
-
remove
protected boolean remove(java.lang.Object searchBounds, java.lang.Object item)Removes an item from the tree. (Builds the tree, if necessary.)
-
removeItem
private boolean removeItem(AbstractNode node, java.lang.Object item)
-
remove
private boolean remove(java.lang.Object searchBounds, AbstractNode node, java.lang.Object item)
-
boundablesAtLevel
protected java.util.List boundablesAtLevel(int level)
-
boundablesAtLevel
private void boundablesAtLevel(int level, AbstractNode top, java.util.Collection boundables)- Parameters:
level- -1 to get items
-
getComparator
protected abstract java.util.Comparator getComparator()
-
-