Public Types | Static Public Member Functions

GeographicLib::DMS Class Reference

Convert between degrees and DMS representation. More...

#include <GeographicLib/DMS.hpp>

List of all members.

Public Types

enum  flag {
  NONE, LATITUDE, LONGITUDE, AZIMUTH,
  NUMBER
}
enum  component { DEGREE, MINUTE, SECOND }

Static Public Member Functions

static Math::real Decode (const std::string &dms, flag &ind)
static Math::real Decode (real d, real m=0, real s=0) throw ()
static Math::real Decode (const std::string &str)
static void DecodeLatLon (const std::string &dmsa, const std::string &dmsb, real &lat, real &lon)
static Math::real DecodeAngle (const std::string &angstr)
static Math::real DecodeAzimuth (const std::string &azistr)
static std::string Encode (real angle, component trailing, unsigned prec, flag ind=NONE)
static std::string Encode (real angle, unsigned prec, flag ind=NONE)
static void Encode (real ang, real &d, real &m) throw ()
static void Encode (real ang, real &d, real &m, real &s) throw ()

Detailed Description

Convert between degrees and DMS representation.

Parse a string representing degree, minutes, and seconds and return the angle in degrees and format an angle in degrees as degree, minutes, and seconds.

Definition at line 26 of file DMS.hpp.


Member Enumeration Documentation

Indicator for presence of hemisphere indicator (N/S/E/W) on latitudes and longitudes.

Enumerator:
NONE 

No indicator present.

LATITUDE 

Latitude indicator (N/S) present.

LONGITUDE 

Longitude indicator (E/W) present.

AZIMUTH 

Used in Encode to indicate output of an azimuth in [000, 360) with no letter indicator.

NUMBER 

Used in Encode to indicate output of a plain number.

Definition at line 50 of file DMS.hpp.

Indicator for trailing units on an angle.

Enumerator:
DEGREE 

Trailing unit is degrees.

MINUTE 

Trailing unit is arc minutes.

SECOND 

Trailing unit is arc seconds.

Definition at line 82 of file DMS.hpp.


Member Function Documentation

Math::real GeographicLib::DMS::Decode ( const std::string &  dms,
flag ind 
) [static]

Convert a string in DMS to an angle.

Parameters:
[in] dms string input.
[out] ind a DMS::flag value indicating the presence of a hemisphere indicator.
Returns:
angle (degrees).

Degrees, minutes, and seconds are indicated by the letters d, ', ", and these components may only be given in this order. Any (but not all) components may be omitted. The last component indicator may be omitted and is assumed to be tbe next smallest unit (thus 33d10 is interpreted as 33d10'). The final component may be a decimal fraction but the non-final components must be integers. The integer parts of the minutes and seconds components must be less than 60. A single leading sign is permitted. A hemisphere designator (N, E, W, S) may be added to tbe beginning or end of the string. The result is multiplied by the implied signed of the hemisphere designator (negative for S and W). In addition ind is set to DMS::LATITUDE if N or S is present, to DMS::LONGITUDE if E or W is present, and to DMS::NONE otherwise. Throws an error on a malformed string. No check is performed on the range of the result.

Definition at line 28 of file DMS.cpp.

References LATITUDE, LONGITUDE, and NONE.

Referenced by DecodeAngle(), DecodeAzimuth(), DecodeLatLon(), main(), ReadDistance(), and GeographicLib::GeoCoords::Reset().

static Math::real GeographicLib::DMS::Decode ( real  d,
real  m = 0,
real  s = 0 
) throw () [inline, static]

Convert DMS to an angle.

Parameters:
[in] d degrees.
[in] m arc minutes.
[in] s arc seconds.
Returns:
angle (degrees)

This does not propagate the sign on d to the other components, so -3d20' would need to be represented as - DMS::Decode(3.0, 20.0) or DMS::Decode(-3.0, -20.0).

Definition at line 136 of file DMS.hpp.

Math::real GeographicLib::DMS::Decode ( const std::string &  str  )  [static]

Convert a string to a real number.

Parameters:
[in] str string input.
Returns:
decoded number.

Definition at line 183 of file DMS.cpp.

void GeographicLib::DMS::DecodeLatLon ( const std::string &  dmsa,
const std::string &  dmsb,
real &  lat,
real &  lon 
) [static]

Convert a pait of strings to latitude and longitude.

Parameters:
[in] dmsa first string.
[in] dmsb second string.
[out] lat latitude.
[out] lon longitude.

