public Track(decimal[] pts, string[] labels) { if (pts.Length > 0) { gpxInfo = new gpxType(); gpxInfo.trk = new trkType[1]; gpxInfo.trk[0] = new trkType(); trkType track = gpxInfo.trk[0]; track.name = "generated_route"; track.trkseg = new trksegType[2]; track.trkseg[0] = new trksegType(); trksegType seg = track.trkseg[0]; seg.trkpt = new wptType[pts.Length / 2]; wptType wpt; for (int i = 0; i < seg.trkpt.Length; i++) { seg.trkpt[i] = new wptType(); wpt = seg.trkpt[i]; wpt.name = labels[i]; wpt.lat = pts[i * 2]; wpt.lon = pts[i * 2 + 1]; } } }
private void button1_Click(object sender, EventArgs e) { int numSeg = 0; List<int> segLengths = new List<int>(); List<int> lengths = new List<int>(); System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(gpxType)); System.IO.StreamReader file = new System.IO.StreamReader(@Pathin.Text); gpxType overview = new gpxType(); gpxType gpxout = new gpxType(); overview = (gpxType)reader.Deserialize(file); file.Close(); numSeg = overview.trk[0].trkseg.Length; Console.WriteLine("Found " + numSeg + " jump(s) at position(s)"); for (int i = 0; i < numSeg; i++) { segLengths.Add(overview.trk[0].trkseg[i].trkpt.Length); Console.WriteLine(i + " " + segLengths[i]); } if (gpxout.trk == null) gpxout.trk = new trkType[numSeg]; for (int i = 0; i < numSeg; i++) { if (gpxout.trk[i] == null) gpxout.trk[i] = new trkType(); if (gpxout.trk[i].trkseg == null) gpxout.trk[i].trkseg = new trksegType[1]; if (gpxout.trk[i].trkseg[0] == null) gpxout.trk[i].trkseg[0] = new trksegType(); if (gpxout.trk[i].trkseg[0].trkpt == null) gpxout.trk[i].trkseg[0].trkpt = new wptType[segLengths[i]]; Console.WriteLine(gpxout.trk[i].trkseg[0].trkpt.Length); for (int j = 0; j < segLengths[i]; j++) { if (gpxout.trk[i].trkseg[0].trkpt[j] == null) gpxout.trk[i].trkseg[0].trkpt[j] = new wptType(); //Console.WriteLine(i+" "+j); gpxout.trk[i].trkseg[0].trkpt[j] = overview.trk[0].trkseg[i].trkpt[j]; } } System.IO.TextWriter writer = new System.IO.StreamWriter(@Pathout.Text); reader.Serialize(writer, gpxout); writer.Close(); }
void ReadData() { //---------------------------------------------------------------------- gpxType gpxtype = new gpxType(); int tracklenght = 0; using (FileStream fs = new FileStream("1.gpx", FileMode.Open, FileAccess.Read, FileShare.Read)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(gpxType)); try { gpxtype = (gpxType)xmlSerializer.Deserialize(fs); } catch (Exception ex) { } finally { } } if (gpxtype != null && gpxtype.trk != null && gpxtype.trk[0].trkseg != null && gpxtype.trk[0].trkseg[0].trkpt != null && gpxtype.trk[0].trkseg[0].trkpt[0].time != null) { //если я хочу отобразить сегмент трека, мне нужен набор точек одного сегмента //склеим сегменты в один лист ptList = new List<wptType>(); for (int u = 0; u < gpxtype.trk.Length; u++) { for (int t = 0; t < gpxtype.trk[u].trkseg.Length; t++) { for (int y = 0; y < gpxtype.trk[u].trkseg[t].trkpt.Length; y++) { ptList.Add(gpxtype.trk[u].trkseg[t].trkpt[y]); } } } } }
public void LoadTrack(string fileName) { // Clean up UI totalDist = 0; totalAvgSpeed = 0; totalTime = TimeSpan.Zero; // lbTracks.Items.Clear(); // lbPoints.Items.Clear(); // Load file XmlSerializer ser = new XmlSerializer(typeof(gpxType)); using (FileStream str = new FileStream(fileName, FileMode.Open)) { // this.Text = "GPS Track Viewer - " + Path.GetFileName(fileName); gpxInfo = (gpxType)ser.Deserialize(str); int nTracks = 0; if (gpxInfo.trk != null) { // populate tracks listbox nTracks = gpxInfo.trk.Length; foreach (trkType track in gpxInfo.trk) { // lbTracks.Items.Add(track.name); } } if (nTracks > 0) { // Select the first track // This raises the SelectedIndexChanged event. // lbTracks.SelectedIndex = 0; } // lblTracks.Text = string.Format("{0} Tracks", nTracks); } }
public void LoadTrack(string fileName) { // Clean up UI totalDist = 0; totalAvgSpeed = 0; totalTime = TimeSpan.Zero; // Load file XmlSerializer ser = new XmlSerializer(typeof(gpxType)); using (FileStream str = new FileStream(fileName, FileMode.Open)) { this.Text = Path.GetFileName(fileName); gpxInfo = (gpxType)ser.Deserialize(str); } }