Class CoordinateSequences
java.lang.Object
org.locationtech.jts.geom.CoordinateSequences
Utility functions for manipulating
CoordinateSequences- Version:
- 1.7
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopy(CoordinateSequence src, int srcPos, CoordinateSequence dest, int destPos, int length) Copies a section of aCoordinateSequenceto anotherCoordinateSequence.static voidcopyCoord(CoordinateSequence src, int srcPos, CoordinateSequence dest, int destPos) Copies a coordinate of aCoordinateSequenceto anotherCoordinateSequence.static CoordinateSequenceEnsures that a CoordinateSequence forms a valid ring, returning a new closed sequence of the correct length if required.static CoordinateSequenceextend(CoordinateSequenceFactory fact, CoordinateSequence seq, int size) static intindexOf(Coordinate coordinate, CoordinateSequence seq) Returns the index ofcoordinatein aCoordinateSequenceThe first position is 0; the second, 1; etc.static booleanisEqual(CoordinateSequence cs1, CoordinateSequence cs2) Tests whether twoCoordinateSequences are equal.static booleanisRing(CoordinateSequence seq) Tests whether aCoordinateSequenceforms a validLinearRing, by checking the sequence length and closure (whether the first and last points are identical in 2D).static CoordinateReturns the minimum coordinate, using the usual lexicographic comparison.static intReturns the index of the minimum coordinate of the whole coordinate sequence, using the usual lexicographic comparison.static intminCoordinateIndex(CoordinateSequence seq, int from, int to) Returns the index of the minimum coordinate of a part of the coordinate sequence (defined byfromandto, using the usual lexicographic comparison.static voidReverses the coordinates in a sequence in-place.static voidscroll(CoordinateSequence seq, int indexOfFirstCoordinate) Shifts the positions of the coordinates until the coordinate atfirstCoordinateIndexis first.static voidscroll(CoordinateSequence seq, int indexOfFirstCoordinate, boolean ensureRing) Shifts the positions of the coordinates until the coordinate atfirstCoordinateIndexis first.static voidscroll(CoordinateSequence seq, Coordinate firstCoordinate) Shifts the positions of the coordinates untilfirstCoordinateis first.static voidswap(CoordinateSequence seq, int i, int j) Swaps two coordinates in a sequence.static StringCreates a string representation of aCoordinateSequence.
-
Constructor Details
-
CoordinateSequences
public CoordinateSequences()
-
-
Method Details
-
reverse
Reverses the coordinates in a sequence in-place.- Parameters:
seq- the coordinate sequence to reverse
-
swap
Swaps two coordinates in a sequence.- Parameters:
seq- the sequence to modifyi- the index of a coordinate to swapj- 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 aCoordinateSequenceto anotherCoordinateSequence. The sequences may have different dimensions; in this case only the common dimensions are copied.- Parameters:
src- the sequence to copy fromsrcPos- the position in the source sequence to start copying atdest- the sequence to copy todestPos- the position in the destination sequence to copy tolength- the number of coordinates to copy
-
copyCoord
public static void copyCoord(CoordinateSequence src, int srcPos, CoordinateSequence dest, int destPos) Copies a coordinate of aCoordinateSequenceto anotherCoordinateSequence. The sequences may have different dimensions; in this case only the common dimensions are copied.- Parameters:
src- the sequence to copy fromsrcPos- the source coordinate to copydest- the sequence to copy todestPos- the destination coordinate to copy to
-
isRing
Tests whether aCoordinateSequenceforms a validLinearRing, 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:
-
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 sequenceseq- the sequence to test- Returns:
- the original sequence, if it was a valid ring, or a new sequence which is valid.
-
extend
public static CoordinateSequence extend(CoordinateSequenceFactory fact, CoordinateSequence seq, int size) -
isEqual
Tests whether twoCoordinateSequences 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. TwoNaNordinates values are considered to be equal.- Parameters:
cs1- a CoordinateSequencecs2- a CoordinateSequence- Returns:
- true if the sequences are equal in the common dimensions
-
toString
Creates a string representation of aCoordinateSequence. The format is:( ord0,ord1.. ord0,ord1,... ... )
- Parameters:
cs- the sequence to output- Returns:
- the string representation of the sequence
-
minCoordinate
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:
-
minCoordinateIndex
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:
-
minCoordinateIndex
Returns the index of the minimum coordinate of a part of the coordinate sequence (defined byfromandto, using the usual lexicographic comparison.- Parameters:
seq- the coordinate sequence to searchfrom- the lower search indexto- the upper search index- Returns:
- the index of the minimum coordinate in the sequence, found using
compareTo - See Also:
-
scroll
Shifts the positions of the coordinates untilfirstCoordinateis first.- Parameters:
seq- the coordinate sequence to rearrangefirstCoordinate- the coordinate to make first
-
scroll
Shifts the positions of the coordinates until the coordinate atfirstCoordinateIndexis first.- Parameters:
seq- the coordinate sequence to rearrangeindexOfFirstCoordinate- the index of the coordinate to make first
-
scroll
Shifts the positions of the coordinates until the coordinate atfirstCoordinateIndexis first.- Parameters:
seq- the coordinate sequence to rearrangeindexOfFirstCoordinate- the index of the coordinate to make firstensureRing- makes sure that will be a closed ring upon exit
-
indexOf
Returns the index ofcoordinatein aCoordinateSequenceThe first position is 0; the second, 1; etc.- Parameters:
coordinate- theCoordinateto search forseq- the coordinate sequence to search- Returns:
- the position of
coordinate, or -1 if it is not found
-