|
static double | Decode (System::String^ dms, [System::Runtime::InteropServices::Out] Flag% ind) |
|
static double | Decode (double d, double m, double s) |
|
static void | DecodeLatLon (System::String^ dmsa, System::String^ dmsb, [System::Runtime::InteropServices::Out] double% lat, [System::Runtime::InteropServices::Out] double% lon, bool swaplatlong) |
|
static double | DecodeAngle (System::String^ angstr) |
|
static double | DecodeAzimuth (System::String^ azistr) |
|
static System::String^ | Encode (double angle, Component trailing, unsigned prec, Flag ind, char dmssep) |
|
static System::String^ | Encode (double angle, unsigned prec, Flag ind, char dmssep) |
|
static void | Encode (double ang, [System::Runtime::InteropServices::Out] double% d, [System::Runtime::InteropServices::Out] double% m) |
|
static void | Encode (double ang, [System::Runtime::InteropServices::Out] double% d, [System::Runtime::InteropServices::Out] double% m, [System::Runtime::InteropServices::Out] double% s) |
|
.NET wrapper for GeographicLib::DMS.
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. In addition, handle NANs and infinities on input and output.
C# Example:
namespace example_DMS
{
class Program
{
static void Main(string[] args)
{
try {
{
string dms = "30d14'45.6\"S";
DMS.Flag type;
double ang = DMS.Decode(dms, out type);
Console.WriteLine(String.Format("Type: {0} String: {1}", type, ang));
}
{
double ang = -30.245715;
string dms = DMS.Encode(ang, 6, DMS.Flag.LATITUDE, 0);
Console.WriteLine(String.Format("Latitude: {0}", dms));
}
}
catch (GeographicErr e) {
Console.WriteLine( String.Format( "Caught exception: {0}", e.Message ) );
}
}
}
}
Managed C++ Example:
int main(array<System::String ^> ^)
{
try {
{
System::String^ dms = "30d14'45.6\"S";
Console::WriteLine(String::Format("Type: {0} String: {1}", type, ang));
}
{
double ang = -30.245715;
Console::WriteLine(String::Format("Latitude: {0}", dms));
}
}
Console::WriteLine( String::Format( "Caught exception: {0}", e->Message ) );
return -1;
}
return 0;
}
Visual Basic Example:
Imports NETGeographicLib
Module example_DMS
Sub Main()
Try
Dim desc As String = "30d14'45.6""S"
Dim type As DMS.Flag
Dim ang As Double = DMS.Decode(desc, type)
Console.WriteLine(String.Format("Type: {0} String: {1}", type, ang))
ang = -30.245715
Dim prec As UInteger = 6
desc = DMS.Encode(ang, prec, DMS.Flag.LATITUDE, 0)
Console.WriteLine(String.Format("Latitude: {0}", desc))
Catch ex As GeographicErr
Console.WriteLine(String.Format("Caught exception: {0}", ex.Message))
End Try
End Sub
End Module
Definition at line 29 of file DMS.h.
static double NETGeographicLib::DMS::Decode |
( |
System::String^ |
dms, |
|
|
[System::Runtime::InteropServices::Out] Flag% |
ind |
|
) |
| |
|
static |
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
- 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
- ILLEGAL (the exception thrown explains the problem)
- 4d5"4', 4::5, 4:5:, :4:5, 4d4.5'4", -N20.5, 1.8e2d, 4:60, 4d-5'
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.