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.
Implementations may optionally support Z-ordinate and M-measure values as appropriate for a CoordinateSequence. Use of Z and M setters or NetTopologySuite.Geometries.Coordinate.this[int] indexer are recommended.
Constructors
| Improve this Doc 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
| Improve this Doc 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
| Improve this Doc View SourceCoordinateValue
Gets/Sets Coordinate
s (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
An ordinate value is valid if it is finite.
Declaration
public bool IsValid { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
Item[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 |
Item[Int32]
Gets or sets the ordinate value for the given index.
Declaration
public virtual double this[int ordinateIndex] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | 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
| Improve this Doc 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 |
---|---|
Int32 | 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 |
---|---|
Int32 | 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. |
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 |
---|---|
Boolean |
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 sealed override bool Equals(object o)
Parameters
Type | Name | Description |
---|---|---|
Object | o |
|
Returns
Type | Description |
---|---|
Boolean |
|
Overrides
| Improve this Doc View SourceEquals2D(Coordinate)
Returns whether the planar projections of the two Coordinate
s are equal.
Declaration
public bool Equals2D(Coordinate other)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | other |
|
Returns
Type | Description |
---|---|
Boolean |
|
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 |
---|---|
Boolean |
|
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 |
---|---|
Boolean |
GetHashCode()
Gets a hashcode for this coordinate.
Declaration
public sealed override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hashcode for this coordinate. |
Overrides
| Improve this Doc View SourceToString()
Returns a string
of the form (x,y,z) .
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
|