Convert a string in DMS to an angle.
- Parameters
-
[in] | dms | string input. |
[out] | ind | a DMS::flag value signaling the presence of a hemisphere indicator. |
- Exceptions
-
- Returns
- angle (degrees).
Degrees, minutes, and seconds are indicated by the characters d, ' (single quote), " (double quote), and these components may only be given in this order. Any (but not all) components may be omitted and other symbols (e.g., the ° symbol for degrees and the unicode prime and double prime symbols for minutes and seconds) may be substituted; two single quotes can be used instead of ". The last component indicator may be omitted and is assumed to be the 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. Instead of using d, ', and " to indicate degrees, minutes, and seconds, : (colon) may be used to separate these components (numbers must appear before and after each colon); thus 50d30'10.3" may be written as 50:30:10.3, 5.5' may be written 0:5.5, and so on. 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 the beginning or end of the string. The result is multiplied by the implied sign 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. Examples of legal and illegal strings are
- LEGAL (all the entries on each line are equivalent)
- -20.51125, 20d30'40.5"S, -20°30'40.5, -20d30.675, N-20d30'40.5", -20:30:40.5
- 4d0'9, 4d9", 4d9'', 4:0:9, 004:00:09, 4.0025, 4.0025d, 4d0.15, 04:.15
- 4:59.99999999999999, 4:60.0, 4:59:59.9999999999999, 4:59:60.0, 5
- ILLEGAL (the exception thrown explains the problem)
- 4d5"4', 4::5, 4:5:, :4:5, 4d4.5'4", -N20.5, 1.8e2d, 4:60, 4:59:60
The decoding operation can also perform addition and subtraction operations. If the string includes internal signs (i.e., not at the beginning nor immediately after an initial hemisphere designator), then the string is split immediately before such signs and each piece is decoded according to the above rules and the results added; thus S3-2.5+4.1N
is parsed as the sum of S3
, -2.5
, +4.1N
. Any piece can include a hemisphere designator; however, if multiple designators are given, they must compatible; e.g., you cannot mix N and E. In addition, the designator can appear at the beginning or end of the first piece, but must be at the end of all subsequent pieces (a hemisphere designator is not allowed after the initial sign). Examples of legal and illegal combinations are
- LEGAL (these are all equivalent)
- 070:00:45, 70:01:15W+0:0.5, 70:01:15W-0:0:30W, W70:01:15+0:0:30E
- ILLEGAL (the exception thrown explains the problem)
- 70:01:15W+0:0:15N, W70:01:15+W0:0:15
WARNING: "Exponential" notation is not recognized. Thus 7.0E1
is illegal, while 7.0E+1
is parsed as (7.0E) + (+1)
, yielding the same result as 8.0E
.
NOTE: At present, all the string handling in the C++ implementation GeographicLib is with 8-bit characters. The support for unicode symbols for degrees, minutes, and seconds is therefore via the UTF-8 encoding. (The JavaScript implementation of this class uses unicode natively, of course.)
Here is the list of Unicode symbols supported for degrees, minutes, seconds:
- degrees:
- d, D lower and upper case letters
- U+00b0 degree symbol (°)
- U+00ba masculine ordinal indicator
- U+2070 superscript zero
- U+02da ring above
- minutes:
- ' apostrophe
- U+2032 prime (′)
- U+00b4 acute accent
- U+2019 right single quote (’)
- seconds:
- " quotation mark
- U+2033 double prime (″)
- U+201d right double quote (”)
- ' ' any two consecutive symbols for minutes
The codes with a leading zero byte, e.g., U+00b0, are accepted in their UTF-8 coded form 0xc2 0xb0 and as a single byte 0xb0.