00001 using System; 00002 using System.Collections.Generic; 00003 using System.Linq; 00004 using System.Text; 00005 using System.IO; 00006 using System.Windows.Forms; 00007 00008 namespace UtmConvert { 00009 public class Printer { 00010 00011 public delegate void updateErrorEventHandler(Exception error); 00012 public event updateErrorEventHandler updateErrorEvent; 00013 00014 string _status = "ok"; 00015 public string Status { 00016 get { return _status; } 00017 } 00018 00019 string _output = ""; 00020 public string Output { 00021 get { return _output; } 00022 } 00023 00024 public string writeUtmXmlFile(List<UtmPointSet> lps) { 00025 _status = "ok"; 00026 try { 00027 StreamWriter sWrite = new StreamWriter(lps[0] 00028 .LocationName + ".xml", false, Encoding.UTF8); 00029 _output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n\r\n"; 00030 foreach (UtmPointSet ps in lps) { 00031 _output = _output + "<utm_point_set location=\"" 00032 + ps.LocationName + "\" datum=\"" + ps.Datum + "\">\r\n"; 00033 foreach (UtmPoint pt in ps.Points) 00034 _output = _output + "\t<dd_dd easting=\"" + pt.Point.X 00035 + "\" northing=\"" + pt.Point.Y + "\" zone=\"" 00036 + pt.Zone + "\" note=\"" + pt.Note 00037 + "\" handle=\"" + pt.Handle + "\" />\r\n"; 00038 _output = _output + "</utm_point_set>\r\n"; 00039 } 00040 sWrite.Write(_output); 00041 sWrite.Close(); 00042 return "utm_" + lps[0].LocationName + ".xml"; 00043 } catch (Exception e) { 00044 if (updateErrorEvent != null) 00045 updateErrorEvent.Invoke(e); 00046 _status = e.Message; 00047 return _status; 00048 } 00049 } 00050 00051 public string writeLatLonXmlFile(List<LatLonPointSet> lps) { 00052 _status = "ok"; 00053 try { 00054 StreamWriter sWrite = new StreamWriter(lps[0] 00055 .LocationName + ".xml", false, Encoding.UTF8); 00056 _output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n\r\n"; 00057 foreach (LatLonPointSet ps in lps) { 00058 _output = _output + "<lat_lon_point_set location=\"" + ps.LocationName 00059 + "\" datum=\"" + ps.Datum + "\">\r\n"; 00060 foreach (LatLonPoint pt in ps.Points) { 00061 if (pt.Format == "ddd_dd") 00062 _output = _output + "\t<" + pt.Format + " " + "lat=\"" 00063 + ConvertDegRad.getDegrees(Math.Abs(pt.Lat)) 00064 + "\" ns=\"" + pt.Ns + "\" lon=\"" 00065 + ConvertDegRad.getDegrees(Math.Abs(pt.Lon)) 00066 + "\" ew=\"" + pt.Ew + "\" note=\"" + pt.Note 00067 +"\" handle=\"" + pt.Handle + "\" />\r\n"; 00068 else if (pt.Format == "ddd_mm_mm") 00069 _output = _output + "\t<" + pt.Format + " " + "lat=\"" 00070 + ConvertDegRad.getDegreesMin(Math.Abs(pt.Lat)) 00071 + "\" ns=\"" + pt.Ns + "\" lon=\"" 00072 + ConvertDegRad.getDegreesMin(Math.Abs(pt.Lon)) 00073 + "\" ew=\"" + pt.Ew + "\" note=\"" + pt.Note 00074 +"\" handle=\"" + pt.Handle + "\" />\r\n"; 00075 else 00076 _output = _output + "\t<" + pt.Format + " " + "lat=\"" 00077 + ConvertDegRad.getDegreesMinSec(Math.Abs(pt.Lat)) 00078 + "\" ns=\"" + pt.Ns + "\" lon=\"" 00079 + ConvertDegRad.getDegreesMinSec(Math.Abs(pt.Lon)) 00080 + "\" ew=\"" + pt.Ew + "\" note=\"" + pt.Note 00081 +"\" handle=\"" + pt.Handle + "\" />\r\n"; 00082 } 00083 _output = _output + "</lat_lon_point_set>\r\n"; 00084 } 00085 sWrite.Write(_output); 00086 sWrite.Close(); 00087 return "lat_lon_" + lps[0].LocationName + ".xml"; 00088 } catch (Exception e) { 00089 if (updateErrorEvent != null) 00090 updateErrorEvent.Invoke(e); 00091 _status = e.Message; 00092 return _status; 00093 } 00094 } 00095 } 00096 00097 00098 }