Convert between degrees and DMS representation. More...
#include <GeographicLib/DMS.hpp>
Public Types | |
enum | flag { NONE = 0, LATITUDE = 1, LONGITUDE = 2, AZIMUTH = 3, NUMBER = 4 } |
enum | component { DEGREE = 0, MINUTE = 1, SECOND = 2 } |
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 () |
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.
Indicator for presence of hemisphere indicator (N/S/E/W) on latitudes and longitudes. DMS::AZIMUTH is used in Encode to indicate output in [000, 360) with no letter indicator. DMS::NUMBER is used in Encode to indicate the output of a plain number.
Math::real GeographicLib::DMS::Decode | ( | const std::string & | dms, | |
flag & | ind | |||
) | [static] |
Read a string dms in DMS format and return the resulting angle in 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 flag is used to indicate whether such a designator was found and whether it implies that the angle is a latitude (N or S) or longitude (E or W). Throws an error on a malformed string. No check is performed on the range of the result.
Definition at line 27 of file DMS.cpp.
References LATITUDE, LONGITUDE, and NONE.
Referenced by DecodeAngle(), DecodeAzimuth(), and DecodeLatLon().
static Math::real GeographicLib::DMS::Decode | ( | real | d, | |
real | m = 0 , |
|||
real | s = 0 | |||
) | throw () [inline, static] |
Convert real degrees d, minutes m, and seconds s, to 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).
Math::real GeographicLib::DMS::Decode | ( | const std::string & | str | ) | [static] |
void GeographicLib::DMS::DecodeLatLon | ( | const std::string & | dmsa, | |
const std::string & | dmsb, | |||
real & | lat, | |||
real & | lon | |||
) | [static] |
Convert two strings dmsa and dmsb to a latitude, lat, and longitude, lon. 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 167 of file DMS.cpp.
References Decode(), LATITUDE, LONGITUDE, and NONE.
Referenced by GeographicLib::GeoCoords::Reset().
Math::real GeographicLib::DMS::DecodeAngle | ( | const std::string & | angstr | ) | [static] |
Math::real GeographicLib::DMS::DecodeAzimuth | ( | const std::string & | azistr | ) | [static] |
Convert a string azistr to an azimuth in 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).
string GeographicLib::DMS::Encode | ( | real | angle, | |
component | trailing, | |||
unsigned | prec, | |||
flag | ind = NONE | |||
) | [static] |
Convert angle (in degrees) into a DMS string. trailing indicates the least significant component of the string (and this component is given as a decimal number if necessary). prec indicates the number of digits after the decimal point for the trailing component. flag indicates additional formating as follows
The integer parts of the minutes and seconds components are always given with 2 digits.
Definition at line 220 of file DMS.cpp.
References AZIMUTH, DEGREE, LATITUDE, MINUTE, NONE, and SECOND.
Referenced by GeographicLib::GeoCoords::DMSRepresentation(), and Encode().
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 prec. 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". If ind is DMS::NUMBER, then merely format angle as a number in fixed format with precision prec.
static void GeographicLib::DMS::Encode | ( | real | ang, | |
real & | d, | |||
real & | m | |||
) | throw () [inline, static] |
static void GeographicLib::DMS::Encode | ( | real | ang, | |
real & | d, | |||
real & | m, | |||
real & | s | |||
) | throw () [inline, static] |