Class CoordinateSequences


  • public class CoordinateSequences
    extends java.lang.Object
    Utility functions for manipulating CoordinateSequences
    Version:
    1.7
    • Constructor Detail

      • CoordinateSequences

        public CoordinateSequences()
    • Method Detail

      • reverse

        public static void reverse​(CoordinateSequence seq)
        Reverses the coordinates in a sequence in-place.
        Parameters:
        seq - the coordinate sequence to reverse
      • swap

        public static void swap​(CoordinateSequence seq,
                                int i,
                                int j)
        Swaps two coordinates in a sequence.
        Parameters:
        seq - the sequence to modify
        i - the index of a coordinate to swap
        j - the index of a coordinate to swap
      • copy

        public static void copy​(CoordinateSequence src,
                                int srcPos,
                                CoordinateSequence dest,
                                int destPos,
                                int length)
        Copies a section of a CoordinateSequence to another CoordinateSequence. The sequences may have different dimensions; in this case only the common dimensions are copied.
        Parameters:
        src - the sequence to copy from
        srcPos - the position in the source sequence to start copying at
        dest - the sequence to copy to
        destPos - the position in the destination sequence to copy to
        length - the number of coordinates to copy
      • copyCoord

        public static void copyCoord​(CoordinateSequence src,
                                     int srcPos,
                                     CoordinateSequence dest,
                                     int destPos)
        Copies a coordinate of a CoordinateSequence to another CoordinateSequence. The sequences may have different dimensions; in this case only the common dimensions are copied.
        Parameters:
        src - the sequence to copy from
        srcPos - the source coordinate to copy
        dest - the sequence to copy to
        destPos - the destination coordinate to copy to
      • isRing

        public static boolean isRing​(CoordinateSequence seq)
        Tests whether a CoordinateSequence forms a valid LinearRing, by checking the sequence length and closure (whether the first and last points are identical in 2D). Self-intersection is not checked.
        Parameters:
        seq - the sequence to test
        Returns:
        true if the sequence is a ring
        See Also:
        LinearRing
      • ensureValidRing

        public static CoordinateSequence ensureValidRing​(CoordinateSequenceFactory fact,
                                                         CoordinateSequence seq)
        Ensures that a CoordinateSequence forms a valid ring, returning a new closed sequence of the correct length if required. If the input sequence is already a valid ring, it is returned without modification. If the input sequence is too short or is not closed, it is extended with one or more copies of the start point.
        Parameters:
        fact - the CoordinateSequenceFactory to use to create the new sequence
        seq - the sequence to test
        Returns:
        the original sequence, if it was a valid ring, or a new sequence which is valid.
      • isEqual

        public static boolean isEqual​(CoordinateSequence cs1,
                                      CoordinateSequence cs2)
        Tests whether two CoordinateSequences are equal. To be equal, the sequences must be the same length. They do not need to be of the same dimension, but the ordinate values for the smallest dimension of the two must be equal. Two NaN ordinates values are considered to be equal.
        Parameters:
        cs1 - a CoordinateSequence
        cs2 - a CoordinateSequence
        Returns:
        true if the sequences are equal in the common dimensions
      • toString

        public static java.lang.String toString​(CoordinateSequence cs)
        Creates a string representation of a CoordinateSequence. The format is:
           ( ord0,ord1.. ord0,ord1,...  ... )
         
        Parameters:
        cs - the sequence to output
        Returns:
        the string representation of the sequence
      • minCoordinate

        public static Coordinate minCoordinate​(CoordinateSequence seq)
        Returns the minimum coordinate, using the usual lexicographic comparison.
        Parameters:
        seq - the coordinate sequence to search
        Returns:
        the minimum coordinate in the sequence, found using compareTo
        See Also:
        Comparable.compareTo(Object)
      • minCoordinateIndex

        public static int minCoordinateIndex​(CoordinateSequence seq)
        Returns the index of the minimum coordinate of the whole coordinate sequence, using the usual lexicographic comparison.
        Parameters:
        seq - the coordinate sequence to search
        Returns:
        the index of the minimum coordinate in the sequence, found using compareTo
        See Also:
        Comparable.compareTo(Object)
      • minCoordinateIndex

        public static int minCoordinateIndex​(CoordinateSequence seq,
                                             int from,
                                             int to)
        Returns the index of the minimum coordinate of a part of the coordinate sequence (defined by from and to, using the usual lexicographic comparison.
        Parameters:
        seq - the coordinate sequence to search
        from - the lower search index
        to - the upper search index
        Returns:
        the index of the minimum coordinate in the sequence, found using compareTo
        See Also:
        Comparable.compareTo(Object)
      • scroll

        public static void scroll​(CoordinateSequence seq,
                                  Coordinate firstCoordinate)
        Shifts the positions of the coordinates until firstCoordinate is first.
        Parameters:
        seq - the coordinate sequence to rearrange
        firstCoordinate - the coordinate to make first
      • scroll

        public static void scroll​(CoordinateSequence seq,
                                  int indexOfFirstCoordinate)
        Shifts the positions of the coordinates until the coordinate at firstCoordinateIndex is first.
        Parameters:
        seq - the coordinate sequence to rearrange
        indexOfFirstCoordinate - the index of the coordinate to make first
      • scroll

        public static void scroll​(CoordinateSequence seq,
                                  int indexOfFirstCoordinate,
                                  boolean ensureRing)
        Shifts the positions of the coordinates until the coordinate at firstCoordinateIndex is first.
        Parameters:
        seq - the coordinate sequence to rearrange
        indexOfFirstCoordinate - the index of the coordinate to make first
        ensureRing - makes sure that will be a closed ring upon exit
      • indexOf

        public static int indexOf​(Coordinate coordinate,
                                  CoordinateSequence seq)
        Returns the index of coordinate in a CoordinateSequence The first position is 0; the second, 1; etc.
        Parameters:
        coordinate - the Coordinate to search for
        seq - the coordinate sequence to search
        Returns:
        the position of coordinate, or -1 if it is not found