00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004 using System.Text;
00005
00006 namespace UtmConvert {
00007 public static class ConvertDegRad {
00008
00009 public delegate void updateErrorEventHandler(Exception error);
00010 public static event updateErrorEventHandler updateErrorEvent;
00011
00012 static string _status = "ok";
00013 public static string Status {
00014 get { return ConvertDegRad._status; }
00015 }
00016
00017
00018 public static double getRadians(string degrees
00019 , string minutes, string seconds, char direction) {
00020 _status = "ok";
00021 try {
00022 if (direction == 'S' || direction == 'W')
00023 return -(Math.PI / 180) * (double.Parse(degrees)
00024 + double.Parse(minutes) / 60 + double.Parse(seconds) / 3600);
00025 return (Math.PI / 180) * (double.Parse(degrees)
00026 + double.Parse(minutes) / 60 + double.Parse(seconds) / 3600);
00027 } catch (Exception e) {
00028 if (updateErrorEvent != null)
00029 updateErrorEvent.Invoke(e);
00030 _status = "not a number: " + e.Message;
00031 return -1;
00032 }
00033 }
00034
00035 public static double getRadians(string degrees
00036 , string minutes, char direction) {
00037 _status = "ok";
00038 try {
00039 if (direction == 'S' || direction == 'W')
00040 return -(Math.PI / 180) * (double.Parse(degrees)
00041 + double.Parse(minutes) / 60);
00042 return (Math.PI / 180)*(double.Parse(degrees)
00043 + double.Parse(minutes) / 60);
00044 } catch (Exception e) {
00045 if (updateErrorEvent != null)
00046 updateErrorEvent.Invoke(e);
00047 _status = "not a number: " + e.Message;
00048 return -1;
00049 }
00050 }
00051
00052 public static double getRadians(string degrees, char direction) {
00053 _status = "ok";
00054 try {
00055 if (direction == 'S' || direction == 'W')
00056 return -(Math.PI / 180) * (double.Parse(degrees));
00057 return (Math.PI / 180)*(double.Parse(degrees));
00058 } catch (Exception e) {
00059 if (updateErrorEvent != null)
00060 updateErrorEvent.Invoke(e);
00061 _status = "not a number: " + e.Message;
00062 return -1;
00063 }
00064 }
00065
00066
00067 public static double getRadians(double degrees) {
00068 return (Math.PI / 180) * degrees;
00069 }
00070
00071 public static double getDegrees(double rad) {
00072 return rad / (Math.PI / 180);
00073 }
00074
00075 public static string getDegreesMin(double rad) {
00076 string dd_ff = (rad / (Math.PI / 180)).ToString();
00077 string mm_ff = (double.Parse(dd_ff.Substring(dd_ff.IndexOf(".")
00078 , dd_ff.Length - dd_ff.IndexOf("."))) * 60).ToString();
00079 dd_ff = dd_ff.Substring(0, dd_ff.IndexOf("."));
00080 return dd_ff + " " + mm_ff;
00081 }
00082
00083 public static string getDegreesMinSec(double rad) {
00084 string dd_ff = (rad / (Math.PI / 180)).ToString();
00085 string mm_ff = (double.Parse(dd_ff.Substring(dd_ff.IndexOf(".")
00086 , dd_ff.Length - dd_ff.IndexOf("."))) * 60).ToString();
00087 string ss_ff = (double.Parse(mm_ff.Substring(mm_ff.IndexOf(".")
00088 , mm_ff.Length - mm_ff.IndexOf("."))) * 60).ToString();
00089 dd_ff = dd_ff.Substring(0, dd_ff.IndexOf("."));
00090 mm_ff = mm_ff.Substring(0, mm_ff.IndexOf("."));
00091 return dd_ff + " " + mm_ff + " " + ss_ff;
00092 }
00093
00094 }
00095 }