Beispiel #1
0
        private void WriteTrackPoint(GpxTrackPoint trackPoint)
        {
            Writer_.WriteStartElement("trkpt");
            WritePoint(trackPoint);

            if (trackPoint.HasExtensions)
            {
                Writer_.WriteStartElement("extensions");
                Writer_.WriteStartElement("TrackPointExtension", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE);

                if (trackPoint.Temperature != null)
                {
                    Writer_.WriteElementString("atemp", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Temperature.Value.ToString());
                }
                if (trackPoint.WaterTemperature != null)
                {
                    Writer_.WriteElementString("wtemp", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.WaterTemperature.Value.ToString());
                }
                if (trackPoint.Depth != null)
                {
                    Writer_.WriteElementString("depth", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Depth.Value.ToString());
                }
                if (trackPoint.HeartRate != null)
                {
                    Writer_.WriteElementString("hr", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.HeartRate.Value.ToString());
                }
                if (trackPoint.Cadence != null)
                {
                    Writer_.WriteElementString("cad", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Cadence.Value.ToString());
                }
                if (trackPoint.Speed != null)
                {
                    Writer_.WriteElementString("speed", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Speed.Value.ToString());
                }
                if (trackPoint.Course != null)
                {
                    Writer_.WriteElementString("course", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Course.Value.ToString());
                }
                if (trackPoint.Bearing != null)
                {
                    Writer_.WriteElementString("bearing", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Bearing.Value.ToString());
                }

                Writer_.WriteEndElement();
                Writer_.WriteEndElement();
            }

            Writer_.WriteEndElement();
        }
Beispiel #2
0
        private void ReadTrackPointExtensions(GpxTrackPoint trackPoint)
        {
            if (Reader_.IsEmptyElement)
            {
                return;
            }

            string elementName = Reader_.Name;

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                case XmlNodeType.Element:

                    if (Reader_.NamespaceURI == GpxNamespaces.GARMIN_EXTENSIONS_NAMESPACE ||
                        Reader_.NamespaceURI == GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V1_NAMESPACE ||
                        Reader_.NamespaceURI == GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE)
                    {
                        switch (Reader_.LocalName)
                        {
                        case "TrackPointExtension":
                            ReadGarminTrackPointExtensions(trackPoint);
                            break;

                        default:
                            SkipElement();
                            break;
                        }

                        break;
                    }

                    SkipElement();
                    break;

                case XmlNodeType.EndElement:
                    if (Reader_.Name != elementName)
                    {
                        throw new FormatException(Reader_.Name);
                    }
                    return;
                }
            }

            throw new FormatException(elementName);
        }
Beispiel #3
0
        private GpxTrackPoint ReadGpxTrackPoint()
        {
            string elementName    = Reader_.Name;
            bool   isEmptyElement = Reader_.IsEmptyElement;

            GpxTrackPoint trackPoint = new GpxTrackPoint();

            GetPointLocation(trackPoint);
            if (isEmptyElement)
            {
                return(trackPoint);
            }

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                case XmlNodeType.Element:

                    switch (Reader_.Name)
                    {
                    case "extensions":
                        ReadTrackPointExtensions(trackPoint);
                        break;

                    default:
                        if (!ProcessPointField(trackPoint))
                        {
                            SkipElement();
                        }
                        break;
                    }

                    break;

                case XmlNodeType.EndElement:
                    if (Reader_.Name != elementName)
                    {
                        throw new FormatException(Reader_.Name);
                    }
                    return(trackPoint);
                }
            }

            throw new FormatException(elementName);
        }
Beispiel #4
0
        private void ReadGarminTrackPointExtensions(GpxTrackPoint trackPoint)
        {
            if (Reader_.IsEmptyElement)
            {
                return;
            }

            string elementName = Reader_.Name;

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                case XmlNodeType.Element:
                    switch (Reader_.LocalName)
                    {
                    case "Temperature":
                    case "atemp":
                        trackPoint.Temperature = ReadContentAsDouble();
                        break;

                    case "wtemp":
                        trackPoint.WaterTemperature = ReadContentAsDouble();
                        break;

                    case "Depth":
                    case "depth":
                        trackPoint.Depth = ReadContentAsDouble();
                        break;

                    case "hr":
                        trackPoint.HeartRate = ReadContentAsInt();
                        break;

                    case "cad":
                        trackPoint.Cadence = ReadContentAsInt();
                        break;

                    case "speed":
                        trackPoint.Speed = ReadContentAsDouble();
                        break;

                    case "course":
                        trackPoint.Course = ReadContentAsDouble();
                        break;

                    case "bearing":
                        trackPoint.Bearing = ReadContentAsDouble();
                        break;

                    default:
                        SkipElement();
                        break;
                    }

                    break;

                case XmlNodeType.EndElement:
                    if (Reader_.Name != elementName)
                    {
                        throw new FormatException(Reader_.Name);
                    }
                    return;
                }
            }

            throw new FormatException(elementName);
        }