Class MortonCode<P extends C2D>


  • public class MortonCode<P extends C2D>
    extends Object
    Calculates the Morton code (Morton-order or Z-order) of Geometries

    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:

    • O : lower-left quadrant
    • 1 : upper-left quadrant
    • 2 : lower-right quadrant
    • 3 : upper-right quadrant
    Author:
    Karel Maesen, Geovise BVBA creation-date: 2/19/13
    • Constructor Detail

      • MortonCode

        public MortonCode​(MortonContext<P> mortonContext)
        Constructs an instance with the given Mortoncontext

        The specified MortonCode determines a QuadTree for which this instance calculates labels.

        Parameters:
        mortonContext - the context to use when calculating morton codes.
    • Method Detail

      • ofGeometry

        public String ofGeometry​(Geometry<P> geometry)
        Returns the Morton code for the specified Geometry.

        This method is equivalent to ofEnvelope(geometry.getEnvelope()).

        Parameters:
        geometry - a {code Geometry} value.
        Returns:
        the morton code for the envelope of the specified Geometry.
        Throws:
        IllegalArgumentException - if the geometry is null, or has an envelope which is not contained in the spatial extent of this instance's MortonContext
      • ofEnvelope

        public String ofEnvelope​(Envelope<P> envelope)
        Returns the Morton code for the specified Envelope.
        Parameters:
        envelope - an Envelope value.
        Returns:
        the morton code for the specified Envelope value.
        Throws:
        IllegalArgumentException - if the value of the envelope parameter is null, or is not contained in the spatial extent of this instance's MortonContext
      • ofPosition

        public String ofPosition​(P pos)
        Returns the Morton code for the specified Point.
        Parameters:
        pos - an Point value.
        Returns:
        the morton code for the specified Point value.
        Throws:
        IllegalArgumentException - if the value of the point parameter is null, or is not contained in the spatial extent of this instance's MortonContext
      • getMaxLength

        public int getMaxLength()
        Returns the maximum length of a morton code generated by this instance.
        Returns:
        the maximum length of a morton code generated by this instance.
      • envelopeOf

        public Envelope<P> envelopeOf​(String mortoncode)
        Returns the extent that corresponds to the specified morton code
        Parameters:
        mortoncode - a morton code String
        Returns:
        the envelope representing the specified morton code