com.vividsolutions.jts.geom

Class CoordinateArrays


public class CoordinateArrays
extends java.lang.Object

Useful utility functions for handling Coordinate arrays
Version:
1.7

Nested Class Summary

static class
CoordinateArrays.BidirectionalComparator
A Comparator for Coordinate arrays modulo their directionality.
static class
CoordinateArrays.ForwardComparator
A Comparator for Coordinate arrays in the forward direction of their coordinates, using lexicographic ordering.

Method Summary

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.
static int
compare(Coordinate[] pts1, Coordinate[] pts2)
Compares two Coordinate arrays in the forward direction of their coordinates, using lexicographic ordering.
static Coordinate[]
copyDeep(Coordinate[] coordinates)
Creates a deep copy of the argument
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)
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
static Coordinate[]
extract(Coordinate[] pts, int start, int end)
Extracts a subsequence of the input Coordinate array from indices start to end (inclusive).
static boolean
hasRepeatedPoints(Coordinate[] coord)
Returns whether #equals returns true for any two consecutive Coordinates in the given array.
static int
increasingDirection(Coordinate[] pts)
Determines which orientation of the Coordinate array is (overall) increasing.
static int
indexOf(Coordinate coordinate, Coordinate[] coordinates)
Returns the index of coordinate in coordinates.
static Coordinate
minCoordinate(Coordinate[] coordinates)
Returns the minimum coordinate, using the usual lexicographic comparison.
static Coordinate
ptNotInList(Coordinate[] testPts, Coordinate[] pts)
Finds a point in a list of points which is not contained in another list of points
static Coordinate[]
removeRepeatedPoints(Coordinate[] coord)
If the coordinate array argument has repeated points, constructs a new array containing no repeated points.
static void
reverse(Coordinate[] coord)
Reverses the coordinates in an array in-place.
static void
scroll(Coordinate[] coordinates, Coordinate firstCoordinate)
Shifts the positions of the coordinates until firstCoordinate is first.
static Coordinate[]
toCoordinateArray(Collection coordList)
Converts the given Collection of Coordinates into a Coordinate array.

Method Details

atLeastNCoordinatesOrNothing

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.

compare

public static int compare(Coordinate[] pts1,
                          Coordinate[] pts2)
Compares two Coordinate arrays in the forward direction of their coordinates, using lexicographic ordering.
Parameters:
pts1 -
pts2 -
Returns:

copyDeep

public static Coordinate[] copyDeep(Coordinate[] coordinates)
Creates a deep copy of the argument Coordinate) array. @param coordinates an array of Coordinates @return a deep copy of the input

equals

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)

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-defined Comparator for Coordinate s
Parameters:
coord1 - an array of Coordinates
coord2 - an array of Coordinates
coordinateComparator - a Comparator for Coordinates

extract

public static Coordinate[] extract(Coordinate[] pts,
                                   int start,
                                   int end)
Extracts a subsequence of the input Coordinate array from indices start to end (inclusive).
Parameters:
pts - the input array
start - the index of the start of the subsequence to extract
end - the index of the end of the subsequence to extract
Returns:
a subsequence of the input array

hasRepeatedPoints

public static boolean hasRepeatedPoints(Coordinate[] coord)
Returns whether #equals returns true for any two consecutive Coordinates in the given array.

increasingDirection

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 - 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

indexOf

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 - the Coordinate to search for
coordinates - the array to search
Returns:
the position of coordinate, or -1 if it is not found

minCoordinate

public static Coordinate minCoordinate(Coordinate[] coordinates)
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

ptNotInList

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 - the Coordinates to test
pts - an array of Coordinates to test the input points against
Returns:
a Coordinate from testPts which is not in pts, ' or null

removeRepeatedPoints

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.

reverse

public static void reverse(Coordinate[] coord)
Reverses the coordinates in an array in-place.

scroll

public static void scroll(Coordinate[] coordinates,
                          Coordinate firstCoordinate)
Shifts the positions of the coordinates until firstCoordinate is first.
Parameters:
coordinates - the array to rearrange
firstCoordinate - the coordinate to make first

toCoordinateArray

public static Coordinate[] toCoordinateArray(Collection coordList)
Converts the given Collection of Coordinates into a Coordinate array.