Table of Contents

Struct LatLon

Namespace
LansMap.Core.Geo

A WGS84 geographic coordinate in degrees, validated at construction.

public readonly struct LatLon : IEquatable<LatLon>
Implements

Remarks

Latitude is positive north, longitude positive east. The constructor throws rather than clamping, so an out-of-range value fails where it is produced instead of silently landing somewhere plausible. Use ClampToMercator(double, double) when clamping is what you want.

Constructors

LatLon(double, double)

Creates a coordinate, rejecting out-of-range values.

public LatLon(double lat, double lon)

Parameters

lat double

Latitude in degrees WGS84, -90 to 90.

lon double

Longitude in degrees WGS84, -180 to 180.

Exceptions

ArgumentOutOfRangeException

Either value is NaN or outside its range.

Fields

MercatorMaxLat

The highest latitude Web Mercator can represent, 85.05112878 degrees. The projection sends the poles to infinity, so the square map is cut at this parallel.

public const double MercatorMaxLat = 85.05112878

Field Value

double

Properties

Lat

Latitude in degrees WGS84, -90 to 90, positive north.

public double Lat { get; }

Property Value

double

Lon

Longitude in degrees WGS84, -180 to 180, positive east.

public double Lon { get; }

Property Value

double

Methods

ClampToMercator(double, double)

Creates a coordinate with latitude clamped into the Web Mercator range, for input that may reach the poles.

public static LatLon ClampToMercator(double lat, double lon)

Parameters

lat double

Latitude in degrees WGS84; clamped to +/- MercatorMaxLat.

lon double

Longitude in degrees WGS84, -180 to 180. Not clamped.

Returns

LatLon

A coordinate the projection can represent.

Equals(LatLon)

Exact component-wise equality. No distance tolerance.

public bool Equals(LatLon other)

Parameters

other LatLon

Returns

bool

Equals(object)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns "(lat,lon)".

public override string ToString()

Returns

string