Package org.locationtech.jts.geom
Class CoordinateArrays
- java.lang.Object
-
- org.locationtech.jts.geom.CoordinateArrays
-
public class CoordinateArrays extends java.lang.Object
Useful utility functions for handling Coordinate arrays- Version:
- 1.7
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CoordinateArrays.BidirectionalComparator
AComparator
forCoordinate
arrays modulo their directionality.static class
CoordinateArrays.ForwardComparator
AComparator
forCoordinate
arrays in the forward direction of their coordinates, using lexicographic ordering.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 twoCoordinate
arrays in the forward direction of their coordinates, using lexicographic ordering.static Coordinate[]
copyDeep(Coordinate[] coordinates)
Creates a deep copy of the argumentCoordinate
array.static void
copyDeep(Coordinate[] src, int srcStart, Coordinate[] dest, int destStart, int length)
Creates a deep copy of a given section of a sourceCoordinate
array into a destination Coordinate array.static int
dimension(Coordinate[] pts)
Determine dimension based on subclass ofCoordinate
.static Envelope
envelope(Coordinate[] coordinates)
Computes the envelope of the coordinates.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, java.util.Comparator coordinateComparator)
Returns true if the two arrays are identical, both null, or pointwise equal, using a user-definedComparator
forCoordinate
sstatic Coordinate[]
extract(Coordinate[] pts, int start, int end)
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 theCoordinate
array is (overall) increasing.static int
indexOf(Coordinate coordinate, Coordinate[] coordinates)
Returns the index ofcoordinate
incoordinates
.static Coordinate[]
intersection(Coordinate[] coordinates, Envelope env)
Extracts the coordinates which intersect anEnvelope
.static boolean
isRing(Coordinate[] pts)
Tests whether an array ofCoordinate
s forms a ring, by checking length and closure.static int
measures(Coordinate[] pts)
Determine number of measures based on subclass ofCoordinate
.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 pointsstatic Coordinate[]
removeNull(Coordinate[] coord)
Collapses a coordinate array to remove all null elements.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 untilfirstCoordinate
is first.static Coordinate[]
toCoordinateArray(java.util.Collection coordList)
Converts the given Collection of Coordinates into a Coordinate array.
-
-
-
Method Detail
-
dimension
public static int dimension(Coordinate[] pts)
Determine dimension based on subclass ofCoordinate
.- Parameters:
pts
- supplied coordinates- Returns:
- number of ordinates recorded
-
measures
public static int measures(Coordinate[] pts)
Determine number of measures based on subclass ofCoordinate
.- Parameters:
pts
- supplied coordinates- Returns:
- number of measures recorded
-
isRing
public static boolean isRing(Coordinate[] pts)
Tests whether an array ofCoordinate
s 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
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
- theCoordinate
s to testpts
- an array ofCoordinate
s to test the input points against- Returns:
- a
Coordinate
fromtestPts
which is not inpts
, ' ornull
-
compare
public static int compare(Coordinate[] pts1, Coordinate[] pts2)
Compares twoCoordinate
arrays in the forward direction of their coordinates, using lexicographic ordering.- Parameters:
pts1
-pts2
-- Returns:
- an integer indicating the order
-
increasingDirection
public static int increasingDirection(Coordinate[] pts)
Determines which orientation of theCoordinate
array 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:
1
if the array is smaller at the start or is a palindrome,-1
if smaller at the end
-
copyDeep
public static Coordinate[] copyDeep(Coordinate[] coordinates)
Creates a deep copy of the argumentCoordinate
array.- 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 sourceCoordinate
array 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
public static Coordinate[] toCoordinateArray(java.util.Collection coordList)
Converts the given Collection of Coordinates into a Coordinate array.
-
hasRepeatedPoints
public static boolean hasRepeatedPoints(Coordinate[] coord)
Returns whether #equals returns true for any two consecutive Coordinates in the given array.
-
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.
-
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.- See Also:
hasRepeatedPoints(Coordinate[])
-
removeNull
public static Coordinate[] removeNull(Coordinate[] coord)
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
public static void reverse(Coordinate[] coord)
Reverses the coordinates in an array in-place.
-
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)- See Also:
Coordinate.equals(Object)
-
equals
public static boolean equals(Coordinate[] coord1, Coordinate[] coord2, java.util.Comparator coordinateComparator)
Returns true if the two arrays are identical, both null, or pointwise equal, using a user-definedComparator
forCoordinate
s- Parameters:
coord1
- an array of Coordinatescoord2
- an array of CoordinatescoordinateComparator
- a Comparator for Coordinates
-
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
- See Also:
Comparable.compareTo(Object)
-
scroll
public static void scroll(Coordinate[] coordinates, Coordinate firstCoordinate)
Shifts the positions of the coordinates untilfirstCoordinate
is first.- Parameters:
coordinates
- the array to rearrangefirstCoordinate
- the coordinate to make first
-
indexOf
public static int indexOf(Coordinate coordinate, Coordinate[] coordinates)
Returns the index ofcoordinate
incoordinates
. The first position is 0; the second, 1; etc.- Parameters:
coordinate
- theCoordinate
to search forcoordinates
- the array to search- Returns:
- the position of
coordinate
, or -1 if it is not found
-
extract
public static Coordinate[] extract(Coordinate[] pts, int start, int end)
Extracts a subsequence of the inputCoordinate
array from indicesstart
toend
(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
public static Envelope envelope(Coordinate[] coordinates)
Computes the envelope of the coordinates.- Parameters:
coordinates
- the coordinates to scan- Returns:
- the envelope of the coordinates
-
intersection
public static Coordinate[] intersection(Coordinate[] coordinates, Envelope env)
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
-
-