00001 using System; 00002 using System.Collections.Generic; 00003 using System.ComponentModel; 00004 using System.Data; 00005 using System.Drawing; 00006 using System.Linq; 00007 using System.Text; 00008 using System.Windows.Forms; 00009 00010 namespace UtmConvert { 00011 public partial class UtmConvertMainForm : Form { 00012 00013 ConvertLatLonUtm con; 00014 XmlParser _parser; 00015 internal XmlParser Parser { 00016 get { return _parser; } 00017 } 00018 00019 public UtmConvertMainForm() { 00020 InitializeComponent(); 00021 _parser = new XmlParser(); 00022 con = new ConvertLatLonUtm(); 00023 foreach (Datum d in Datums.datumList) 00024 datumsListBox.Items.Add(d.Name); 00025 datumsListBox.SelectedIndex = 0; 00026 northSouthComboBox.SelectedIndex = 0; 00027 eastWestComboBox.SelectedIndex = 1; 00028 latLonFormatToolStripComboBox.SelectedIndex = 0; 00029 convertLatLonToUtm(); 00030 } 00031 00032 private void datumsListBox_SelectedIndexChanged(object sender, EventArgs e) { 00033 foreach (Datum d in Datums.datumList) { 00034 if (d.Name == datumsListBox.SelectedItem.ToString()) { 00035 datumPropertyGrid.SelectedObject = d; 00036 con.Datum = d; 00037 } 00038 } 00039 } 00040 00041 00042 private void convertButton_Click(object sender, EventArgs e) { 00043 if (latLonToUtmRadioButton.Checked) 00044 convertLatLonToUtm(); 00045 else 00046 convertUtmToLatLon(); 00047 } 00048 00049 private void convertLatLonToUtm() { 00050 double lat = 0, lon = 0; 00051 bool nS = (northSouthComboBox.Text != "N"); 00052 bool eW = (eastWestComboBox.Text != "E"); 00053 if (latDegTextBox.Text != "" && latMinTextBox.Text != "" && latSecTextBox.Text != "") 00054 lat = ConvertDegRad.getRadians(latDegTextBox.Text, latMinTextBox.Text 00055 , latSecTextBox.Text, northSouthComboBox.Text[0]); 00056 else if (latDegTextBox.Text != "" && latMinTextBox.Text != "") 00057 lat = ConvertDegRad.getRadians(latDegTextBox.Text 00058 , latMinTextBox.Text, northSouthComboBox.Text[0]); 00059 else if (latDegTextBox.Text != "") 00060 lat = ConvertDegRad.getRadians(latDegTextBox.Text, northSouthComboBox.Text[0]); 00061 latInRad.Text = Math.Round(lat, 4).ToString(); 00062 if (lonDegTextBox.Text != "" && lonMinTextBox.Text != "" && lonSecTextBox.Text != "") 00063 lon = ConvertDegRad.getRadians(lonDegTextBox.Text, lonMinTextBox.Text 00064 , lonSecTextBox.Text, eastWestComboBox.Text[0]); 00065 else if (lonDegTextBox.Text != "" && lonMinTextBox.Text != "") 00066 lon = ConvertDegRad.getRadians(lonDegTextBox.Text 00067 , lonMinTextBox.Text, eastWestComboBox.Text[0]); 00068 else if (lonDegTextBox.Text != "") 00069 lon = ConvertDegRad.getRadians(lonDegTextBox.Text, eastWestComboBox.Text[0]); 00070 lonInRad.Text = Math.Round(lon, 4).ToString(); 00071 con.convertLatLonToUtm(lat, lon); 00072 eastingTextBox.Text = Math.Round(con.Easting, 2).ToString(); 00073 northingTextBox.Text = Math.Round(con.Northing, 2).ToString(); 00074 zoneTextBox.Text = con.Zone; 00075 latToolStripStatusLabel.Text = ConvertDegRad.getDegrees(Math.Abs(lat)).ToString() 00076 + " " + northSouthComboBox.Text + ", "; 00077 lonToolStripStatusLabel.Text = ConvertDegRad.getDegrees(Math.Abs(lon)).ToString() 00078 + " " + eastWestComboBox.Text + ", "; 00079 } 00080 00081 private void convertUtmToLatLon() { 00082 if (eastingTextBox.Text != "" || northingTextBox.Text != "") { 00083 double e = 0, n = 0; 00084 double.TryParse(eastingTextBox.Text, out e); 00085 double.TryParse(northingTextBox.Text, out n); 00086 con.convertUtmToLatLon(e, n, zoneTextBox.Text); 00087 if (con.Latitude > 0) 00088 northSouthComboBox.SelectedIndex = 0; 00089 else 00090 northSouthComboBox.SelectedIndex = 1; 00091 latDegTextBox.Text = ConvertDegRad.getDegrees(Math.Abs(con.Latitude)).ToString(); 00092 latMinTextBox.Clear(); 00093 latSecTextBox.Clear(); 00094 if (con.Longitude > 0) 00095 eastWestComboBox.SelectedIndex = 0; 00096 else 00097 eastWestComboBox.SelectedIndex = 1; 00098 lonDegTextBox.Text = ConvertDegRad.getDegrees(Math.Abs(con.Longitude)).ToString(); 00099 lonMinTextBox.Clear(); 00100 lonSecTextBox.Clear(); 00101 } 00102 } 00103 00104 private void convertingUTMToLatitudeLongitudepdfToolStripMenuItem_Click(object sender, EventArgs e) { 00105 DocViewer dv = new DocViewer(); 00106 dv.Show(); 00107 ToolStripMenuItem t = (ToolStripMenuItem)sender; 00108 dv.viewDocument(t.Text); 00109 } 00110 00111 private void theUniversalTransverseMercatorSystempdfToolStripMenuItem_Click(object sender, EventArgs e) { 00112 DocViewer dv = new DocViewer(); 00113 dv.Show(); 00114 ToolStripMenuItem t = (ToolStripMenuItem)sender; 00115 dv.viewDocument(t.Text); 00116 } 00117 00118 private void utmzonesjpgToolStripMenuItem_Click(object sender, EventArgs e) { 00119 DocViewer dv = new DocViewer(); 00120 dv.Show(); 00121 ToolStripMenuItem t = (ToolStripMenuItem)sender; 00122 dv.viewDocument(t.Text); 00123 } 00124 00125 private void uTMConversions1xlsToolStripMenuItem_Click(object sender, EventArgs e) { 00126 DocViewer dv = new DocViewer(); 00127 dv.Show(); 00128 ToolStripMenuItem t = (ToolStripMenuItem)sender; 00129 dv.viewDocument(t.Text); 00130 } 00131 00132 private void zoneCentralMeridianspdfToolStripMenuItem_Click(object sender, EventArgs e) { 00133 DocViewer dv = new DocViewer(); 00134 dv.Show(); 00135 ToolStripMenuItem t = (ToolStripMenuItem)sender; 00136 dv.viewDocument(t.Text); 00137 } 00138 00139 private void exitToolStripMenuItem_Click(object sender, EventArgs e) { 00140 this.Dispose(); 00141 } 00142 00143 private void sourceCodeToolStripMenuItem_Click(object sender, EventArgs e) { 00144 DocViewer dv = new DocViewer(); 00145 dv.Show(); 00146 dv.viewDocument(".\\html\\index.html"); 00147 } 00148 00149 private void aboutUtmConvertToolStripMenuItem_Click(object sender, EventArgs e) { 00150 AboutBoxMainForm a = new AboutBoxMainForm(); 00151 a.Show(); 00152 } 00153 00154 private void openToolStripMenuItem_Click(object sender, EventArgs e) { 00155 xmlOpenFileDialog.ShowDialog(); 00156 } 00157 00158 private void xmlOpenFileDialog_FileOk(object sender, CancelEventArgs e) { 00159 _parser = new XmlParser(); 00160 _parser.readFile(xmlOpenFileDialog.FileName); 00161 inputXmlTextBox.Text = _parser.FileString; 00162 _parser.Parse(latLonFormatToolStripComboBox.Text); 00163 parserToolStripStatusLabel.Text = "Read: " + _parser.Status + ", "; 00164 utmPointsTextBox.Clear(); 00165 foreach (UtmPointSet ps in _parser.UtmPointSetList) { 00166 foreach(UtmPoint pt in ps.Points) 00167 utmPointsTextBox.AppendText("x: " + pt.Point.X + ", y: " + pt.Point.Y 00168 + ", z: " + pt.Zone + ", n: " + pt.Note + "\r\n"); 00169 } 00170 if (_parser.UtmPointSetList.Count > 0) { 00171 Printer print = new Printer(); 00172 printerToolStripStatusLabel.Text = 00173 print.writeUtmXmlFile(_parser.UtmPointSetList); 00174 outputXmlTextBox.Text = print.Output; 00175 } 00176 latLonPointsTextBox.Clear(); 00177 foreach (LatLonPointSet ps in _parser.LatLonPointSetList) { 00178 foreach (LatLonPoint pt in ps.Points) 00179 latLonPointsTextBox.AppendText("lat: " 00180 + pt.Lat + ", ns: " + pt.Ns 00181 + ", lon: " + pt.Lon + ", ew: " 00182 + pt.Ew + ", n: " + pt.Note + "\r\n"); 00183 } 00184 if (_parser.LatLonPointSetList.Count > 0) { 00185 Printer print = new Printer(); 00186 printerToolStripStatusLabel.Text = 00187 print.writeLatLonXmlFile(_parser.LatLonPointSetList); 00188 outputXmlTextBox.Text = print.Output; 00189 } 00190 utmPointsTextBox.AppendText("Status: " + _parser.Status); 00191 latLonPointsTextBox.AppendText("Status " + _parser.Status); 00192 } 00193 00194 } 00195 }