public static int Main(string[] args) { var parsedArgs = new ParsedArgs(args); if (parsedArgs.Ready) { Console.WriteLine(parsedArgs); using (XmlReader fileReader = XmlReader.Create(parsedArgs.InTrackFile)) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.CloseOutput = true; settings.Encoding = UTF8Encoding.UTF8; settings.WriteEndDocumentOnClose = true; settings.NamespaceHandling = NamespaceHandling.OmitDuplicates; using (XmlWriter fileWriter = XmlWriter.Create(parsedArgs.OutTrackFile, settings)) { Statistics stats = new Statistics(); GpxPoint previous = null; stats.Init(); ProcessMethodExtended dealPoint = (XmlReader entry, object extraData) => { GpxPoint current = new GpxPoint(ProcessXml.ReadElement(entry), fileReader.NamespaceURI); if (current.Hdop > parsedArgs.HdopLimit) { Console.WriteLine(current + ", hdop " + current.Hdop); } else { ProcessPoint(current, ref previous, ref stats); } current.Entry.WriteTo(extraData as XmlWriter); }; var segment = new PartsRunner("trkseg", "trkpt", dealPoint); var track = new PartsRunner("trk", "trkseg", segment.Run); fileWriter.WriteStartDocument(); fileReader.MoveToContent(); fileWriter.WriteStartElement("gpx", fileReader.NamespaceURI); // xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"> fileWriter.WriteAttributeString("version", "1.1"); ProcessXml.ProcessEntries(fileReader, "trk", track.Run, fileWriter); fileWriter.WriteEndElement(); fileWriter.Close(); Console.WriteLine(stats); } } } else { Console.WriteLine("Wrong arguments passed to the application."); } return(0); }
public static double CalcVelocity(GpxPoint previous, GpxPoint current, double distance = -1.0) { if (.0 > distance) { distance = CalcDistance(previous, current); } return(distance / (current.Moment - previous.Moment).TotalSeconds); }
public static double CalcDistance(GpxPoint previous, GpxPoint current) { const double R = 6371e3; // Earth radius double rLat1 = previous.Latitude * Math.PI / 180.0, rLat2 = current.Latitude * Math.PI / 180.0, drLon = (current.Longitude - previous.Longitude) * Math.PI / 180.0; double a = Math.Sin((rLat2 - rLat1) / 2.0), b = Math.Sin(drLon / 2.0); double hcls = a * a + Math.Cos(rLat1) * Math.Cos(rLat2) * b * b; return(R * 2 * Math.Atan2(Math.Sqrt(hcls), Math.Sqrt(1 - hcls))); }
private static void ProcessPoint(GpxPoint current, ref GpxPoint previous, ref Statistics stats) { if (null != previous) { current.Previous = previous; stats.Distance += current.Distance; stats.Time += (current.Moment - previous.Moment).TotalSeconds; stats.AvdSpeed += current.Velocity * current.Distance; if (current.Velocity < stats.MinSpeed) { stats.MinSpeed = current.Velocity; } if (current.Velocity > stats.MaxSpeed) { stats.MaxSpeed = current.Velocity; } } previous = current; Console.WriteLine(current + ", distance " + current.Distance + ", velocity " + current.Velocity); }