/// <summary>
        /// When passed a file, open it and parse all routes and route segments from it.
        /// </summary>
        /// <param name="gpxDoc">Fully qualified file name (local)</param>
        /// <returns>
        /// A List of PositionData
        /// </returns>
        public static IEnumerable <PositionData> LoadPositionData(XDocument gpxDoc)
        {
            XNamespace gpx = XNamespace.Get("http://www.topografix.com/GPX/1/1");
            XNamespace ins = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance/ins");

            return(from routepoint in gpxDoc.Descendants(gpx + "rtept")
                   let extensions = routepoint.Element(gpx + "extensions")
                                    let inertial = extensions != null?extensions.Element(ins + "inertial") : null
                                                       select new PositionData
            {
                Latitude = XmlConvert.ToDouble(routepoint.Attribute("lat").Value),
                Longitude = XmlConvert.ToDouble(routepoint.Attribute("lon").Value),
                Utc = routepoint.Element(gpx + "time") != null
                                                        ? XmlConvert.ToDateTime(routepoint.Element(gpx + "time").Value, XmlDateTimeSerializationMode.Utc)
                                                        : DateTime.MinValue,
                Altitude = routepoint.Element(gpx + "geoidheight") != null
                                                        ? XmlConvert.ToDouble(routepoint.Element (gpx + "geoidheight").Value)
                                                        : routepoint.Element(gpx + "ele") != null
                                                                ? XmlConvert.ToDouble(routepoint.Element (gpx + "ele").Value)
                                                                : 0d,
                Quality = routepoint.Element(gpx + "fix") != null
                                                        ? GpxConvert.ToFixType(routepoint.Element (gpx + "fix").Value)
                                                        : FixType.None,
                NbSatellites = routepoint.Element(gpx + "sat") != null
                                                        ? XmlConvert.ToInt32(routepoint.Element (gpx + "sat").Value)
                                                        : 0,
                InsData = inertial != null
                                                        ? new InsData
                {
                    AccelerationX = XmlConvert.ToDouble(inertial.Element(gpx + "accx").Value),
                    AccelerationY = XmlConvert.ToDouble(inertial.Element(gpx + "accy").Value),
                    AccelerationZ = XmlConvert.ToDouble(inertial.Element(gpx + "accz").Value),
                    AngularRateX = XmlConvert.ToDouble(inertial.Element(gpx + "angrtx").Value),
                    AngularRateY = XmlConvert.ToDouble(inertial.Element(gpx + "angrty").Value),
                    AngularRateZ = XmlConvert.ToDouble(inertial.Element(gpx + "angrtz").Value),
                    DownVelocity = XmlConvert.ToDouble(inertial.Element(gpx + "dvelo").Value),
                    EastVelocity = XmlConvert.ToDouble(inertial.Element(gpx + "evelo").Value),
                    NorthVelocity = XmlConvert.ToDouble(inertial.Element(gpx + "nvelo").Value),
                    Heading = XmlConvert.ToDouble(inertial.Element(gpx + "heading").Value),
                    Pitch = XmlConvert.ToDouble(inertial.Element(gpx + "pitch").Value),
                    Roll = XmlConvert.ToDouble(inertial.Element(gpx + "roll").Value),
                }

                                                        : null
            });
        }
        /// <summary>
        /// When passed a file, open it and parse all routes and route segments from it.
        /// </summary>
        /// <param name="filePath">Fully qualified file name (local)</param>
        /// <returns>
        /// A List of PositionData
        /// </returns>
        public static IEnumerable <GpxData> LoadGpxData(string filePath, bool useCorrectedValue)
        {
            XDocument  gpxDoc  = XDocument.Load(filePath);
            XNamespace gpx     = XNamespace.Get("http://www.topografix.com/GPX/1/1");
            XNamespace ins     = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance/ins");
            string     version = gpxDoc.Root.FirstAttribute.Value;

            if (version == "1.1")
            {
                useCorrectedValue = false;
            }

            return(from routepoint in gpxDoc.Descendants(gpx + "rtept")
                   let extensions = routepoint.Element(gpx + "extensions")
                                    let correctedPositionValue = extensions.Element(gpx + "CorrectedPositionValue")
                                                                 let inertial = extensions != null?extensions.Element(ins + "inertial") : null
                                                                                    select new GpxData
            {
                PositionData = new PositionData {
                    Latitude = useCorrectedValue
                                                           ? XmlConvert.ToDouble(correctedPositionValue.Element(gpx + "lat").Value)
                                                           : XmlConvert.ToDouble(routepoint.Attribute("lat").Value),
                    Longitude = useCorrectedValue
                                                                   ? XmlConvert.ToDouble(correctedPositionValue.Element(gpx + "lon").Value)
                                                                   : XmlConvert.ToDouble(routepoint.Attribute("lon").Value),
                    Utc = routepoint.Element(gpx + "time") != null
                                                           ? XmlConvert.ToDateTime(routepoint.Element(gpx + "time").Value, XmlDateTimeSerializationMode.Utc)
                                                           : DateTime.MinValue,
                    Altitude = routepoint.Element(gpx + "ele") != null
                                                           ? XmlConvert.ToDouble(routepoint.Element (gpx + "ele").Value)
                                                           : 0d,
                    GeoIdHeight = routepoint.Element(gpx + "geoidheight") != null
                                                           ? XmlConvert.ToDouble(routepoint.Element (gpx + "geoidheight").Value)
                                                           : 0d,
                    Quality = routepoint.Element(gpx + "fix") != null
                                                           ? GpxConvert.ToFixType(routepoint.Element (gpx + "fix").Value)
                                                           : FixType.None,
                    NbSatellites = routepoint.Element(gpx + "sat") != null
                                                           ? XmlConvert.ToInt32(routepoint.Element (gpx + "sat").Value)
                                                           : 0,
                    InsData = inertial != null
                                                           ? new InsData
                    {
                        AccelerationX = XmlConvert.ToDouble(inertial.Element(gpx + "accx").Value),
                        AccelerationY = XmlConvert.ToDouble(inertial.Element(gpx + "accy").Value),
                        AccelerationZ = XmlConvert.ToDouble(inertial.Element(gpx + "accz").Value),
                        AngularRateX = XmlConvert.ToDouble(inertial.Element(gpx + "angrtx").Value),
                        AngularRateY = XmlConvert.ToDouble(inertial.Element(gpx + "angrty").Value),
                        AngularRateZ = XmlConvert.ToDouble(inertial.Element(gpx + "angrtz").Value),
                        DownVelocity = XmlConvert.ToDouble(inertial.Element(gpx + "dvelo").Value),
                        EastVelocity = XmlConvert.ToDouble(inertial.Element(gpx + "evelo").Value),
                        NorthVelocity = XmlConvert.ToDouble(inertial.Element(gpx + "nvelo").Value),
                        Heading = XmlConvert.ToDouble(inertial.Element(gpx + "heading").Value),
                        Pitch = XmlConvert.ToDouble(inertial.Element(gpx + "pitch").Value),
                        Roll = XmlConvert.ToDouble(inertial.Element(gpx + "roll").Value),
                    }

                                                           : null
                },
                VelocityData = new VelocityData {
                    SpeedMs = extensions.Element(gpx + "speedKmh") != null
                                                           ? XmlConvert.ToDouble(extensions.Element(gpx + "speedKmh").Value) / 3.6
                                                           : 0,
                },
                PrecisionData = new PrecisionData {
                    Hdop = routepoint.Element(gpx + "hdop") != null
                                                           ? XmlConvert.ToDouble(routepoint.Element(gpx + "hdop").Value)
                                                           : 0d,
                    Vdop = routepoint.Element(gpx + "vdop") != null
                                                           ? XmlConvert.ToDouble(routepoint.Element(gpx + "vdop").Value)
                                                           : 0d,
                    Pdop = routepoint.Element(gpx + "pdop") != null
                                                           ? XmlConvert.ToDouble(routepoint.Element(gpx + "pdop").Value)
                                                           : 0d,
                },
                ExtensionData = new ExtensionData {
                    Speed = extensions.Element(gpx + "speedKmh") != null
                                                           ? XmlConvert.ToDouble(extensions.Element(gpx + "speedKmh").Value) / 3.6
                                                           : 0,
                    CorrectedLatitude = extensions.Element(gpx + "lat") != null?XmlConvert.ToDouble(correctedPositionValue.Element(gpx + "lat").Value) : 0,
                                            CorrectedLongitude = extensions.Element(gpx + "lon") != null?XmlConvert.ToDouble(correctedPositionValue.Element(gpx + "lon").Value) : 0,
                                                                     GpsStatus = extensions.Element(gpx + "gpsStatus") != null
                                                           ? extensions.Element(gpx + "gpsStatus").Value
                                                           : "",
                                                                     ComputerDateTime = extensions.Element(gpx + "computerDateTime") != null
                                                           ? XmlConvert.ToDateTime(extensions.Element(gpx + "computerDateTime").Value, XmlDateTimeSerializationMode.Utc)
                                                           : DateTime.MinValue,
                                                                     Progress = extensions.Element(gpx + "progress") != null
                                                           ? XmlConvert.ToDouble(extensions.Element(gpx + "progress").Value)
                                                           : 0,
                }
            });
        }
