Class Coordinate
- Namespace
- NetTopologySuite.Geometries
- Assembly
- NetTopologySuite.dll
A lightweight class used to store coordinates on the 2-dimensional Cartesian plane.
The base data object is suitable for use with coordinate sequences with
dimension = 2 and measures = 0.
public class Coordinate : IComparable, IComparable<Coordinate>
- Inheritance
-
Coordinate
- Implements
- Derived
- Inherited Members
Remarks
It is distinct from Point, which is a subclass of Geometry.
Unlike objects of type Point (which contain additional
information such as an envelope, a precision model, and spatial reference
system information), a Coordinate only contains ordinate values
and properties.
Constructors
Coordinate()
Constructs a Coordinate at (0,0).
public Coordinate()
Coordinate(Coordinate)
Constructs a Coordinate having the same (x,y,z) values as
c.
public Coordinate(Coordinate c)
Parameters
cCoordinateCoordinateto copy.
Coordinate(double, double)
Constructs a Coordinate at (x,y).
public Coordinate(double x, double y)
Parameters
Fields
NullOrdinate
The value used to indicate a null or missing ordinate value. In particular, used for the value of ordinates for dimensions greater than the defined dimension of a coordinate.
public const double NullOrdinate = NaN
Field Value
Properties
CoordinateValue
Gets/Sets Coordinates (x,y,z) values.
public virtual Coordinate CoordinateValue { get; set; }
Property Value
IsValid
Gets a value indicating if the Coordinate
has valid x- and y ordinate values
public bool IsValid { get; }
Property Value
- bool
trueif the coordinate is valid
this[Ordinate]
Gets or sets the value for the given ordinate.
public virtual double this[Ordinate ordinate] { get; set; }
Parameters
ordinateOrdinateThe ordinate.
Property Value
- double
The ordinate value
Exceptions
this[int]
Gets or sets the ordinate value for the given index.
public virtual double this[int ordinateIndex] { get; set; }
Parameters
ordinateIndexintThe ordinate index
Property Value
- double
The ordinate value
Remarks
The base implementation supports 0 (X) and 1 (Y) as values for the index.
Exceptions
- ArgumentOutOfRangeException
Thrown if
ordinateIndexis not in the valid range.
M
Gets or sets the value of the measure, if supported. If no measure value is present, returns NullOrdinate.
public virtual double M { get; set; }
Property Value
Exceptions
- InvalidOperationException
Thrown if an attempt is made to set the measure value on an instance where measures are not supported.
X
Gets or sets the X-ordinate value.
public double X { get; set; }
Property Value
Y
Gets or sets the Y-ordinate value.
public double Y { get; set; }
Property Value
Z
Gets or sets the Z-ordinate value, if supported. If no Z value is present, returns NullOrdinate.
public virtual double Z { get; set; }
Property Value
Exceptions
- InvalidOperationException
Thrown if an attempt is made to set the Z-ordinate value on an instance where the Z-ordinate value is not supported.
Methods
CompareTo(Coordinate)
Compares this object with the specified object for order. Since Coordinates are 2.5D, this routine ignores the z value when making the comparison. Returns -1 : this.x < other.x || ((this.x == other.x) AND (this.y < other.y)) 0 : this.x == other.x AND this.y = other.y 1 : this.x > other.x || ((this.x == other.x) AND (this.y > other.y))
public int CompareTo(Coordinate other)
Parameters
otherCoordinateCoordinatewith which thisCoordinateis being compared.
Returns
- int
A negative integer, zero, or a positive integer as this
Coordinateis less than, equal to, or greater than the specifiedCoordinate.
CompareTo(object)
Compares this object with the specified object for order. Since Coordinates are 2.5D, this routine ignores the z value when making the comparison. Returns -1 : this.x < other.x || ((this.x == other.x) AND (this.y < other.y)) 0 : this.x == other.x AND this.y = other.y 1 : this.x > other.x || ((this.x == other.x) AND (this.y > other.y))
public int CompareTo(object o)
Parameters
oobjectCoordinatewith which thisCoordinateis being compared.
Returns
- int
A negative integer, zero, or a positive integer as this
Coordinateis less than, equal to, or greater than the specifiedCoordinate.
Copy()
Create a copy of this Coordinate.
public virtual Coordinate Copy()
Returns
- Coordinate
A copy of this coordinate.
Create(double, double, double, double)
Create a Coordinate of the same type as this Coordinate, using the provided values.
public virtual Coordinate Create(double x = 0, double y = 0, double z = NaN, double m = NaN)
Parameters
xdoubleThe x-ordinate value, if not provided, it is
0d.ydoubleThe y-ordinate value, if not provided, it is
0d.zdoubleThe z-ordinate value, if not provided, it is NullOrdinate.
mdoubleThe m-ordinate value, if not provided, it is NullOrdinate.
Returns
- Coordinate
A new Coordinate
Remarks
Depending on the actual type the following limitations are in place:
| Coordinate (Sub-)Class | Limitation |
|---|---|
Coordinate | z-parameter and m-parameter are silently dropped. |
CoordinateZ | m-parameter is silently dropped. |
CoordinateM | z-parameter is silently dropped. |
CoordinateZM | No parameter is dropped. |
Distance(Coordinate)
Computes the 2-dimensional Euclidean distance to another location.
public double Distance(Coordinate c)
Parameters
cCoordinateA Coordinate with which to do the distance comparison.
Returns
- double
the 2-dimensional Euclidean distance between the locations.
Remarks
The Z-ordinate is ignored.
Equals(Coordinate)
public bool Equals(Coordinate other)
Parameters
otherCoordinate
Returns
Equals(object)
Returns true if other has the same values for the x and y ordinates.
Since Coordinates are 2.5D, this routine ignores the z value when making the comparison.
public override sealed bool Equals(object o)
Parameters
oobjectCoordinatewith which to do the comparison.
Returns
- bool
trueifotheris aCoordinatewith the same values for the x and y ordinates.
Equals2D(Coordinate)
Returns whether the planar projections of the two Coordinates are equal.
public bool Equals2D(Coordinate other)
Parameters
otherCoordinateCoordinatewith which to do the 2D comparison.
Returns
- bool
trueif the x- and y-coordinates are equal; the Z coordinates do not have to be equal.
Equals2D(Coordinate, double)
Tests if another Coordinate has the same values for the X and Y ordinates, within a specified tolerance value. The Z ordinate is ignored.
public bool Equals2D(Coordinate c, double tolerance)
Parameters
cCoordinateA Coordinate.
tolerancedoubleThe tolerance value to use.
Returns
- bool
trueif the X and Y ordinates are within the given tolerance.
Remarks
The Z ordinate is ignored.
EqualsWithTolerance(double, double, double)
protected static bool EqualsWithTolerance(double v1, double v2, double tolerance)
Parameters
Returns
GetHashCode()
Gets a hashcode for this coordinate.
public override sealed int GetHashCode()
Returns
- int
A hashcode for this coordinate.
ToString()
Returns a string of the form (x,y,z) .
public override string ToString()
Returns
- string
stringof the form (x,y,z)