private void tsmReadGpsData_Click(object sender, EventArgs e) { using (var form = new GpsDataSelector()) { if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { var ps = TrackPointDao.GetTrackPoints(form.CarName, form.StartTime, form.EndTime); this.LoadTrackPoint(ps); } } }
private static void SimulateTrack(long trackId, Action <TrackPoint> action = null) { System.Console.WriteLine("Start to simulateTrack."); var track = TrackDao.GetTrack(trackId); DateTime?endDate = track.EndTime; track.EndTime = null; (new TrackDao()).Update(track); var trackPointDao = new TrackPointDao(); var point = TrackPointDao.GetTrackPoints(track); foreach (var p in point) { p.IsActive = false; trackPointDao.Update(p); } TrackPoint lastp = null; foreach (var p in point) { if (lastp != null && p.GpsTime == lastp.GpsTime) { continue; } p.IsActive = true; trackPointDao.Update(p); if (action != null) { action(p); } System.Console.Write("Press any Key."); System.Console.ReadLine(); //System.Threading.Thread.Sleep(5000); System.Console.WriteLine(string.Format("write trackpoint at {0}", p.GpsTime)); lastp = p; } track.EndTime = endDate; (new TrackDao()).Update(track); System.Console.WriteLine("Finish."); }
private static void SimulateTrack(long trackId, Action <TrackPoint> action4TrackPoint = null, Action <WayPoint> action4WayPoint = null) { System.Console.WriteLine("Start to simulateTrack."); var track = TrackDao.GetTrack(trackId); DateTime?endDate = track.EndTime; track.EndTime = null; (new TrackDao()).Update(track); var trackPointDao = new TrackPointDao(); var wayPointDao = new WayPointDao(); var trackPoints = TrackPointDao.GetTrackPoints(track); foreach (var p in trackPoints) { p.IsActive = false; trackPointDao.Update(p); } var wayPoints = WayPointDao.GetWaypoints(track); foreach (var p in wayPoints) { p.IsActive = false; wayPointDao.Update(p); } int wayPointIdx = 0; TrackPoint lastp = null; foreach (var p in trackPoints) { //if (lastp != null && p.GpsTime == lastp.GpsTime) // continue; p.IsActive = true; trackPointDao.Update(p); if (action4TrackPoint != null) { action4TrackPoint(p); } if (wayPointIdx < wayPoints.Count && p.MessageTime >= wayPoints[wayPointIdx].MessageTime) { wayPoints[wayPointIdx].IsActive = true; wayPointDao.Update(wayPoints[wayPointIdx]); action4WayPoint(wayPoints[wayPointIdx]); wayPointIdx++; } System.Console.Write("Press any Key."); System.Console.ReadLine(); //System.Threading.Thread.Sleep(5000); System.Console.WriteLine(string.Format("write trackpoint at {0}", p.GpsTime)); lastp = p; } track.EndTime = endDate; (new TrackDao()).Update(track); System.Console.WriteLine("Finish."); }
private static void SimulateTrack(long trackId, Action<TrackPoint> action = null) { System.Console.WriteLine("Start to simulateTrack."); var track = TrackDao.GetTrack(trackId); DateTime? endDate = track.EndTime; track.EndTime = null; (new TrackDao()).Update(track); var trackPointDao = new TrackPointDao(); var point = TrackPointDao.GetTrackPoints(track); foreach (var p in point) { p.IsActive = false; trackPointDao.Update(p); } TrackPoint lastp = null; foreach (var p in point) { if (lastp != null && p.GpsTime == lastp.GpsTime) continue; p.IsActive = true; trackPointDao.Update(p); if (action != null) { action(p); } System.Console.Write("Press any Key."); System.Console.ReadLine(); //System.Threading.Thread.Sleep(5000); System.Console.WriteLine(string.Format("write trackpoint at {0}", p.GpsTime)); lastp = p; } track.EndTime = endDate; (new TrackDao()).Update(track); System.Console.WriteLine("Finish."); }
private static void SimulateTrack(long trackId, Action<TrackPoint> action4TrackPoint = null, Action<WayPoint> action4WayPoint = null) { System.Console.WriteLine("Start to simulateTrack."); var track = TrackDao.GetTrack(trackId); DateTime? endDate = track.EndTime; track.EndTime = null; (new TrackDao()).Update(track); var trackPointDao = new TrackPointDao(); var wayPointDao = new WayPointDao(); var trackPoints = TrackPointDao.GetTrackPoints(track); foreach (var p in trackPoints) { p.IsActive = false; trackPointDao.Update(p); } var wayPoints = WayPointDao.GetWaypoints(track); foreach (var p in wayPoints) { p.IsActive = false; wayPointDao.Update(p); } int wayPointIdx = 0; TrackPoint lastp = null; foreach (var p in trackPoints) { //if (lastp != null && p.GpsTime == lastp.GpsTime) // continue; p.IsActive = true; trackPointDao.Update(p); if (action4TrackPoint != null) { action4TrackPoint(p); } if (wayPointIdx < wayPoints.Count && p.MessageTime >= wayPoints[wayPointIdx].MessageTime) { wayPoints[wayPointIdx].IsActive = true; wayPointDao.Update(wayPoints[wayPointIdx]); action4WayPoint(wayPoints[wayPointIdx]); wayPointIdx++; } System.Console.Write("Press any Key."); System.Console.ReadLine(); //System.Threading.Thread.Sleep(5000); System.Console.WriteLine(string.Format("write trackpoint at {0}", p.GpsTime)); lastp = p; } track.EndTime = endDate; (new TrackDao()).Update(track); System.Console.WriteLine("Finish."); }
public TrackForm() : base(ADInfoBll.Instance.GetWindowInfo("SD_Track")) { InitializeComponent(); this.MasterGrid.DataRowTemplate.Cells["VehicleName"].DoubleClick += new EventHandler(TrackForm_VehicleName_DoubleClick); this.MasterGrid.DataRowTemplate.Cells["StartTime"].DoubleClick += new EventHandler(TrackForm_StartTime_DoubleClick); var toolStrip = new ToolStrip(); toolStrip.Items.Add("ToGPX", null, new EventHandler(delegate(object sender, EventArgs e) { if (this.MasterGrid.CurrentRow == null) { return; } Track track = this.MasterGrid.CurrentRow.Tag as Track; if (track == null) { return; } var gpx = GpxConverter.ConvertToGpx(track); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.RestoreDirectory = true; saveFileDialog1.Filter = "GPX 文件(*.gpx)|*.gpx"; //saveFileDialog1.Title = "保存"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(saveFileDialog1.FileName)) { sw.WriteLine(gpx); } } saveFileDialog1.Dispose(); })); toolStrip.Items.Add("ToKML", null, new EventHandler(delegate(object sender, EventArgs e) { if (this.MasterGrid.CurrentRow == null) { return; } Track track = this.MasterGrid.CurrentRow.Tag as Track; if (track == null) { return; } SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.RestoreDirectory = true; saveFileDialog1.Filter = "KML 文件(*.kml)|*.kml"; //saveFileDialog1.Title = "保存"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { Feng.Map.KmlHelper.GenerateTourKml(track, saveFileDialog1.FileName); } saveFileDialog1.Dispose(); })); toolStrip.Items.Add("ToCSV", null, new EventHandler(delegate(object sender, EventArgs e) { if (this.MasterGrid.CurrentRow == null) { return; } Track track = this.MasterGrid.CurrentRow.Tag as Track; if (track == null) { return; } SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.RestoreDirectory = true; saveFileDialog1.Filter = "CSV 文件(*.csv)|*.csv"; //saveFileDialog1.Title = "保存"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(saveFileDialog1.FileName)) { sw.WriteLine("Time, X, Y"); var ps = TrackPointDao.GetTrackPoints(track); foreach (var i in ps) { sw.WriteLine(string.Format("{0}, {2}, {1}", i.GpsTime.ToString("yyyy-MM-ddTHH:mm:ss"), i.Latitude, i.Longitude)); } } } saveFileDialog1.Dispose(); })); base.MergeToolStrip(toolStrip); }
public static void GenerateTourKml(Track track, string kmlFilePath) { //var animationUpdate = new SharpKml.Dom.GX.AnimatedUpdate(); //animationUpdate.Duration = 6.5; //animationUpdate.Update = new Update(); //animationUpdate.Update.AddUpdate(new ChangeCollection //{ // new IconStyle { TargetId = "iconstyle", Scale = 10.0 } //}); var tour = new SharpKml.Dom.GX.Tour(); tour.Name = "Play"; tour.Playlist = new SharpKml.Dom.GX.Playlist(); //tour.Playlist.AddTourPrimitive(animationUpdate); var trackPoint = TrackPointDao.GetTrackPoints(track); if (trackPoint.Count == 0) { return; } for (int i = 0; i < trackPoint.Count; ++i) { var p = trackPoint[i]; if (p.Heading == 0) { continue; } var flyTo = new SharpKml.Dom.GX.FlyTo(); if (i == trackPoint.Count - 1) { flyTo.Duration = 10; } else { var ts = trackPoint[i + 1].GpsTime - p.GpsTime; flyTo.Duration = Math.Max(1, ts.TotalSeconds / 5); } flyTo.View = new Camera { Longitude = p.Longitude, Latitude = p.Latitude, Altitude = p.Altitude, Heading = p.Heading, Tilt = 80, Roll = 0 }; flyTo.Mode = SharpKml.Dom.GX.FlyToMode.Smooth; tour.Playlist.AddTourPrimitive(flyTo); //var wait = new SharpKml.Dom.GX.Wait(); //wait.Duration = 1; //tour.Playlist.AddTourPrimitive(wait); } var document = new Document(); document.Name = "PlayTrack " + track.ID.ToString(); document.Open = true; document.AddStyle( new Style { Id = "style0", Icon = new IconStyle { Id = "iconstyle", Scale = 1.0 } }); document.AddFeature( new Placemark { Id = "Track Start " + track.ID.ToString(), Name = "Start", StyleUrl = new Uri("#style0", UriKind.Relative), Geometry = new Point { Coordinate = new Vector(trackPoint[0].Latitude, trackPoint[0].Longitude, trackPoint[0].Altitude) } }); document.AddFeature(tour); SharpKml.Dom.GX.Track t = new SharpKml.Dom.GX.Track(); t.Id = "Track Track " + track.ID.ToString(); for (int i = 0; i < trackPoint.Count; ++i) { var p = trackPoint[i]; t.AddWhen(p.GpsTime.ToString("yyyy-MM-ddTHH:mm:ssZ")); t.AddCoordinate(new Vector(p.Latitude, p.Longitude, p.Altitude)); } Placemark placemark = new Placemark(); placemark.Name = "All"; placemark.Geometry = t; document.AddFeature(placemark); // Quick way to save the output var kml = new Kml { Feature = document }; AddNamespace(kml, "gx", "http://www.google.com/kml/ext/2.2"); KmlFile.Create(kml, false).Save(kmlFilePath); }
private void LoadTrackData(Track track, bool clearFirst = false) { Feng.Async.AsyncHelper.Start(() => { IList <TrackPoint> trackPoints = TrackPointDao.GetTrackPoints(track); if (trackPoints.Count == 0) { if (track.StartTime.HasValue) { if (!track.EndTime.HasValue) { track.EndTime = DateTime.MaxValue; } trackPoints = TrackPointDao.GetTrackPoints(track.VehicleName, track.StartTime.Value, track.EndTime.Value); } } return(trackPoints); }, (result) => { var trackPoints = result as IList <TrackPoint>; List <PointLatLng> points = new List <GMap.NET.PointLatLng>(); foreach (var p in trackPoints) { points.Add(new PointLatLng(p.Latitude, p.Longitude)); } if (clearFirst) { ClearTrack(); } DarwTrack(points); if (trackPoints.Count > 0) { //DrawCircle(); var p = trackPoints[trackPoints.Count - 1]; var p2 = new PointLatLng(p.Latitude, p.Longitude); var m = new GMap.NET.WindowsForms.Markers.GMapMarkerCircle(p2); m_trackOverlay.Markers.Add(m); m_MainMap.Position = p2; } if (tsm显示路线点地址.Checked) { // Show Start, End for (int i = 0; i < trackPoints.Count; i += trackPoints.Count - 1) { var p = trackPoints[i]; var m = new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleRed(new PointLatLng(p.Latitude, p.Longitude)); m.ToolTipText = (i == 0 ? "Start" : "End") + ", " + p.GpsTime.ToLongTimeString(); m_trackOverlay.Markers.Add(m); } try { DrawTrackPointAddr(trackPoints); } catch (Exception) { } } if (tsm显示路线点.Checked) { IList <WayPoint> wayPoint = WayPointDao.GetWaypoints(track); foreach (var p in wayPoint) { if (!string.IsNullOrEmpty(p.Action)) { var m = new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleRed(new PointLatLng(p.Latitude, p.Longitude)); m.ToolTipText = p.Action + "," + p.GpsTime.ToLongTimeString(); m_trackOverlay.Markers.Add(m); } } } if (!track.EndTime.HasValue) { if (m_timer == null) { m_timer = new System.Timers.Timer(30 * 1000); m_timer.Elapsed += new System.Timers.ElapsedEventHandler(m_timer_Elapsed); } m_timer.AutoReset = true; m_timer.Enabled = true; } if (track.Route != null) { LoadRoute(track.Route.Name); } }); }