public class MortonCode<P extends C2D>
extends java.lang.Object
Morton codes are labels for the nodes of a QuadTree. A QuadTree is a partition of a spatial extent by recursively
decomposing it into four equal quadrants. A QuadTree is determined by a spatial extent and depth of the tree (the
number of recursive subdivisions of the extent). Both are specified by the MortonContext passed during
construction of instances of this class.
The Morton code of a Geometry can be viewed as a path to the quadrant containing the envelope of that
Geometry. The left-most character of the code contains the label of the quadrant at depth 1, the second at
depth 2, etc. If the Morton code is the empty string, then the envelope fits in no single quandrant of the QuadTree.
At each level the four quadrants are labeled:
| Modifier and Type | Field and Description |
|---|---|
private double |
gridHeight
The height of the leaves of the quadtree implied by the MortonContext
|
private double |
gridWidth
The width of the leaves of the quadtree implied by the MortonContext
|
private int |
maxGridCellCoordinate |
private MortonContext<P> |
mortonContext |
private java.util.regex.Pattern |
VALID_MORTONCODE_PATTERN |
| Constructor and Description |
|---|
MortonCode(MortonContext<P> mortonContext)
Constructs an instance with the given
Mortoncontext
|
| Modifier and Type | Method and Description |
|---|---|
private void |
checkForNull(java.lang.Object object) |
private void |
checkWithinExtent(Envelope<P> envelope) |
private void |
checkWithinExtent(P pos) |
private java.lang.String |
commonMortonCodePrefixAsString(long mc1,
long mc2)
Returns the common prefix of two morton codes.
|
Envelope<P> |
envelopeOf(java.lang.String mortoncode)
Returns the extent that corresponds to the specified morton code
|
private Envelope<P> |
envelopeOf(java.lang.String mortoncode,
int index,
Envelope<P> extent) |
private int |
getCol(double x) |
int |
getMaxLength()
Returns the maximum length of a morton code generated by this instance.
|
private int |
getRow(double y) |
private long |
interleave(int col,
int row) |
private boolean |
isValidMortonCode(java.lang.String mortoncode) |
java.lang.String |
ofEnvelope(Envelope<P> envelope)
Returns the Morton code for the specified
Envelope. |
java.lang.String |
ofGeometry(Geometry<P> geometry)
Returns the Morton code for the specified
Geometry. |
java.lang.String |
ofPosition(P pos)
Returns the Morton code for the specified
Point. |
private java.lang.String |
pointMortonCodeAsString(long interleaved) |
private java.lang.String |
toRadix4String(long interleaved,
int level)
Transforms the morton code long value into a string such that each character is a label for the quadrant.
|
private final java.util.regex.Pattern VALID_MORTONCODE_PATTERN
private final MortonContext<P extends C2D> mortonContext
private final double gridWidth
private final double gridHeight
private final int maxGridCellCoordinate
public MortonCode(MortonContext<P> mortonContext)
Mortoncontext
The specified MortonCode determines a QuadTree for which
this instance calculates labels.
mortonContext - the context to use when calculating morton codes.public java.lang.String ofGeometry(Geometry<P> geometry)
Geometry.
This method is equivalent to ofEnvelope(geometry.getEnvelope()).
geometry - a {code Geometry} value.Geometry.java.lang.IllegalArgumentException - if the geometry is null, or has an envelope which is not contained in
the spatial extent of this instance's MortonContextpublic java.lang.String ofEnvelope(Envelope<P> envelope)
Envelope.envelope - an Envelope value.Envelope value.java.lang.IllegalArgumentException - if the value of the envelope parameter is null, or is not contained in
the spatial extent of this instance's MortonContextpublic java.lang.String ofPosition(P pos)
Point.pos - an Point value.Point value.java.lang.IllegalArgumentException - if the value of the point parameter is null, or is not contained in
the spatial extent of this instance's MortonContextpublic int getMaxLength()
public Envelope<P> envelopeOf(java.lang.String mortoncode)
mortoncode - a morton code Stringprivate Envelope<P> envelopeOf(java.lang.String mortoncode, int index, Envelope<P> extent)
private boolean isValidMortonCode(java.lang.String mortoncode)
private int getRow(double y)
private int getCol(double x)
private void checkWithinExtent(P pos)
private long interleave(int col,
int row)
private java.lang.String pointMortonCodeAsString(long interleaved)
private java.lang.String commonMortonCodePrefixAsString(long mc1,
long mc2)
The common prefix is the morton code for the quadtree node that is the common ancestor node for the nodes specified by the argument morton codes.
mc1 - first mortonCode (as an interleaved long)mc2 - second mortonCodeprivate java.lang.String toRadix4String(long interleaved,
int level)
Long.toString(interleaved, 4) was not used since this turns morton code '001' into '1')interleaved - the morton code as a longlevel - the level of the morton codeprivate void checkForNull(java.lang.Object object)