By default, the lat (resp., lon) is assigned to the results of decoding dmsa (resp., dmsb). However this is overridden if either dmsa or dmsb contain a latitude or longitude hemisphere designator (N, S, E, W). Throws an error if the decoded numbers are out of the ranges [-90o, 90o] for latitude and [-180o, 360o] for longitude and, in which case lat and lon are unchanged. Finally the longitude is reduced to the range [-180o, 180o).

Definition at line 205 of file DMS.cpp.

References Decode(), LATITUDE, LONGITUDE, and NONE.

Referenced by main(), and GeographicLib::GeoCoords::Reset().

Math::real GeographicLib::DMS::DecodeAngle ( const std::string &  angstr  )  [static]

Convert a string to an angle in degrees.

Parameters:
[in] angstr input string.
Returns:
angle (degrees)

No hemisphere designator is allowed and no check is done on the range of the result.

Definition at line 237 of file DMS.cpp.

References Decode(), and NONE.

Referenced by ReadDistance().

Math::real GeographicLib::DMS::DecodeAzimuth ( const std::string &  azistr  )  [static]

Convert a string to an azimuth in degrees.

Parameters:
[in] azistr input string.
Returns:
azimuth (degrees)

A hemisphere designator E/W can be used; the result is multiplied by -1 if W is present. Throws an error if the result is out of the range [-180o, 360o]. Finally the azimuth is reduced to the range [-180o, 180o).

Definition at line 246 of file DMS.cpp.

References Decode(), and LATITUDE.

Referenced by main().

string GeographicLib::DMS::Encode ( real  angle,
component  trailing,
unsigned  prec,
flag  ind = NONE 
) [static]

Convert angle (in degrees) into a DMS string.

Parameters:
[in] angle input angle (degrees)
[in] trailing DMS::component value indicating the trailing units on the string and this is given as a decimal number if necessary.
[in] prec the number of digits after the decimal point for the trailing component.
[in] ind DMS::flag value indicated additional formatting.
Returns:
formatted string

The interpretation of ind is as follows:

  • ind == DMS::NONE, signed result no leading zeros on degrees except in the units place, e.g., -8d03'.
  • ind == DMS::LATITUDE, trailing N or S hemisphere designator, no sign, pad degrees to 2 digits, e.g., 08d03'S.
  • ind == DMS::LONGITUDE, trailing E or W hemisphere designator, no sign, pad degrees to 3 digits, e.g., 008d03'W.
  • ind == DMS::AZIMUTH, convert to the range [0, 360o), no sign, pad degrees to 3 digits, , e.g., 351d57'.

The integer parts of the minutes and seconds components are always given with 2 digits.

Definition at line 258 of file DMS.cpp.

References AZIMUTH, DEGREE, GeographicLib::Math::isfinite(), LATITUDE, MINUTE, NONE, and SECOND.

Referenced by AzimuthString(), DistanceStrings(), GeographicLib::GeoCoords::DMSRepresentation(), Encode(), LatLonString(), and main().

static std::string GeographicLib::DMS::Encode ( real  angle,
unsigned  prec,
flag  ind = NONE 
) [inline, static]

Convert angle into a DMS string selecting the trailing component based on the precision.

Parameters:
[in] angle input angle (degrees)
[in] prec the precision relative to 1 degree.
[in] ind DMS::flag value indicated additional formatting.
Returns:
formatted string

prec indicates the precision relative to 1 degree, e.g., prec = 3 gives a result accurate to 0.1' and prec = 4 gives a result accurate to 1". ind is interpreted as in DMS::Encode with the additional facility at DMS::NUMBER treats angle a number in fixed format with precision prec.

Definition at line 233 of file DMS.hpp.

References DEGREE, Encode(), GeographicLib::Math::isfinite(), MINUTE, NUMBER, and SECOND.

static void GeographicLib::DMS::Encode ( real  ang,
real &  d,
real &  m 
) throw () [inline, static]

Split angle into degrees and mintues

Parameters:
[in] ang angle (degrees)
[out] d degrees (an integer returned as a real)
[out] m arc minutes.

Definition at line 255 of file DMS.hpp.

static void GeographicLib::DMS::Encode ( real  ang,
real &  d,
real &  m,
real &  s 
) throw () [inline, static]

Split angle into degrees and mintues and seconds.

Parameters:
[in] ang angle (degrees)
[out] d degrees (an integer returned as a real)
[out] m arc minutes (an integer returned as a real)
[out] s arc seconds.

Definition at line 267 of file DMS.hpp.


The documentation for this class was generated from the following files: