Class CoordinateArrays

Hierarchy: Object , CoordinateArrays
public class CoordinateArrays
Useful utility functions for handling Coordinate arrays

Other

  • version: 1.7
public static int dimension(Coordinate[] pts)
Determine dimension based on subclass of Coordinate.
Parameters:
pts - pts supplied coordinates
Returns:
number of ordinates recorded
public static int measures(Coordinate[] pts)
Determine number of measures based on subclass of Coordinate.
Parameters:
pts - pts supplied coordinates
Returns:
number of measures recorded
public static void enforceConsistency(Coordinate[] array)
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 - array Modified in place to coordinates of consistent dimension and measures.
public static Coordinate[] enforceConsistency(Coordinate[] array, int dimension, int measures)
public static boolean isRing(Coordinate[] pts)
Tests whether an array of Coordinates forms a ring, by checking length and closure. Self-intersection is not checked.
Parameters:
pts - pts an array of Coordinates
Returns:
true if the coordinate form a ring.
public static Coordinate ptNotInList(Coordinate[] testPts, Coordinate[] pts)
Finds a point in a list of points which is not contained in another list of points
Parameters:
testPts - testPts the Coordinates to test
pts - pts an array of Coordinates to test the input points against
Returns:
a Coordinate from testPts which is not in pts, ' or null
public static int compare(Coordinate[] pts1, Coordinate[] pts2)
Compares two Coordinate arrays in the forward direction of their coordinates, using lexicographic ordering.
Parameters:
pts1 - pts1
pts2 - pts2
Returns:
an integer indicating the order
public static int increasingDirection(Coordinate[] pts)
Determines which orientation of the Coordinate array is (overall) increasing. In other words, determines which end of the array is "smaller" (using the standard ordering on Coordinate). 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 - pts the array of Coordinates to test
Returns:
1 if the array is smaller at the start or is a palindrome, -1 if smaller at the end
public static Coordinate[] copyDeep(Coordinate[] coordinates)
Creates a deep copy of the argument Coordinate array.
Parameters:
coordinates - coordinates an array of Coordinates
Returns:
a deep copy of the input
public static void copyDeep(Coordinate[] src, int srcStart, Coordinate[] dest, int destStart, int length)
Creates a deep copy of a given section of a source Coordinate array into a destination Coordinate array. The destination array must be an appropriate size to receive the copied coordinates.
Parameters:
src - src an array of Coordinates
srcStart - srcStart the index to start copying from
dest - dest the
destStart - destStart the destination index to start copying to
length - length the number of items to copy
public static Coordinate[] toCoordinateArray(Collection coordList)
Converts the given Collection of Coordinates into a Coordinate array.
public static boolean hasRepeatedPoints(Coordinate[] coord)
Returns whether #equals returns true for any two consecutive Coordinates in the given array.
public static 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.
public static Coordinate[] removeRepeatedPoints(Coordinate[] coord)
If the coordinate array argument has repeated points, constructs a new array containing no repeated points. Otherwise, returns the argument.
See also:
#hasRepeatedPoints(Coordinate[])
public static Coordinate[] removeNull(Coordinate[] coord)
Collapses a coordinate array to remove all null elements.
Parameters:
coord - coord the coordinate array to collapse
Returns:
an array containing only non-null elements
public static void reverse(Coordinate[] coord)
Reverses the coordinates in an array in-place.
public static boolean equals(Coordinate[] coord1, Coordinate[] coord2)
Returns true if the two arrays are identical, both null, or pointwise equal (as compared using Coordinate#equals)
See also:
Coordinate#equals(Object)
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-defined Comparator for Coordinate s
Parameters:
coord1 - coord1 an array of Coordinates
coord2 - coord2 an array of Coordinates
coordinateComparator - coordinateComparator a Comparator for Coordinates
public static Coordinate minCoordinate(Coordinate[] coordinates)
Returns the minimum coordinate, using the usual lexicographic comparison.
Parameters:
coordinates - coordinates the array to search
See also:
Coordinate#compareTo(Coordinate)
Returns:
the minimum coordinate in the array, found using compareTo
public static void scroll(Coordinate[] coordinates, Coordinate firstCoordinate)
Shifts the positions of the coordinates until firstCoordinate is first.
Parameters:
coordinates - coordinates the array to rearrange
firstCoordinate - firstCoordinate the coordinate to make first
public static void scroll(Coordinate[] coordinates, int indexOfFirstCoordinate)
Shifts the positions of the coordinates until the coordinate at firstCoordinate is first.
Parameters:
coordinates - coordinates the array to rearrange
indexOfFirstCoordinate - indexOfFirstCoordinate the index of the coordinate to make first
public static void scroll(Coordinate[] coordinates, int indexOfFirstCoordinate, boolean ensureRing)
Shifts the positions of the coordinates until the coordinate at indexOfFirstCoordinate is first.

If ensureRing is true, first and last coordinate of the returned array are equal.
Parameters:
coordinates - coordinates the array to rearrange
indexOfFirstCoordinate - indexOfFirstCoordinate the index of the coordinate to make first
ensureRing - ensureRing flag indicating if returned array should form a ring.
public static int indexOf(Coordinate coordinate, Coordinate[] coordinates)
Returns the index of coordinate in coordinates. The first position is 0; the second, 1; etc.
Parameters:
coordinate - coordinate the Coordinate to search for
coordinates - coordinates the array to search
Returns:
the position of coordinate, or -1 if it is not found
public static Coordinate[] extract(Coordinate[] pts, int start, int end)
Extracts a subsequence of the input Coordinate array from indices start to end (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 - pts the input array
start - start the index of the start of the subsequence to extract
end - end the index of the end of the subsequence to extract
Returns:
a subsequence of the input array
public static Envelope envelope(Coordinate[] coordinates)
Computes the envelope of the coordinates.
Parameters:
coordinates - coordinates the coordinates to scan
Returns:
the envelope of the coordinates
public static Coordinate[] intersection(Coordinate[] coordinates, Envelope env)
Extracts the coordinates which intersect an Envelope.
Parameters:
coordinates - coordinates the coordinates to scan
env - env the envelope to intersect with
Returns:
an array of the coordinates which intersect the envelope