Module: GeographicLib/DMS

Decode/Encode angles expressed as degrees, minutes, and seconds. This module defines several constants:

  • hemisphere indicator (returned by Decode) and a formatting indicator (used by Encode)
    • NONE = 0, no designator and format as plain angle;
    • LATITUDE = 1, a N/S designator and format as latitude;
    • LONGITUDE = 2, an E/W designator and format as longitude;
    • AZIMUTH = 3, format as azimuth;
  • the specification of the trailing component in Encode
    • DEGREE;
    • MINUTE;
    • SECOND.
Source:

Methods

(static) Decode(dms) → {object}

Decode a DMS string.

The interpretation of the string is given in the documentation of the corresponding function, Decode(string&, flag&) in the C++ DMS class

Parameters:
Name Type Description
dms string

the string.

Source:
Throws:

an error if the string is illegal.

Returns:

r where r.val is the decoded value (degrees) and r.ind is a hemisphere designator, one of NONE, LATITUDE, LONGITUDE.

Type
object

(static) DecodeAngle(angstr) → {number}

Decode a DMS string interpreting it as an arc length.

Parameters:
Name Type Description
angstr string

the string (this must not include a hemisphere indicator).

Source:
Throws:

an error if the string is illegal.

Returns:

the arc length (degrees).

Type
number

(static) DecodeAzimuth(azistr) → {number}

Decode a DMS string interpreting it as an azimuth.

Parameters:
Name Type Description
azistr string

the string (this may include an E/W hemisphere indicator).

Source:
Throws:

an error if the string is illegal.

Returns:

the azimuth (degrees).

Type
number

(static) DecodeLatLon(stra, strb, longfirstopt) → {object}

Decode two DMS strings interpreting them as a latitude/longitude pair.

Parameters:
Name Type Attributes Default Description
stra string

the first string.

strb string

the first string.

longfirst bool <optional>
false

if true assume then longitude is given first (in the absense of any hemisphere indicators).

Source:
Throws:

an error if the strings are illegal.

Returns:

r where r.lat is the decoded latitude and r.lon is the decoded longitude (both in degrees).

Type
object

(static) Encode(angle, trailing, prec, indopt) → {string}

Convert angle (in degrees) into a DMS string (using °, ', and ").

Parameters:
Name Type Attributes Default Description
angle number

input angle (degrees).

trailing number

one of DEGREE, MINUTE, or SECOND to indicate the trailing component of the string (this component is given as a decimal number if necessary).

prec number

the number of digits after the decimal point for the trailing component.

ind number <optional>
NONE

a formatting indicator, one of NONE, LATITUDE, LONGITUDE, AZIMUTH.

Source:
Returns:

the resulting string formatted as follows:

  • NONE, signed result no leading zeros on degrees except in the units place, e.g., -8°03'.
  • LATITUDE, trailing N or S hemisphere designator, no sign, pad degrees to 2 digits, e.g., 08°03'S.
  • LONGITUDE, trailing E or W hemisphere designator, no sign, pad degrees to 3 digits, e.g., 008°03'W.
  • AZIMUTH, convert to the range [0, 360°), no sign, pad degrees to 3 digits, e.g., 351°57'.
Type
string