Class Coordinate
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.
Inherited Members
Namespace: NetTopologySuite.Geometries
Assembly: NetTopologySuite.dll
Syntax
[Serializable]
public class Coordinate : IComparable, IComparable<Coordinate>
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
| Edit this page View SourceCoordinate()
Constructs a Coordinate at (0,0).
Declaration
public Coordinate()
Coordinate(Coordinate)
Constructs a Coordinate having the same (x,y,z) values as
c.
Declaration
public Coordinate(Coordinate c)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | c |
|
Coordinate(double, double)
Constructs a Coordinate at (x,y).
Declaration
public Coordinate(double x, double y)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | The X value |
| double | y | The Y value |
Fields
| Edit this page View SourceNullOrdinate
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.
Declaration
public const double NullOrdinate = NaN
Field Value
| Type | Description |
|---|---|
| double |
Properties
| Edit this page View SourceCoordinateValue
Gets/Sets Coordinates (x,y,z) values.
Declaration
public virtual Coordinate CoordinateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Coordinate |
IsValid
Gets a value indicating if the Coordinate
has valid x- and y ordinate values
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
this[Ordinate]
Gets or sets the value for the given ordinate.
Declaration
public virtual double this[Ordinate ordinate] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| Ordinate | ordinate | The ordinate. |
Property Value
| Type | Description |
|---|---|
| double | The ordinate value |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
this[int]
Gets or sets the ordinate value for the given index.
Declaration
public virtual double this[int ordinateIndex] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | ordinateIndex | The ordinate index |
Property Value
| Type | Description |
|---|---|
| double | The ordinate value |
Remarks
The base implementation supports 0 (X) and 1 (Y) as values for the index.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
M
Gets or sets the value of the measure, if supported. If no measure value is present, returns NullOrdinate.
Declaration
public virtual double M { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public double X { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Y
Gets or sets the Y-ordinate value.
Declaration
public double Y { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Z
Gets or sets the Z-ordinate value, if supported. If no Z value is present, returns NullOrdinate.
Declaration
public virtual double Z { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Exceptions
| Type | Condition |
|---|---|
| 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
| Edit this page View SourceCompareTo(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))
Declaration
public int CompareTo(Coordinate other)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | other |
|
Returns
| Type | Description |
|---|---|
| int | A negative integer, zero, or a positive integer as this |
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))
Declaration
public int CompareTo(object o)
Parameters
| Type | Name | Description |
|---|---|---|
| object | o |
|
Returns
| Type | Description |
|---|---|
| int | A negative integer, zero, or a positive integer as this |
Copy()
Create a copy of this Coordinate.
Declaration
public virtual Coordinate Copy()
Returns
| Type | Description |
|---|---|
| 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.
Declaration
public virtual Coordinate Create(double x = 0, double y = 0, double z = NaN, double m = NaN)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | The x-ordinate value, if not provided, it is |
| double | y | The y-ordinate value, if not provided, it is |
| double | z | The z-ordinate value, if not provided, it is NullOrdinate. |
| double | m | The m-ordinate value, if not provided, it is NullOrdinate. |
Returns
| Type | Description |
|---|---|
| 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. |
Deconstruct(out double, out double)
Deconstructs this Coordinate into its components.
Declaration
public void Deconstruct(out double x, out double y)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | |
| double | y |
Distance(Coordinate)
Computes the 2-dimensional Euclidean distance to another location.
Declaration
public double Distance(Coordinate c)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | c | A Coordinate with which to do the distance comparison. |
Returns
| Type | Description |
|---|---|
| double | the 2-dimensional Euclidean distance between the locations. |
Remarks
The Z-ordinate is ignored.
Equals(Coordinate)
Declaration
public bool Equals(Coordinate other)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | other |
Returns
| Type | Description |
|---|---|
| bool |
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.
Declaration
public override sealed bool Equals(object o)
Parameters
| Type | Name | Description |
|---|---|---|
| object | o |
|
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
| Edit this page View SourceEquals2D(Coordinate)
Returns whether the planar projections of the two Coordinates are equal.
Declaration
public bool Equals2D(Coordinate other)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | other |
|
Returns
| Type | Description |
|---|---|
| bool |
|
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.
Declaration
public bool Equals2D(Coordinate c, double tolerance)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | c | A Coordinate. |
| double | tolerance | The tolerance value to use. |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
The Z ordinate is ignored.
EqualsWithTolerance(double, double, double)
Declaration
protected static bool EqualsWithTolerance(double v1, double v2, double tolerance)
Parameters
| Type | Name | Description |
|---|---|---|
| double | v1 | |
| double | v2 | |
| double | tolerance |
Returns
| Type | Description |
|---|---|
| bool |
GetHashCode()
Gets a hashcode for this coordinate.
Declaration
public override sealed int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hashcode for this coordinate. |
Overrides
| Edit this page View SourceToString()
Returns a string of the form (x,y,z) .
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
|
Overrides
Operators
| Edit this page View Sourceimplicit operator Coordinate((double x, double y))
Implicitly cast a tuple to a new Coordinate as a copy of this instance.
Declaration
public static implicit operator Coordinate((double x, double y) value)
Parameters
| Type | Name | Description |
|---|---|---|
| (double x, double y) | value |
Returns
| Type | Description |
|---|---|
| Coordinate |