Class CoordinateArrays
java.lang.Object
org.locationtech.jts.geom.CoordinateArrays
Useful utility functions for handling Coordinate arrays
- Version:
- 1.7
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAComparatorforCoordinatearrays modulo their directionality.static classAComparatorforCoordinatearrays in the forward direction of their coordinates, using lexicographic ordering. -
Method Summary
Modifier and TypeMethodDescriptionstatic Coordinate[]atLeastNCoordinatesOrNothing(int n, Coordinate[] c) Returns either the given coordinate array if its length is greater than the given amount, or an empty coordinate array.static intcompare(Coordinate[] pts1, Coordinate[] pts2) Compares twoCoordinatearrays in the forward direction of their coordinates, using lexicographic ordering.static Coordinate[]copyDeep(Coordinate[] coordinates) Creates a deep copy of the argumentCoordinatearray.static voidcopyDeep(Coordinate[] src, int srcStart, Coordinate[] dest, int destStart, int length) Creates a deep copy of a given section of a sourceCoordinatearray into a destination Coordinate array.static intdimension(Coordinate[] pts) Determine dimension based on subclass ofCoordinate.static voidenforceConsistency(Coordinate[] array) Utility method ensuring array contents are of consistent dimension and measures.static Coordinate[]enforceConsistency(Coordinate[] array, int dimension, int measures) Utility method ensuring array contents are of the specified dimension and measures.static Envelopeenvelope(Coordinate[] coordinates) Computes the envelope of the coordinates.static booleanequals(Coordinate[] coord1, Coordinate[] coord2) Returns true if the two arrays are identical, both null, or pointwise equal (as compared using Coordinate#equals)static booleanequals(Coordinate[] coord1, Coordinate[] coord2, Comparator coordinateComparator) Returns true if the two arrays are identical, both null, or pointwise equal, using a user-definedComparatorforCoordinatesstatic Coordinate[]extract(Coordinate[] pts, int start, int end) static booleanhasRepeatedOrInvalidPoints(Coordinate[] coord) Tests whether an array has any repeated or invalid coordinates.static booleanhasRepeatedPoints(Coordinate[] coord) Tests whetherCoordinate.equals(Object)returns true for any two consecutive Coordinates in the given array.static intincreasingDirection(Coordinate[] pts) Determines which orientation of theCoordinatearray is (overall) increasing.static intindexOf(Coordinate coordinate, Coordinate[] coordinates) Returns the index ofcoordinateincoordinates.static Coordinate[]intersection(Coordinate[] coordinates, Envelope env) Extracts the coordinates which intersect anEnvelope.static booleanisRing(Coordinate[] pts) Tests whether an array ofCoordinates forms a ring, by checking length and closure.static intmeasures(Coordinate[] pts) Determine number of measures based on subclass ofCoordinate.static CoordinateminCoordinate(Coordinate[] coordinates) Returns the minimum coordinate, using the usual lexicographic comparison.static CoordinateptNotInList(Coordinate[] testPts, Coordinate[] pts) Finds a point in a list of points which is not contained in another list of pointsstatic Coordinate[]removeNull(Coordinate[] coord) Collapses a coordinate array to remove all null elements.static Coordinate[]removeRepeatedOrInvalidPoints(Coordinate[] coord) If the coordinate array argument has repeated or invalid points, constructs a new array containing no repeated points.static Coordinate[]removeRepeatedPoints(Coordinate[] coord) If the coordinate array argument has repeated points, constructs a new array containing no repeated points.static voidreverse(Coordinate[] coord) Reverses the coordinates in an array in-place.static voidscroll(Coordinate[] coordinates, int indexOfFirstCoordinate) Shifts the positions of the coordinates until the coordinate atfirstCoordinateis first.static voidscroll(Coordinate[] coordinates, int indexOfFirstCoordinate, boolean ensureRing) Shifts the positions of the coordinates until the coordinate atindexOfFirstCoordinateis first.static voidscroll(Coordinate[] coordinates, Coordinate firstCoordinate) Shifts the positions of the coordinates untilfirstCoordinateis first.static Coordinate[]toCoordinateArray(Collection coordList) Converts the given Collection of Coordinates into a Coordinate array.
-
Method Details
-
dimension
Determine dimension based on subclass ofCoordinate.- Parameters:
pts- supplied coordinates- Returns:
- number of ordinates recorded
-
measures
Determine number of measures based on subclass ofCoordinate.- Parameters:
pts- supplied coordinates- Returns:
- number of measures recorded
-
enforceConsistency
Utility method ensuring array contents are of consistent dimension and measures.Array is modified in place if required, coordinates are replaced in the array as required to ensure all coordinates have the same dimension and measures. The final dimension and measures used are the maximum found when checking the array.
- Parameters:
array- Modified in place to coordinates of consistent dimension and measures.
-
enforceConsistency
Utility method ensuring array contents are of the specified dimension and measures.Array is returned unmodified if consistent, or a copy of the array is made with each inconsistent coordinate duplicated into an instance of the correct dimension and measures.
invalid input: '<'/>- Parameters:
array- coordinate arraydimension-measures-- Returns:
- array returned, or copy created if required to enforce consistency.
-
isRing
Tests whether an array ofCoordinates forms a ring, by checking length and closure. Self-intersection is not checked.- Parameters:
pts- an array of Coordinates- Returns:
- true if the coordinate form a ring.
-
ptNotInList
Finds a point in a list of points which is not contained in another list of points- Parameters:
testPts- theCoordinates to testpts- an array ofCoordinates to test the input points against- Returns:
- a
CoordinatefromtestPtswhich is not inpts, ' ornull
-
compare
Compares twoCoordinatearrays in the forward direction of their coordinates, using lexicographic ordering.- Parameters:
pts1-pts2-- Returns:
- an integer indicating the order
-
increasingDirection
Determines which orientation of theCoordinatearray is (overall) increasing. In other words, determines which end of the array is "smaller" (using the standard ordering onCoordinate). Returns an integer indicating the increasing direction. If the sequence is a palindrome, it is defined to be oriented in a positive direction.- Parameters:
pts- the array of Coordinates to test- Returns:
1if the array is smaller at the start or is a palindrome,-1if smaller at the end
-
copyDeep
Creates a deep copy of the argumentCoordinatearray.- Parameters:
coordinates- an array of Coordinates- Returns:
- a deep copy of the input
-
copyDeep
public static void copyDeep(Coordinate[] src, int srcStart, Coordinate[] dest, int destStart, int length) Creates a deep copy of a given section of a sourceCoordinatearray into a destination Coordinate array. The destination array must be an appropriate size to receive the copied coordinates.- Parameters:
src- an array of CoordinatessrcStart- the index to start copying fromdest- thedestStart- the destination index to start copying tolength- the number of items to copy
-
toCoordinateArray
Converts the given Collection of Coordinates into a Coordinate array. -
hasRepeatedPoints
Tests whetherCoordinate.equals(Object)returns true for any two consecutive Coordinates in the given array.- Parameters:
coord- an array of coordinates- Returns:
- true if the array has repeated points
-
atLeastNCoordinatesOrNothing
Returns either the given coordinate array if its length is greater than the given amount, or an empty coordinate array. -
removeRepeatedPoints
If the coordinate array argument has repeated points, constructs a new array containing no repeated points. Otherwise, returns the argument.- Parameters:
coord- an array of coordinates- Returns:
- the array with repeated coordinates removed
- See Also:
-
hasRepeatedOrInvalidPoints
Tests whether an array has any repeated or invalid coordinates.- Parameters:
coord- an array of coordinates- Returns:
- true if the array contains repeated or invalid coordinates
- See Also:
-
removeRepeatedOrInvalidPoints
If the coordinate array argument has repeated or invalid points, constructs a new array containing no repeated points. Otherwise, returns the argument.- Parameters:
coord- an array of coordinates- Returns:
- the array with repeated and invalid coordinates removed
- See Also:
-
removeNull
Collapses a coordinate array to remove all null elements.- Parameters:
coord- the coordinate array to collapse- Returns:
- an array containing only non-null elements
-
reverse
Reverses the coordinates in an array in-place. -
equals
Returns true if the two arrays are identical, both null, or pointwise equal (as compared using Coordinate#equals)- See Also:
-
equals
public static boolean equals(Coordinate[] coord1, Coordinate[] coord2, Comparator coordinateComparator) Returns true if the two arrays are identical, both null, or pointwise equal, using a user-definedComparatorforCoordinates- Parameters:
coord1- an array of Coordinatescoord2- an array of CoordinatescoordinateComparator- a Comparator for Coordinates
-
minCoordinate
Returns the minimum coordinate, using the usual lexicographic comparison.- Parameters:
coordinates- the array to search- Returns:
- the minimum coordinate in the array, found using
compareTo - See Also:
-
scroll
Shifts the positions of the coordinates untilfirstCoordinateis first.- Parameters:
coordinates- the array to rearrangefirstCoordinate- the coordinate to make first
-
scroll
Shifts the positions of the coordinates until the coordinate atfirstCoordinateis first.- Parameters:
coordinates- the array to rearrangeindexOfFirstCoordinate- the index of the coordinate to make first
-
scroll
Shifts the positions of the coordinates until the coordinate atindexOfFirstCoordinateis first. IfensureRingistrue, first and last coordinate of the returned array are equal.- Parameters:
coordinates- the array to rearrangeindexOfFirstCoordinate- the index of the coordinate to make firstensureRing- flag indicating if returned array should form a ring.
-
indexOf
Returns the index ofcoordinateincoordinates. The first position is 0; the second, 1; etc.- Parameters:
coordinate- theCoordinateto search forcoordinates- the array to search- Returns:
- the position of
coordinate, or -1 if it is not found
-
extract
Extracts a subsequence of the inputCoordinatearray from indicesstarttoend(inclusive). The input indices are clamped to the array size; If the end index is less than the start index, the extracted array will be empty.- Parameters:
pts- the input arraystart- the index of the start of the subsequence to extractend- the index of the end of the subsequence to extract- Returns:
- a subsequence of the input array
-
envelope
Computes the envelope of the coordinates.- Parameters:
coordinates- the coordinates to scan- Returns:
- the envelope of the coordinates
-
intersection
Extracts the coordinates which intersect anEnvelope.- Parameters:
coordinates- the coordinates to scanenv- the envelope to intersect with- Returns:
- an array of the coordinates which intersect the envelope
-