Class RTreeNode
java.lang.Object
org.apache.sis.io.wkt.FormattableObject
org.apache.sis.geometry.AbstractEnvelope
org.apache.sis.geometry.GeneralEnvelope
org.apache.sis.internal.referencing.RTreeNode
- All Implemented Interfaces:
Serializable,Cloneable,Emptiable,org.opengis.geometry.Envelope
Placeholder for a RTree. This simple implementation is not designed for scalability or performance.
This class is there for minimal service, to be replaced in some future Apache SIS version by a more
sophisticated tree. Current version of this class is okay for small trees where big nodes are added
before small nodes.
A RTreeNode instance is used as the root of the tree. Children nodes are stored as a linked list
(the list is implemented by the sibling field, which reference the next element in the list).
Possible evolution:
a future version could avoid extending
GeneralEnvelope. Instead, we could provide abstract
contains(…) methods and let subclasses define them, with possibly more efficient implementations.
We would still need an implementation that delegate to GeneralEnvelope since that class has the
advantage of handling envelopes crossing the anti-meridian.- Since:
- 1.1
- Version:
- 1.1
- Author:
- Martin Desruisseaux (Geomatys)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRTreeNode(org.opengis.geometry.Envelope area) Creates a new node for the given envelope. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdds the given node to the tree having this node as the root.booleanCompares this node with the given object for equality, ignoring the parent and the siblings.final RTreeNodefinish()Finishes the construction of the tree.protected StringFormats this envelope as a "DOMAIN" element (non-standard).Returns the immediate children of this node, or an empty list if none.org.opengis.referencing.crs.CoordinateReferenceSystemReturns the envelope coordinate reference system, ornullif unknown.intReturns the length of coordinate sequence (the number of entries) in this envelope.doublegetLower(int dimension) Returns the limit in the direction of decreasing coordinate values in the specified dimension.doublegetMaximum(int dimension) Returns the maximal coordinate value for the specified dimension.doublegetMedian(int dimension) Returns the median coordinate along the specified dimension.doublegetMinimum(int dimension) Returns the minimal coordinate value for the specified dimension.final RTreeNodeReturns the parent of this node, ornullif none.doublegetSpan(int dimension) Returns the envelope span (typically width or height) along the specified dimension.doublegetUpper(int dimension) Returns the limit in the direction of increasing coordinate values in the specified dimension.inthashCode()Returns a hash code value based on the this node and its children, ignoring the parent and the siblings.booleanisAllNaN()Returnsfalseif at least one coordinate value is not NaN.booleanisEmpty()Determines whether or not this envelope is empty.static RTreeNodeReturns the node that contains the given position, ornullif none.toString()Returns a string representation of this node and its children as a tree.final TreeTabletoTree()Returns a representation of this node and its children as a tree.static voidExecutes the given action on the given node, all its children and all its siblings.Methods inherited from class org.apache.sis.geometry.GeneralEnvelope
add, add, castOrCopy, clone, horizontal, intersect, normalize, setCoordinateReferenceSystem, setEnvelope, setEnvelope, setRange, setTimeRange, setToInfinite, setToNaN, simplify, subEnvelope, translate, wraparoundMethods inherited from class org.apache.sis.geometry.AbstractEnvelope
contains, contains, contains, equals, getLowerCorner, getMedian, getSpan, getTimeRange, getUpperCorner, intersects, intersects, toSimpleEnvelopesMethods inherited from class org.apache.sis.io.wkt.FormattableObject
print, toString, toWKT
-
Constructor Details
-
RTreeNode
public RTreeNode(org.opengis.geometry.Envelope area) Creates a new node for the given envelope.- Parameters:
area- the region covered by this node.
-
-
Method Details
-
getParent
Returns the parent of this node, ornullif none.- Returns:
- the parent of this node, or
nullif none.
-
getChildren
Returns the immediate children of this node, or an empty list if none.- Returns:
- the immediate children of this node.
-
walk
Executes the given action on the given node, all its children and all its siblings.- Parameters:
node- the node on which to execute the action, ornullif none.action- the action to execute.
-
addNode
Adds the given node to the tree having this node as the root. This method assumes that this node or its siblings are likely to contain the nodes given to this method. This method will work even if this assumption does not hold, but the tree will be inefficient in such case.A "professional" R-Tree would make a better effort for creating a balanced tree here. Current version of this class uses a simple algorithm, okay for small trees where big nodes are added before small nodes. This is not a good general purpose R-Tree.
- Parameters:
node- the node to add to this tree. If this node has sibling, they will be added too.- See Also:
-
finish
Finishes the construction of the tree. This method should be invoked only on the instance on whichaddNode(RTreeNode)has been invoked. It performs the following tasks:- Verify that all nodes have the same CRS or null CRS. An exception is thrown if incompatible CRS are found. This method does not verify the number of dimensions; this check should have been done by the caller.
- Set the CRS of all nodes to the common value found in previous step.
- Ensure that the tree has a single root, by creating a synthetic parent if necessary.
- Returns:
- the root of the tree, which is
thisif this node has no sibling.
-
locate
Returns the node that contains the given position, ornullif none. The given node does not need to be the root of the tree; it can be any node. This method will check that node first. If it does not contain the position, then this method goes up in the parent nodes.If consecutive positions are close to each other, then a good strategy is to give to this method the most recently used node.
- Parameters:
node- any node in the tree. Should be node most likely to contain the position.pos- the position of the node to locate, ornullif none.- Returns:
- the smallest node containing the given position, or
nullif none.
-
hashCode
public int hashCode()Returns a hash code value based on the this node and its children, ignoring the parent and the siblings.- Returns:
- a hash code value for this node and its children.
-
equals
Compares this node with the given object for equality, ignoring the parent and the siblings.- Parameters:
obj- the object to compare with this node.- Returns:
- whether the two objects are of the same class, have equal envelope and equal children list.
-
formatTo
Formats this envelope as a "DOMAIN" element (non-standard).- Overrides:
formatToin classAbstractEnvelope- Parameters:
formatter- the formatter where to format the inner content of this envelope.- Returns:
- the pseudo-WKT keyword, which is
"Box"for this element. - See Also:
-
toString
Returns a string representation of this node and its children as a tree. This method is for debugging purposes.- Returns:
- a string representation of this node and all its children.
-
toTree
Returns a representation of this node and its children as a tree. This is mostly for debugging purposes.- Returns:
- a tree representation of this node and all its children.
-
getDimension
public int getDimension()Returns the length of coordinate sequence (the number of entries) in this envelope. This information is available even when the coordinate reference system is unknown.- Specified by:
getDimensionin interfaceorg.opengis.geometry.Envelope- Returns:
- the dimensionality of this envelope.
-
getCoordinateReferenceSystem
public org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()Returns the envelope coordinate reference system, ornullif unknown. If non-null, it shall be the same as lower corner and upper corner CRS.- Specified by:
getCoordinateReferenceSystemin interfaceorg.opengis.geometry.Envelope- Returns:
- the envelope CRS, or
nullif unknown.
-
getLower
Returns the limit in the direction of decreasing coordinate values in the specified dimension. This is usually the algebraic minimum, except if this envelope spans the anti-meridian.- Specified by:
getLowerin classAbstractEnvelope- Parameters:
dimension- the dimension for which to obtain the coordinate value.- Returns:
- the starting coordinate value at the given dimension.
- Throws:
IndexOutOfBoundsException- if the given index is negative or is equal or greater than the envelope dimension.- See Also:
-
getUpper
Returns the limit in the direction of increasing coordinate values in the specified dimension. This is usually the algebraic maximum, except if this envelope spans the anti-meridian.- Specified by:
getUpperin classAbstractEnvelope- Parameters:
dimension- the dimension for which to obtain the coordinate value.- Returns:
- the starting coordinate value at the given dimension.
- Throws:
IndexOutOfBoundsException- if the given index is negative or is equal or greater than the envelope dimension.- See Also:
-
getMinimum
Returns the minimal coordinate value for the specified dimension. In the typical case of non-empty envelopes not crossing the anti-meridian, this method returns theAbstractEnvelope.getLower(int)value verbatim. In the case of envelope crossing the anti-meridian, this method returns the axis minimum value. If the range in the given dimension is invalid, then this method returnsNaN.- Specified by:
getMinimumin interfaceorg.opengis.geometry.Envelope- Overrides:
getMinimumin classAbstractEnvelope- Parameters:
dimension- the dimension for which to obtain the coordinate value.- Returns:
- the minimal coordinate value at the given dimension.
- Throws:
IndexOutOfBoundsException- if the given index is negative or is equal or greater than the envelope dimension.
-
getMaximum
Returns the maximal coordinate value for the specified dimension. In the typical case of non-empty envelopes not crossing the anti-meridian, this method returns theAbstractEnvelope.getUpper(int)value verbatim. In the case of envelope crossing the anti-meridian, this method returns the axis maximum value. If the range in the given dimension is invalid, then this method returnsNaN.- Specified by:
getMaximumin interfaceorg.opengis.geometry.Envelope- Overrides:
getMaximumin classAbstractEnvelope- Parameters:
dimension- the dimension for which to obtain the coordinate value.- Returns:
- the maximal coordinate value at the given dimension.
- Throws:
IndexOutOfBoundsException- if the given index is negative or is equal or greater than the envelope dimension.
-
getMedian
Returns the median coordinate along the specified dimension. In most cases, the result is equal (minus rounding error) to:Crossing the anti-meridian of a Geographic CRS
If upper < lower and the range meaning for the requested dimension is wraparound, then the median calculated above is actually in the middle of the space outside the envelope. In such cases, this method shifts the median value by half of the periodicity (180° in the longitude case) in order to switch from outer space to inner space. If the axis range meaning is notWRAPAROUND, then this method returnsNaN.- Specified by:
getMedianin interfaceorg.opengis.geometry.Envelope- Overrides:
getMedianin classAbstractEnvelope- Parameters:
dimension- the dimension for which to obtain the coordinate value.- Returns:
- the median coordinate at the given dimension, or
Double.NaN. - Throws:
IndexOutOfBoundsException- if the given index is negative or is equal or greater than the envelope dimension.- See Also:
-
getSpan
Returns the envelope span (typically width or height) along the specified dimension. In most cases, the result is equal (minus rounding error) to:Crossing the anti-meridian of a Geographic CRS
If upper < lower and the range meaning for the requested dimension is wraparound, then the span calculated above is negative. In such cases, this method adds the periodicity (typically 360° of longitude) to the span. If the result is a positive number, it is returned. Otherwise this method returnsNaN.- Specified by:
getSpanin interfaceorg.opengis.geometry.Envelope- Overrides:
getSpanin classAbstractEnvelope- Parameters:
dimension- the dimension for which to obtain the span.- Returns:
- the span (typically width or height) at the given dimension, or
Double.NaN. - Throws:
IndexOutOfBoundsException- if the given index is negative or is equal or greater than the envelope dimension.
-
isEmpty
public boolean isEmpty()Determines whether or not this envelope is empty. An envelope is empty if it has zero dimension, or if the span of at least one axis is negative, 0 orNaN.Note: Strictly speaking, there is an ambiguity if a span isIfNaNor if the envelope contains both 0 and infinite spans (since 0⋅∞ =NaN). In such cases, this method arbitrarily ignores the infinite values and returnstrue.isEmpty()returnsfalse, thenAbstractEnvelope.isAllNaN()is guaranteed to also returnfalse. However, the converse is not always true.- Specified by:
isEmptyin interfaceEmptiable- Overrides:
isEmptyin classAbstractEnvelope- Returns:
trueif this envelope is empty.- See Also:
-
isAllNaN
public boolean isAllNaN()Returnsfalseif at least one coordinate value is not NaN. ThisisAllNaN()check is different than theAbstractEnvelope.isEmpty()check since it returnsfalsefor a partially initialized envelope, whileisEmpty()returnsfalseonly after all dimensions have been initialized. More specifically, the following rules apply:- If
isAllNaN() == true, thenisEmpty() == true - If
isEmpty() == false, thenisAllNaN() == false - The converse of the above-cited rules are not always true.
- Overrides:
isAllNaNin classAbstractEnvelope- Returns:
trueif this envelope has NaN values.- See Also:
- If
-