Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using System.Xml;
  9.  
  10. namespace gpxtotxt
  11. {
  12.     class Program
  13.     {
  14.         static List<XmlDocument> docList = new List<XmlDocument>();
  15.         static XmlDocument doc = new XmlDocument();
  16.         static int colsWPT = 0;
  17.         static int rowsWPT = 1;
  18.         static int colsTRK = 0;
  19.         static int rowsTRK = 1;
  20.         static void CzytajPliki(String path)
  21.         {
  22.             try
  23.             {
  24.                 Console.WriteLine("Loading files:");
  25.                 for (int i = 0; i < Directory.GetFiles(path, "*.gpx").Length; i++)
  26.                 {
  27.                     doc.Load(Directory.GetFiles(path)[i]);
  28.                     docList.Add(doc);
  29.                     Console.WriteLine(Directory.GetFiles(path, "*.gpx")[i]);
  30.                     Thread.Sleep(500);
  31.                 }
  32.  
  33.             }
  34.             catch (Exception e)
  35.             {
  36.                 Console.WriteLine("{0} Caught exception.", e);
  37.                 Thread.Sleep(10000);
  38.             }
  39.         }
  40.         static void SprawdzPliki()
  41.         {
  42.             for (int j = 0; j < docList.Count; j++)
  43.             {
  44.                 if(docList[j].GetElementsByTagName("wpt").Count >0)
  45.                 {
  46.                     rowsWPT += docList[j].GetElementsByTagName("wpt").Count;
  47.                     colsWPT = docList[j].GetElementsByTagName("wpt")[0].ChildNodes.Count+3; //+5 => lat and lon
  48.                 }
  49.                 if(docList[j].GetElementsByTagName("trkpt").Count > 0)
  50.                 {
  51.                     rowsTRK += docList[j].GetElementsByTagName("trkpt").Count;
  52.                     colsTRK = docList[j].GetElementsByTagName("trkpt")[0].ChildNodes.Count + 3; //+2 => lat and lon + name which is elsewhere
  53.                 }
  54.             }
  55.         }
  56.         static void TworzTabele()
  57.         {
  58.             String[][] arrayWPT = new String[rowsWPT][];
  59.             String[][] arrayTRK = new String[rowsTRK][];
  60.             for (int i = 0; i < arrayWPT.Length; i++)
  61.             {
  62.                 arrayWPT[i] = new string[colsWPT];
  63.             }
  64.             for (int i = 0; i < arrayTRK.Length; i++)
  65.             {
  66.                 arrayTRK[i] = new string[colsTRK];
  67.             }
  68.             for (int j = 0; j < docList.Count; j++)
  69.             {
  70.                 if (docList[j].GetElementsByTagName("wpt").Count > 0)
  71.                 {
  72.                     for (int h = 0; h < docList[j].GetElementsByTagName("wpt")[0].ChildNodes.Count; h++) // wypisz nazwy
  73.                     {
  74.  
  75.                         //if(x[z].childNodes[i].nodeName == "desc")
  76.                         //  {
  77.                         //  txt += strip(x[z].childNodes[i].childNodes[0].nodeValue) + "<br>";
  78.                         //}
  79.                         //else
  80.                         //{
  81.                         //txtNames.Add(docList[j].GetElementsByTagName("wpt")[0].ChildNodes[h].Name + "|");
  82.                         arrayWPT[0][h] = docList[j].GetElementsByTagName("wpt")[0].ChildNodes[h].Name + "|";
  83.                         // Console.WriteLine(txtItem[0]);
  84.                         // Thread.Sleep(20000);
  85.                     }
  86.                    
  87.                     for (int z = 1; z <= docList[j].GetElementsByTagName("wpt").Count; z++)
  88.                     {
  89.                         for (int g = 0; g < docList[j].GetElementsByTagName("wpt")[z-1].ChildNodes.Count; g++)
  90.                         {
  91.                            
  92.                             arrayWPT[z][g] = docList[j].GetElementsByTagName("wpt")[z-1].ChildNodes[g].InnerText + "|";
  93.                         }
  94.  
  95.                     }
  96.                 }
  97.  
  98.                 if (docList[j].GetElementsByTagName("trkpt").Count > 0)
  99.                 {
  100.                     for (int h = 0; h < docList[j].GetElementsByTagName("trkpt")[0].ChildNodes.Count; h++) // wypisz nazwy
  101.                     {
  102.  
  103.                         //if(x[z].childNodes[i].nodeName == "desc")
  104.                         //  {
  105.                         //  txt += strip(x[z].childNodes[i].childNodes[0].nodeValue) + "<br>";
  106.                         //}
  107.                         //else
  108.                         //{
  109.                         //txtNames.Add(docList[j].GetElementsByTagName("wpt")[0].ChildNodes[h].Name + "|");
  110.                         arrayTRK[0][h] = docList[j].GetElementsByTagName("trkpt")[0].ChildNodes[h].Name + "|";
  111.                         // Console.WriteLine(txtItem[0]);
  112.                         // Thread.Sleep(20000);
  113.                     }
  114.                    
  115.                     for (int z = 1; z < docList[j].GetElementsByTagName("trkpt").Count + 1; z++)
  116.                     {
  117.                         for (int g = 0; g < docList[j].GetElementsByTagName("trkpt")[z].ChildNodes.Count; g++)
  118.                         {
  119.                            
  120.                             arrayTRK[z][g] = docList[j].GetElementsByTagName("trkpt")[z].ChildNodes[g].InnerText + "|";
  121.                         }
  122.  
  123.                     }
  124.                 }
  125.                
  126.  
  127.             }
  128.         }
  129.         static void Main(string[] args)
  130.         {
  131.  
  132.             Console.WriteLine("Enter the path to your gpx files:");
  133.             CzytajPliki(Console.ReadLine());
  134.             SprawdzPliki();
  135.             TworzTabele();
  136.  
  137.  
  138.         }
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement