Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Xml;
- namespace gpxtotxt
- {
- class Program
- {
- static List<XmlDocument> docList = new List<XmlDocument>();
- static XmlDocument doc = new XmlDocument();
- static int colsWPT = 0;
- static int rowsWPT = 1;
- static int colsTRK = 0;
- static int rowsTRK = 1;
- static void CzytajPliki(String path)
- {
- try
- {
- Console.WriteLine("Loading files:");
- for (int i = 0; i < Directory.GetFiles(path, "*.gpx").Length; i++)
- {
- doc.Load(Directory.GetFiles(path)[i]);
- docList.Add(doc);
- Console.WriteLine(Directory.GetFiles(path, "*.gpx")[i]);
- Thread.Sleep(500);
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("{0} Caught exception.", e);
- Thread.Sleep(10000);
- }
- }
- static void SprawdzPliki()
- {
- for (int j = 0; j < docList.Count; j++)
- {
- if(docList[j].GetElementsByTagName("wpt").Count >0)
- {
- rowsWPT += docList[j].GetElementsByTagName("wpt").Count;
- colsWPT = docList[j].GetElementsByTagName("wpt")[0].ChildNodes.Count+3; //+5 => lat and lon
- }
- if(docList[j].GetElementsByTagName("trkpt").Count > 0)
- {
- rowsTRK += docList[j].GetElementsByTagName("trkpt").Count;
- colsTRK = docList[j].GetElementsByTagName("trkpt")[0].ChildNodes.Count + 3; //+2 => lat and lon + name which is elsewhere
- }
- }
- }
- static void TworzTabele()
- {
- String[][] arrayWPT = new String[rowsWPT][];
- String[][] arrayTRK = new String[rowsTRK][];
- for (int i = 0; i < arrayWPT.Length; i++)
- {
- arrayWPT[i] = new string[colsWPT];
- }
- for (int i = 0; i < arrayTRK.Length; i++)
- {
- arrayTRK[i] = new string[colsTRK];
- }
- for (int j = 0; j < docList.Count; j++)
- {
- if (docList[j].GetElementsByTagName("wpt").Count > 0)
- {
- for (int h = 0; h < docList[j].GetElementsByTagName("wpt")[0].ChildNodes.Count; h++) // wypisz nazwy
- {
- //if(x[z].childNodes[i].nodeName == "desc")
- // {
- // txt += strip(x[z].childNodes[i].childNodes[0].nodeValue) + "<br>";
- //}
- //else
- //{
- //txtNames.Add(docList[j].GetElementsByTagName("wpt")[0].ChildNodes[h].Name + "|");
- arrayWPT[0][h] = docList[j].GetElementsByTagName("wpt")[0].ChildNodes[h].Name + "|";
- // Console.WriteLine(txtItem[0]);
- // Thread.Sleep(20000);
- }
- for (int z = 1; z <= docList[j].GetElementsByTagName("wpt").Count; z++)
- {
- for (int g = 0; g < docList[j].GetElementsByTagName("wpt")[z-1].ChildNodes.Count; g++)
- {
- arrayWPT[z][g] = docList[j].GetElementsByTagName("wpt")[z-1].ChildNodes[g].InnerText + "|";
- }
- }
- }
- if (docList[j].GetElementsByTagName("trkpt").Count > 0)
- {
- for (int h = 0; h < docList[j].GetElementsByTagName("trkpt")[0].ChildNodes.Count; h++) // wypisz nazwy
- {
- //if(x[z].childNodes[i].nodeName == "desc")
- // {
- // txt += strip(x[z].childNodes[i].childNodes[0].nodeValue) + "<br>";
- //}
- //else
- //{
- //txtNames.Add(docList[j].GetElementsByTagName("wpt")[0].ChildNodes[h].Name + "|");
- arrayTRK[0][h] = docList[j].GetElementsByTagName("trkpt")[0].ChildNodes[h].Name + "|";
- // Console.WriteLine(txtItem[0]);
- // Thread.Sleep(20000);
- }
- for (int z = 1; z < docList[j].GetElementsByTagName("trkpt").Count + 1; z++)
- {
- for (int g = 0; g < docList[j].GetElementsByTagName("trkpt")[z].ChildNodes.Count; g++)
- {
- arrayTRK[z][g] = docList[j].GetElementsByTagName("trkpt")[z].ChildNodes[g].InnerText + "|";
- }
- }
- }
- }
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Enter the path to your gpx files:");
- CzytajPliki(Console.ReadLine());
- SprawdzPliki();
- TworzTabele();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement