Table of Contents

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.

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

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

c Coordinate

Coordinate to copy.

Coordinate(double, double)

Constructs a Coordinate at (x,y).

public Coordinate(double x, double y)

Parameters

x double

The X value

y double

The Y value

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

double

Properties

CoordinateValue

Gets/Sets Coordinates (x,y,z) values.

public virtual Coordinate CoordinateValue { get; set; }

Property Value

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.
public bool IsValid { get; }

Property Value

bool

true if the coordinate is valid

this[Ordinate]

Gets or sets the value for the given ordinate.

public virtual double this[Ordinate ordinate] { get; set; }

Parameters

ordinate Ordinate

The ordinate.

Property Value

double

The ordinate value

Exceptions

ArgumentOutOfRangeException

Thrown if ordinate is not one of X, Y, Z, or M.

this[int]

Gets or sets the ordinate value for the given index.

public virtual double this[int ordinateIndex] { get; set; }

Parameters

ordinateIndex int

The 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 ordinateIndex is 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

double

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

double

Y

Gets or sets the Y-ordinate value.

public double Y { get; set; }

Property Value

double

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

double

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

other Coordinate

Coordinate with which this Coordinate is being compared.

Returns

int

A negative integer, zero, or a positive integer as this Coordinate is less than, equal to, or greater than the specified Coordinate.

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

o object

Coordinate with which this Coordinate is being compared.

Returns

int

A negative integer, zero, or a positive integer as this Coordinate is less than, equal to, or greater than the specified Coordinate.

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

x double

The x-ordinate value, if not provided, it is 0d.

y double

The y-ordinate value, if not provided, it is 0d.

z double

The z-ordinate value, if not provided, it is NullOrdinate.

m double

The 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-)ClassLimitation
Coordinatez-parameter and m-parameter are silently dropped.
CoordinateZm-parameter is silently dropped.
CoordinateMz-parameter is silently dropped.
CoordinateZMNo parameter is dropped.

Distance(Coordinate)

Computes the 2-dimensional Euclidean distance to another location.

public double Distance(Coordinate c)

Parameters

c Coordinate

A 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

other Coordinate

Returns

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.

public override sealed bool Equals(object o)

Parameters

o object

Coordinate with which to do the comparison.

Returns

bool

true if other is a Coordinate with 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

other Coordinate

Coordinate with which to do the 2D comparison.

Returns

bool

true if 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

c Coordinate

A Coordinate.

tolerance double

The tolerance value to use.

Returns

bool

true if 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

v1 double
v2 double
tolerance double

Returns

bool

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

string of the form (x,y,z)