Exemplo n.º 3
0
        public void Trace(GeoData raw, GeoData corrected, GpsStatus gpsStatus, DateTime computerDateTime, RoutepointExtension rteptExtension)
        {
            if (raw == null)
            {
                Log.Warn().Message("raw est null").Write(); return;
            }
            if (corrected == null)
            {
                Log.Warn().Message("corrected est null").Write(); return;
            }

            if (raw.PositionData == null)
            {
                Log.Warn().Message("raw.PositionData est null").Write(); return;
            }
            if (raw.VelocityData == null)
            {
                Log.Warn().Message("raw.VelocityData est null").Write(); return;
            }

            if (corrected.PositionData == null)
            {
                Log.Warn().Message("corrected.PositionData est null").Write(); return;
            }
            if (corrected.VelocityData == null)
            {
                Log.Warn().Message("corrected.VelocityData est null").Write(); return;
            }

            if (_output != null && (_output.WriteState == WriteState.Closed || _output.WriteState == WriteState.Error))
            {
                Log.Warn().Message("Le fichier de trace est fermé ou en erreur.").Write(); return;
            }

            _output.WriteStartElement("rtept");
            {
                _output.WriteAttributeString("lat", Convert.ToString(raw.PositionData.Latitude, CultureInfo.InvariantCulture));
                _output.WriteAttributeString("lon", Convert.ToString(raw.PositionData.Longitude, CultureInfo.InvariantCulture));

                _output.WriteElementString("time", raw.PositionData.Utc.ToString("yyyy-MM-ddTHH:mm:ss.ffK"));
                _output.WriteElementString("ele", Convert.ToString(raw.PositionData.Altitude, CultureInfo.InvariantCulture));
                _output.WriteElementString("geoidheight", Convert.ToString(raw.PositionData.GeoIdHeight, CultureInfo.InvariantCulture));
                _output.WriteElementString("fix", GpxConvert.FromFixType(raw.PositionData.Quality));
                _output.WriteElementString("sat", Convert.ToString(raw.PositionData.NbSatellites, CultureInfo.InvariantCulture));

                if (raw.PrecisionData != null)
                {
                    if (raw.PrecisionData.Hdop != null)
                    {
                        _output.WriteElementString("hdop", Convert.ToString(raw.PrecisionData.Hdop, CultureInfo.InvariantCulture));
                    }

                    if (raw.PrecisionData.Vdop != null)
                    {
                        _output.WriteElementString("vdop", Convert.ToString(raw.PrecisionData.Vdop, CultureInfo.InvariantCulture));
                    }

                    if (raw.PrecisionData.Pdop != null)
                    {
                        _output.WriteElementString("pdop", Convert.ToString(raw.PrecisionData.Pdop, CultureInfo.InvariantCulture));
                    }
                }

                _output.WriteElementString("ageofdgpsdata", Convert.ToString(raw.PositionData.DifferentialDataAge, CultureInfo.InvariantCulture));
                _output.WriteElementString("dgpsid", Convert.ToString(raw.PositionData.DifferentialStationId));

                _output.WriteStartElement("extensions");
                {
                    _output.WriteElementString("computerDateTime", computerDateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffffffK"));

                    _output.WriteStartElement("CorrectedPositionValue");
                    {
                        _output.WriteElementString("lat", Convert.ToString(corrected.PositionData.Latitude, CultureInfo.InvariantCulture));
                        _output.WriteElementString("lon", Convert.ToString(corrected.PositionData.Longitude, CultureInfo.InvariantCulture));
                    }
                    _output.WriteEndElement();

                    _output.WriteElementString("gpsStatus", Convert.ToString(gpsStatus));
                    _output.WriteElementString("speedKmh", Convert.ToString(raw.VelocityData.SpeedKmh, CultureInfo.InvariantCulture));

                    if (rteptExtension != null)
                    {
                        if (rteptExtension.Progress.HasValue)
                        {
                            _output.WriteElementString("progress", Convert.ToString(rteptExtension.Progress.Value, CultureInfo.InvariantCulture));
                        }
                    }

                    if (raw.PositionData.InsData != null)
                    {
                        _output.WriteStartElement("ins", "inertial", null);
                        {
                            _output.WriteElementString("navigationStatus", Convert.ToString(raw.PositionData.InsData.Status, CultureInfo.InvariantCulture));
                            _output.WriteElementString("accx", Convert.ToString(raw.PositionData.InsData.AccelerationX, CultureInfo.InvariantCulture));
                            _output.WriteElementString("accy", Convert.ToString(raw.PositionData.InsData.AccelerationY, CultureInfo.InvariantCulture));
                            _output.WriteElementString("accz", Convert.ToString(raw.PositionData.InsData.AccelerationZ, CultureInfo.InvariantCulture));
                            _output.WriteElementString("angrtx", Convert.ToString(raw.PositionData.InsData.AngularRateX, CultureInfo.InvariantCulture));
                            _output.WriteElementString("angrty", Convert.ToString(raw.PositionData.InsData.AngularRateY, CultureInfo.InvariantCulture));
                            _output.WriteElementString("angrtz", Convert.ToString(raw.PositionData.InsData.AngularRateZ, CultureInfo.InvariantCulture));
                            _output.WriteElementString("nvelo", Convert.ToString(raw.PositionData.InsData.NorthVelocity, CultureInfo.InvariantCulture));
                            _output.WriteElementString("evelo", Convert.ToString(raw.PositionData.InsData.EastVelocity, CultureInfo.InvariantCulture));
                            _output.WriteElementString("dvelo", Convert.ToString(raw.PositionData.InsData.DownVelocity, CultureInfo.InvariantCulture));
                            _output.WriteElementString("heading", Convert.ToString(raw.PositionData.InsData.Heading, CultureInfo.InvariantCulture));
                            _output.WriteElementString("pitch", Convert.ToString(raw.PositionData.InsData.Pitch, CultureInfo.InvariantCulture));
                            _output.WriteElementString("roll", Convert.ToString(raw.PositionData.InsData.Roll, CultureInfo.InvariantCulture));

                            if (raw.PrecisionData != null)
                            {
                                if (raw.PrecisionData.EastPositionAccuracy != null)
                                {
                                    _output.WriteElementString("eastPositionAccuracy", Convert.ToString(raw.PrecisionData.EastPositionAccuracy, CultureInfo.InvariantCulture));
                                }

                                if (raw.PrecisionData.DownPositionAccuracy != null)
                                {
                                    _output.WriteElementString("downPositionAccuracy", Convert.ToString(raw.PrecisionData.DownPositionAccuracy, CultureInfo.InvariantCulture));
                                }

                                if (raw.PrecisionData.NorthPositionAccuracy != null)
                                {
                                    _output.WriteElementString("northPositionAccuracy", Convert.ToString(raw.PrecisionData.NorthPositionAccuracy, CultureInfo.InvariantCulture));
                                }

                                if (raw.PrecisionData.DownVelocityAccuracy != null)
                                {
                                    _output.WriteElementString("downVelocityAccuracy", Convert.ToString(raw.PrecisionData.DownVelocityAccuracy, CultureInfo.InvariantCulture));
                                }

                                if (raw.PrecisionData.EastVelocityAccuracy != null)
                                {
                                    _output.WriteElementString("eastVelocityAccuracy", Convert.ToString(raw.PrecisionData.EastVelocityAccuracy, CultureInfo.InvariantCulture));
                                }

                                if (raw.PrecisionData.NorthVelocityAccuracy != null)
                                {
                                    _output.WriteElementString("northVelocityAccuracy", Convert.ToString(raw.PrecisionData.NorthVelocityAccuracy, CultureInfo.InvariantCulture));
                                }

                                if (raw.PrecisionData.HeadingAccuracy != null)
                                {
                                    _output.WriteElementString("headingAccuracy", Convert.ToString(raw.PrecisionData.HeadingAccuracy, CultureInfo.InvariantCulture));
                                }

                                if (raw.PrecisionData.PitchAccuracy != null)
                                {
                                    _output.WriteElementString("pitchAccuracy", Convert.ToString(raw.PrecisionData.PitchAccuracy, CultureInfo.InvariantCulture));
                                }

                                if (raw.PrecisionData.RollAccuracy != null)
                                {
                                    _output.WriteElementString("rollAccuracy", Convert.ToString(raw.PrecisionData.RollAccuracy, CultureInfo.InvariantCulture));
                                }
                            }
                        }
                        _output.WriteEndElement();
                    }
                }
                _output.WriteEndElement();
            }
            _output.WriteEndElement();
        }