private bool TracksExportToKML(string fileName) { KMLData data = new KMLData(fileName, string.Format("Generated by {0}", Application.ProductName)); List <KMLLocation> kmlTrack; foreach (var item in tracks) { kmlTrack = new List <KMLLocation>(); foreach (var point in item.Value) { kmlTrack.Add(new KMLLocation(point.Longitude, point.Latitude, -point.Depth)); } data.Add(new KMLPlacemark(string.Format("{0} track", item.Key), "", kmlTrack.ToArray())); } bool isOk = false; try { TinyKML.Write(data, fileName); isOk = true; } catch (Exception ex) { ProcessException(ex, true); } return(isOk); }
private void SaveTracks(string fileName) { #region Save to KML KMLData data = new KMLData(fileName, "Generated by RedGTR_VLBL application"); var gnssKmlTrack = new List <KMLLocation>(); foreach (var trackItem in bLocation) { gnssKmlTrack.Add(new KMLLocation(trackItem.Longitude, trackItem.Latitude, bDepth.Value)); } data.Add(new KMLPlacemark("BOAT GNSS", "Boat GNSS track", gnssKmlTrack.ToArray())); var msmsKmlTrack = new List <KMLLocation>(); var msms = measurements.ToArray(); foreach (var trackItem in msms) { msmsKmlTrack.Add(new KMLLocation(trackItem.Longitude, trackItem.Latitude, bDepth.Value)); } data.Add(new KMLPlacemark("MEASUREMENT POINTS", "Measurements points", msmsKmlTrack.ToArray())); var targetKmlTrack = new List <KMLLocation>(); foreach (var trackItem in tLocation) { targetKmlTrack.Add(new KMLLocation(trackItem.Longitude, trackItem.Latitude, tDepth.Value)); } data.Add(new KMLPlacemark("TARGET", "Target track", targetKmlTrack.ToArray())); data.Add(new KMLPlacemark("BEST", "Location with minimal radial error", true, true, new KMLLocation(tBestLocation.Longitude, tBestLocation.Latitude, tDepth.Value))); try { TinyKML.Write(data, fileName); } catch (Exception ex) { ProcessException(ex, true); } #endregion }
private void SaveTrackXML(string fileName) { bool isSaved = false; KMLData data = new KMLData(fileName, "Generated by RedNavHost, www.unavlab.com"); for (int i = 0; i < waypoints.Count; i++) { if (waypoints[i].PType == 0) { data.Add(new KMLPlacemark(LocRM.GetString("mfText_BuoyStr"), "", false, false, new KMLLocation(waypoints[i].Longitude, waypoints[i].Latitude, 0))); } else if (waypoints[i].PType == 1) { data.Add(new KMLPlacemark(string.Format("{0} {1}", LocRM.GetString("mfText_WaypointStr"), i), "", false, false, new KMLLocation(waypoints[i].Longitude, waypoints[i].Latitude, 0))); } else if (waypoints[i].PType == 2) { data.Add(new KMLPlacemark(string.Format("{0} {1}", LocRM.GetString("mfText_SavedPoint"), i), "", false, false, new KMLLocation(waypoints[i].Longitude, waypoints[i].Latitude, 0))); } } List <KMLLocation> tPOwn = new List <KMLLocation>(); for (int i = 0; i < track.Count; i++) { tPOwn.Add(new KMLLocation(track[i].Longitude, track[i].Latitude, -track[i].Depth)); } if (track.Count > 0) { data.Add(new KMLPlacemark(LocRM.GetString("mfText_OwnTrackStr"), string.Format("RedWave RedNav {0}", LocRM.GetString("mfText_TrackStr")), tPOwn.ToArray())); } try { TinyKML.Write(data, fileName); track = null; isSaved = true; } catch (Exception ex) { MessageBox.Show(string.Format("{0} {1}: {2}", LocRM.GetString("mfText_ErrorSavingDataStr"), fileName, ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (isSaved) { if (MessageBox.Show(LocRM.GetString("mfText_RemoveTrackFromDeviceStr"), LocRM.GetString("mfText_QuestionStr"), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { port.Send(port.QueryTrackClear()); this.UseWaitCursor = true; Thread.Sleep(5000); this.UseWaitCursor = false; InvokeSetText(trackCountLbl, LocRM.GetString("mfText_DeviceTrackIsEmptyStr")); InvokeSetEnabledState(downloadTrackBtn, false); } } }
private void saveTrackToolStripMenuItem_Click(object sender, EventArgs e) { using (SaveFileDialog sDialog = new SaveFileDialog()) { sDialog.Title = "Choose filename to save data..."; sDialog.FileName = GetTimeFileName(DateTime.Now); sDialog.Filter = "KML (*.kml)|*.kml"; if (sDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //if (sDialog.FilterIndex == 1) //{ #region Save to KML KMLData data = new KMLData(sDialog.FileName, "Generated by RedNODE Host application"); List <KMLLocation> tPOwn = new List <KMLLocation>(); List <KMLLocation> tBuoy0 = new List <KMLLocation>(); List <KMLLocation> tBuoy1 = new List <KMLLocation>(); List <KMLLocation> tBuoy2 = new List <KMLLocation>(); List <KMLLocation> tBuoy3 = new List <KMLLocation>(); List <KMLLocation> gnss = new List <KMLLocation>(); for (int i = 0; i < track.Count; i++) { tPOwn.Add(new KMLLocation(track[i].Location.Lon, track[i].Location.Lat, track[i].Location.Depth)); tBuoy0.Add(new KMLLocation(track[i].Buoy0Location.Lon, track[i].Buoy0Location.Lat, 0)); tBuoy1.Add(new KMLLocation(track[i].Buoy1Location.Lon, track[i].Buoy1Location.Lat, 0)); tBuoy2.Add(new KMLLocation(track[i].Buoy2Location.Lon, track[i].Buoy2Location.Lat, 0)); tBuoy3.Add(new KMLLocation(track[i].Buoy3Location.Lon, track[i].Buoy3Location.Lat, 0)); } for (int i = 0; i < gnssTrack.Count; i++) { gnss.Add(new KMLLocation(gnssTrack[i].Lon, gnssTrack[i].Lat, 0)); } for (int i = 0; i < markedPoints.Count; i++) { data.Add(new KMLPlacemark(string.Format("Marked point", i), "", false, false, new KMLLocation(markedPoints[i].Lon, markedPoints[i].Lat, 0))); } data.Add(new KMLPlacemark("Own", "RedWave RedNODE device track", tPOwn.ToArray())); data.Add(new KMLPlacemark("RedBASE #1", "Buoy #1 track", tBuoy0.ToArray())); data.Add(new KMLPlacemark("RedBASE #2", "Buoy #2 track", tBuoy1.ToArray())); data.Add(new KMLPlacemark("RedBASE #3", "Buoy #3 track", tBuoy2.ToArray())); data.Add(new KMLPlacemark("RedBASE #4", "Buoy #4 track", tBuoy3.ToArray())); if (gnss.Count > 0) { data.Add(new KMLPlacemark("GNSS", "GNSS track", gnss.ToArray())); } try { TinyKML.Write(data, sDialog.FileName); } catch (Exception ex) { MessageBox.Show(string.Format("Unable to save track to {0}: {1}", sDialog.FileName, ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); logger.Write(ex); } #endregion /*} * else if (sDialog.FilterIndex == 2) * { #region Save to CSV * * try * { * // * } * catch (Exception ex) * { * MessageBox.Show(string.Format("Unable to save track to {0}: {1}", sDialog.FileName, ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); * } * #endregion * } * else if (sDialog.FilterIndex == 3) * { #region Save to GPX * #endregion * } */ } } }