Class CoordinateArrays
- Namespace
- NetTopologySuite.Geometries
- Assembly
- NetTopologySuite.dll
Useful utility functions for handling Coordinate arrays.
public static class CoordinateArrays
- Inheritance
-
CoordinateArrays
- Inherited Members
Methods
AtLeastNCoordinatesOrNothing(int, Coordinate[])
Returns either the given coordinate array if its length is greater than the given amount, or an empty coordinate array.
public static Coordinate[] AtLeastNCoordinatesOrNothing(int n, Coordinate[] c)
Parameters
n
intLength amount.
c
Coordinate[]Array of Coordinates.
Returns
- Coordinate[]
New Coordinate array.
Compare(Coordinate[], Coordinate[])
Compares two Coordinate arrays in the forward direction of their coordinates, using lexicographic ordering.
public static int Compare(Coordinate[] pts1, Coordinate[] pts2)
Parameters
pts1
Coordinate[]pts2
Coordinate[]
Returns
CopyDeep(Coordinate[])
Creates a deep copy of the argument Coordinate
array.
public static Coordinate[] CopyDeep(Coordinate[] coordinates)
Parameters
coordinates
Coordinate[]Array of Coordinates.
Returns
- Coordinate[]
Deep copy of the input.
CopyDeep(Coordinate[], int, Coordinate[], int, int)
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.
public static void CopyDeep(Coordinate[] src, int srcStart, Coordinate[] dest, int destStart, int length)
Parameters
src
Coordinate[]An array of Coordinates
srcStart
intThe index to start copying from
dest
Coordinate[]The array to receive the deep-copied coordinates
destStart
intThe destination index to start copying to
length
intThe number of items to copy
Dimension(Coordinate[])
Determine dimension based on subclass of Coordinate.
public static int Dimension(Coordinate[] pts)
Parameters
pts
Coordinate[]pts supplied coordinates
Returns
- int
number of ordinates recorded
EnforceConsistency(Coordinate[])
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.public static void EnforceConsistency(Coordinate[] array)
Parameters
array
Coordinate[]Modified in place to coordinates of consistent dimension and measures.
EnforceConsistency(Coordinate[], int, int)
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.public static Coordinate[] EnforceConsistency(Coordinate[] array, int dimension, int measures)
Parameters
array
Coordinate[]A coordinate array
dimension
intmeasures
int
Returns
- Coordinate[]
Input array or copy created if required to enforce consistency.
Envelope(Coordinate[])
Computes the Envelope(Coordinate[]) of the coordinates.
public static Envelope Envelope(Coordinate[] coordinates)
Parameters
coordinates
Coordinate[]the Coordinate array to scan.
Returns
- Envelope
the Envelope(Coordinate[]) of the
coordinates
.
Equals(Coordinate[], Coordinate[])
Returns true
if the two arrays are identical, both null
, or pointwise
equal (as compared using Coordinate.Equals).
public static bool Equals(Coordinate[] coord1, Coordinate[] coord2)
Parameters
coord1
Coordinate[]First array of Coordinates.
coord2
Coordinate[]Second array of Coordinates.
Returns
- bool
true
if two Coordinates array are equals; false otherwise
Equals(Coordinate[], Coordinate[], IComparer<Coordinate[]>)
Returns true
if the two arrays are identical, both null
, or pointwise
equal, using a user-defined IComparer
for Coordinates.
public static bool Equals(Coordinate[] coord1, Coordinate[] coord2, IComparer<Coordinate[]> coordinateComparer)
Parameters
coord1
Coordinate[]An array of Coordinates.
coord2
Coordinate[]Another array of Coordinates.
coordinateComparer
IComparer<Coordinate[]>A IComparer for Coordinates.
Returns
Extract(Coordinate[], int, int)
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.
public static Coordinate[] Extract(Coordinate[] pts, int start, int end)
Parameters
pts
Coordinate[]The input array.
start
intThe index of the start of the subsequence to extract.
end
intThe index of the end of the subsequence to extract.
Returns
- Coordinate[]
A subsequence of the input array.
HasRepeatedOrInvalidPoints(Coordinate[])
Tests whether an array has any repeated or invalid coordinates.
public static bool HasRepeatedOrInvalidPoints(Coordinate[] coord)
Parameters
coord
Coordinate[]An array of coordinates
Returns
- bool
true
if the array contains repeated or invalid coordinates
HasRepeatedPoints(Coordinate[])
Returns whether Equals(object) returns true for any two consecutive coordinates in the given array.
public static bool HasRepeatedPoints(Coordinate[] coord)
Parameters
coord
Coordinate[]An array of
Coordinate
s.
Returns
- bool
true if coord has repeated points; false otherwise.
IncreasingDirection(Coordinate[])
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.
public static int IncreasingDirection(Coordinate[] pts)
Parameters
pts
Coordinate[]The array of Coordinates to test.
Returns
- int
1
if the array is smaller at the start or is a palindrome,-1
if smaller at the end.
IndexOf(Coordinate, Coordinate[])
Returns the index of coordinate
in coordinates
.
The first position is 0; the second is 1; etc.
public static int IndexOf(Coordinate coordinate, Coordinate[] coordinates)
Parameters
coordinate
CoordinateA Coordinate to search for.
coordinates
Coordinate[]A Coordinate array to search.
Returns
- int
The position of
coordinate
, or -1 if it is not found.
Intersection(Coordinate[], Envelope)
Extracts the coordinates which intersect an Envelope(Coordinate[]).
public static Coordinate[] Intersection(Coordinate[] coordinates, Envelope env)
Parameters
coordinates
Coordinate[]The coordinates to scan
env
EnvelopeThe envelope to intersect with
Returns
- Coordinate[]
An array of coordinates which intersect with the envelope
IsRing(Coordinate[])
Tests whether an array of Coordinates forms a ring, by checking length and closure. Self-intersection is not checked.
public static bool IsRing(Coordinate[] pts)
Parameters
pts
Coordinate[]An array of Coordinates
Returns
- bool
true if the coordinate form a ring.
Measures(Coordinate[])
Determine number of measures based on subclass of Coordinate.
public static int Measures(Coordinate[] pts)
Parameters
pts
Coordinate[]supplied coordinates
Returns
- int
number of measures recorded
MinCoordinate(Coordinate[])
Returns the minimum coordinate, using the usual lexicographic comparison.
public static Coordinate MinCoordinate(Coordinate[] coordinates)
Parameters
coordinates
Coordinate[]Array to search.
Returns
- Coordinate
The minimum coordinate in the array, found using
CompareTo
.
PointNotInList(Coordinate[], Coordinate[])
Finds a Coordinate in a list of Coordinates which is not contained in another list of Coordinates.
public static Coordinate PointNotInList(Coordinate[] testPts, Coordinate[] pts)
Parameters
testPts
Coordinate[]The Coordinates to test.
pts
Coordinate[]An array of Coordinates to test the input points against.
Returns
- Coordinate
A Coordinate from
testPts
which is not inpts
, ornull
.
RemoveNull(Coordinate[])
Collapses a coordinate array to remove all null elements.
public static Coordinate[] RemoveNull(Coordinate[] coord)
Parameters
coord
Coordinate[]The coordinate array to collapse
Returns
- Coordinate[]
An Array containing only non-null elements
RemoveRepeatedOrInvalidPoints(Coordinate[])
If the coordinate array argument has repeated or invalid points, constructs a new array containing no repeated points. Otherwise, returns the argument.
public static Coordinate[] RemoveRepeatedOrInvalidPoints(Coordinate[] coord)
Parameters
coord
Coordinate[]An array of coordinates
Returns
- Coordinate[]
The array with repeated or invalid coordinates removed.
RemoveRepeatedPoints(Coordinate[])
If the coordinate array argument has repeated points, constructs a new array containing no repeated points. Otherwise, returns the argument.
public static Coordinate[] RemoveRepeatedPoints(Coordinate[] coord)
Parameters
coord
Coordinate[]An array of
Coordinate
s
Returns
- Coordinate[]
The array with repeated coordinates removed
Reverse(Coordinate[])
Reverses the coordinates in an array in-place.
public static void Reverse(Coordinate[] coord)
Parameters
coord
Coordinate[]Array of Coordinates.
Scroll(Coordinate[], Coordinate)
Shifts the positions of the coordinates until firstCoordinate
is first.
public static void Scroll(Coordinate[] coordinates, Coordinate firstCoordinate)
Parameters
coordinates
Coordinate[]Array to rearrange.
firstCoordinate
CoordinateCoordinate to make first.
Scroll(Coordinate[], int)
Shifts the positions of the coordinates until the coordinate
at indexOfFirstCoordinate
is first.
public static void Scroll(Coordinate[] coordinates, int indexOfFirstCoordinate)
Parameters
coordinates
Coordinate[]The array of coordinates to arrange
indexOfFirstCoordinate
intThe index of the coordinate to make first
Scroll(Coordinate[], int, bool)
Shifts the positions of the coordinates until the coordinate
at indexOfFirstCoordinate
is first.
public static void Scroll(Coordinate[] coordinates, int indexOfFirstCoordinate, bool ensureRing)
Parameters
coordinates
Coordinate[]The array of coordinates to arrange
indexOfFirstCoordinate
intThe index of the coordinate to make first
ensureRing
boolA flag indicating if returned array should form a ring.
Remarks
If ensureRing
is true
, first and last
coordinate of the returned array are equal.
ToCoordinateArray(IEnumerable<Coordinate>)
Converts the given IEnumerable<T> of Coordinates into a Coordinate array.
public static Coordinate[] ToCoordinateArray(IEnumerable<Coordinate> coordList)
Parameters
coordList
IEnumerable<Coordinate>IEnumerable<T> of coordinates.