コード例 #1
0
ファイル: MainForm.cs プロジェクト: ucnl/WAYU
        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);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: ucnl/RedGTR_VLBL
        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
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: ucnl/UGPSHub
        private void utilsTrackFilteringBtn_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog oDialog = new OpenFileDialog())
            {
                oDialog.Title      = "Select a KML file to filter...";
                oDialog.DefaultExt = "kml";
                oDialog.Filter     = "KML files (*.kml)|*.kml";

                if (oDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    bool    isLoaded = false;
                    KMLData kmlData  = null;
                    try
                    {
                        kmlData  = TinyKML.Read(oDialog.FileName);
                        isLoaded = true;
                    }
                    catch (Exception ex)
                    {
                        ProcessException(ex, true);
                    }

                    if (isLoaded)
                    {
                        TrackFilter trkFilter = new TrackFilter(8);
                        for (int i = 0; i < kmlData.Count; i++)
                        {
                            if (kmlData[i].PlacemarkItem.Count > 1)
                            {
                                trkFilter.Reset();
                                for (int j = 0; j < kmlData[i].PlacemarkItem.Count; j++)
                                {
                                    var fresult = trkFilter.Filter(kmlData[i].PlacemarkItem[j].Latitude, kmlData[i].PlacemarkItem[j].Longitude);
                                    kmlData[i].PlacemarkItem[j].Latitude  = fresult.Latitude;
                                    kmlData[i].PlacemarkItem[j].Longitude = fresult.Longitude;
                                }
                            }
                        }

                        using (SaveFileDialog sDialog = new SaveFileDialog())
                        {
                            sDialog.Title      = "Select filename to save filtered track...";
                            sDialog.DefaultExt = "kml";
                            sDialog.Filter     = "KML files (*.kml)|*.kml";

                            var fName = string.Format("FLT_{0}", Path.GetFileName(oDialog.FileName));
                            var fPath = Path.GetDirectoryName(oDialog.FileName);

                            sDialog.FileName = Path.Combine(fPath, fName);

                            if (sDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                bool isSaved = false;
                                try
                                {
                                    TinyKML.Write(kmlData, sDialog.FileName);
                                    isSaved = true;
                                }
                                catch (Exception ex)
                                {
                                    ProcessException(ex, true);
                                }

                                if (isSaved)
                                {
                                    MessageBox.Show("Tracks successfully saved.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: ucnl/RedNavHost
        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);
                }
            }
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: ucnl/RedNodeHost
        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
                     * }
                     */
                }
            }
        }