protected void DoTrackCleanUp() { int nTime = 0, nDupe = 0, nSpike = 0; var validPoints = new List <AXPoint>(); var minValidTime = Date + new TimeSpan(4, 0, 0); //04:00(am) or 16:00(pm) local var maxValidTime = Date + new TimeSpan(12, 0, 0); //12:00(am) or 24:00(pm) local AXPoint point_m1 = null; AXPoint point_m2 = null; foreach (var point in OriginalTrack) { // remove points before/after valid times if (point.Time < minValidTime || point.Time > maxValidTime) { nTime++; continue; } // remove dupe if (point_m1 != null && Physics.TimeDiff(point, point_m1).TotalSeconds == 0) { nDupe++; continue; } // remove spike //TODO: consider removing spikes by change in direction if (point_m2 != null && Physics.Acceleration3D(point, point_m1, point_m2) > Settings.MaxAcceleration) { nSpike++; continue; } validPoints.Add(point); point_m2 = point_m1; point_m1 = point; } Notes.Add(string.Format("Original track has {0} points", OriginalTrack.Length)); if (nTime > 0) { Notes.Add(string.Format("{0} out-of-time points removed", nTime)); } if (nDupe > 0) { Notes.Add(string.Format("{0} duplicated points removed", nDupe)); } if (nSpike > 0) { Notes.Add(string.Format("{0} spike points removed", nSpike)); } cleanTrack = validPoints.ToArray(); if (cleanTrack.Length == 0) { Notes.Add("Empty track file! Check the flight date and time and UTM zone."); } else if (Settings.InterpolationInterval > 0) { var nBefore = cleanTrack.Length; //cleanTrack = Interpolation.Linear(cleanTrack, Settings.InterpolationInterval, Settings.InterpolationMaxGap).ToArray(); cleanTrack = Interpolation.Spline(cleanTrack, Settings.InterpolationInterval, Settings.InterpolationMaxGap).ToArray(); Notes.Add(string.Format("{0} points added by interpolation", cleanTrack.Length - nBefore)); } }