Esempio n. 1
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            metadata m = new metadata(txtName.Text, txtDesc.Text, txtAuthor.Text, txtKeywords.Text, txtURL.Text, txtEmail.Text, txtAuthorURL.Text);

            char[] colon = { ':' };
            if (listTracks.SelectedIndex < 0)
            {
                return;
            }
            int t = Convert.ToInt32(listTracks.SelectedItem.ToString().Split(colon)[0]);

            Export(t, m);
        }
Esempio n. 2
0
        private void Export(int cNumber, metadata Details)
        {
            int year, month, day;

            //int hour, minute, second;
            string[] localstart = listTracks.SelectedItem.ToString().Split(' ');
            string[] localdate  = localstart[1].Split('-');
            //string[] localtime = localstart[2].Split(':');

            year  = Convert.ToInt32(localdate[0]);
            month = Convert.ToInt32(localdate[1]);
            day   = Convert.ToInt32(localdate[2]);
            //hour = Convert.ToInt32(localtime[0]);
            //minute = Convert.ToInt32(localtime[1]);
            //second = Convert.ToInt32(localtime[2]);

            //DateTime d = new DateTime(year, month, day, hour, minute, second);
            DateTime d    = new DateTime(year, month, day);
            DateTime UTCd = d.AddHours(Convert.ToDouble(numericUpDown1.Value));

            //select file to save to
            DialogResult result = saveFileDialog1.ShowDialog();
            //if result == ok etc

            //open connection to db
            string strAccessConn   = @"Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + openFileDialog1.FileName + "; Jet OLEDB:Database Password=danger";
            string strAccessSelect = "SELECT LongitudeN,LatitudeN,TrackTime,LonSign,LatSign FROM TrackPoint WHERE Cnumber = " + cNumber + " ORDER BY SerNo";

            // Create the dataset and add the Categories table to it:
            DataSet         myDataSet    = new DataSet();
            OleDbConnection myAccessConn = null;

            try
            {
                myAccessConn = new OleDbConnection(strAccessConn);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
                return;
            }

            try
            {
                OleDbCommand     myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn);
                OleDbDataAdapter myDataAdapter   = new OleDbDataAdapter(myAccessCommand);

                myAccessConn.Open();
                myDataAdapter.Fill(myDataSet, "TrackPoint");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Failed to retrieve the required data from the DataBase.\n{0}", ex.Message);
                return;
            }
            finally
            {
                myAccessConn.Close();
            }

            XmlWriterSettings xs = new XmlWriterSettings();

            //xs.CheckCharacters = false;
            xs.Indent = true;

            XmlWriter writer = XmlWriter.Create(saveFileDialog1.FileName, xs);


            writer.WriteStartDocument();

            writer.WriteStartElement("gpx", @"http://www.topografix.com/GPX/1/0");
            //writer.WriteAttributeString("xmlns", @"http://www.topografix.com/GPX/1/0");
            writer.WriteAttributeString("creator", "Laser GPS Converter");
            writer.WriteAttributeString("version", "1.0");
            writer.WriteAttributeString("xsi", "xlmns", @"http://www.w3.org/2001/XMLSchema-instance");
            writer.WriteAttributeString("schemaLocation", "xsi", @"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd");

            //assume no metadata for now - skip

            writer.WriteStartElement("trk");

            writer.WriteStartElement("trkseg");


            DataRowCollection dra = myDataSet.Tables["TrackPoint"].Rows;

            foreach (DataRow dr in dra)
            {
                writer.WriteStartElement("trkpt");
                if (dr[4].ToString().Trim().Equals("N"))
                {
                    writer.WriteAttributeString("lat", dr[1].ToString());
                }
                else
                {
                    writer.WriteAttributeString("lat", "-" + dr[1].ToString());
                }

                if (dr[3].ToString().Trim().Equals("E"))
                {
                    writer.WriteAttributeString("lon", dr[0].ToString());
                }
                else
                {
                    writer.WriteAttributeString("lon", "-" + dr[0].ToString());
                }

                writer.WriteStartElement("time");

                //dr[2] = 14:48:25, etc
                string[] localtime = dr[2].ToString().Trim().Split(':');
                DateTime localT    = UTCd.AddHours(Convert.ToInt32(localtime[0]));
                localT = localT.AddMinutes(Convert.ToInt32(localtime[1]));
                localT = localT.AddSeconds(Convert.ToInt32(localtime[2]));

                writer.WriteString(String.Join("-", localT.Year, localT.Month, localT.Day) + "T" + String.Join(":", localT.Hour, localT.Minute, localT.Second) + "Z");
                writer.WriteEndElement();

                writer.WriteEndElement();
            }

            writer.WriteEndDocument();
            writer.Close();

            //update tracktime to add date from listTracks
            //retrieve timezone setting, convert from number to timezone, update tracktime
            //create gpx file, start xml
            //write metadata to gpx file if necessary
            //retrieve matching datapoints
            //write each to gpx file
            //finish xml
            //close file
        }