00001 using System; 00002 using System.Collections.Generic; 00003 using System.Linq; 00004 using System.Text; 00005 using System.IO; 00006 00007 namespace GoogleEarthKMLConverter { 00008 class Program { 00009 static void Main(string[] args) { 00010 FileStream fs = new FileStream(args[0], FileMode.Open); 00011 StreamReader sr = new StreamReader(fs); 00012 string s = sr.ReadToEnd(); 00013 fs.Close(); 00014 sr.Close(); 00015 s = s.Substring(s.IndexOf("<coordinates>") 00016 , s.IndexOf("</coordinates>") - s.IndexOf("<coordinates>")); 00017 s = s.Replace("-", ""); 00018 s = s.Replace("\n", ","); 00019 s = s.Replace(" ", ","); 00020 s = s.Replace("<coordinates>", ""); 00021 List<double> latArray = new List<double>(); 00022 List<double> lonArray = new List<double>(); 00023 string num; 00024 while (s != ",") { 00025 num = s.Substring(s.IndexOf(",") + 1, s.IndexOf(",", s.IndexOf(",") + 1) - 1); 00026 lonArray.Add(double.Parse(num)); 00027 s = s.Remove(0, s.IndexOf(",", s.IndexOf(",") + 1)); 00028 num = s.Substring(s.IndexOf(",") + 1, s.IndexOf(",", s.IndexOf(",") + 1) - 1); 00029 latArray.Add(double.Parse(num)); 00030 s = s.Remove(0, s.IndexOf(",", s.IndexOf(",") + 1)); 00031 s = s.Remove(0, s.IndexOf(",", s.IndexOf(",") + 1)); 00032 } 00033 Console.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"); 00034 Console.Write("<lat_lon_point_set location=\"" + args[0] + "\" datum=\"NAD83/WGS84\">\r\n"); 00035 for (int i = 0; i < lonArray.Count; i++) { 00036 Console.Write("<ddd_dd lat=\"" + latArray[i] + "\" ns=\"N\" lon=\""); 00037 Console.Write(lonArray[i] + "\" ew=\"W\" note=\"dummy\" handle=\"0\" />\r\n"); 00038 } 00039 Console.Write("</lat_lon_point_set>"); 00040 00041 } 00042 } 00043 }