Example #1
0
        private void WriteTrackPoint(string elementName, GpxTrackPoint trackPoint)
        {
            Writer_.WriteStartElement(elementName);

            Writer_.WriteAttributeString("lat", trackPoint.Latitude.ToString(CultureInfo.InvariantCulture));
            Writer_.WriteAttributeString("lon", trackPoint.Longitude.ToString(CultureInfo.InvariantCulture));
            if (trackPoint.Elevation != default(double))
            {
                Writer_.WriteElementString("ele", trackPoint.Elevation.ToString(CultureInfo.InvariantCulture));
            }
            if (trackPoint.Time != default(DateTime))
            {
                Writer_.WriteElementString("time", ToGpxDateString(trackPoint.Time));
            }
            if (trackPoint.MagneticVar != default(double))
            {
                Writer_.WriteElementString("magvar", trackPoint.MagneticVar.ToString(CultureInfo.InvariantCulture));
            }
            if (trackPoint.GeoidHeight != default(double))
            {
                Writer_.WriteElementString("geoidheight", trackPoint.GeoidHeight.ToString(CultureInfo.InvariantCulture));
            }
            if (!string.IsNullOrEmpty(trackPoint.FixType))
            {
                Writer_.WriteElementString("fix", trackPoint.FixType);
            }
            if (trackPoint.Satelites != default(int))
            {
                Writer_.WriteElementString("sat", trackPoint.Satelites.ToString(CultureInfo.InvariantCulture));
            }
            if (trackPoint.Hdop != default(double))
            {
                Writer_.WriteElementString("hdop", trackPoint.Hdop.ToString(CultureInfo.InvariantCulture));
            }
            if (trackPoint.Vdop != default(double))
            {
                Writer_.WriteElementString("vdop", trackPoint.Vdop.ToString(CultureInfo.InvariantCulture));
            }
            if (trackPoint.Pdop != default(double))
            {
                Writer_.WriteElementString("pdop", trackPoint.Pdop.ToString(CultureInfo.InvariantCulture));
            }
            if (trackPoint.AgeOfData != default(double))
            {
                Writer_.WriteElementString("ageofdgpsdata", trackPoint.AgeOfData.ToString(CultureInfo.InvariantCulture));
            }
            if (trackPoint.DgpsId != default(int))
            {
                Writer_.WriteElementString("dgpsid", trackPoint.DgpsId.ToString(CultureInfo.InvariantCulture));
            }

            Writer_.WriteEndElement();
        }
Example #2
0
        private GpxTrackPoint ReadGpxTrackPoint(XmlReader reader)
        {
            GpxTrackPoint point = new GpxTrackPoint();

            string elementName    = reader.Name;
            bool   isEmptyElement = reader.IsEmptyElement;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "lat":
                    point.Latitude = double.Parse(reader.Value, CultureInfo.InvariantCulture.NumberFormat);
                    break;

                case "lon":
                    point.Longitude = double.Parse(reader.Value, CultureInfo.InvariantCulture.NumberFormat);
                    break;
                }
            }

            if (isEmptyElement)
            {
                return(point);
            }

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

                    switch (reader.Name)
                    {
                    case "ele":
                        point.Elevation = ReadContentAsDouble(reader);
                        break;

                    case "time":
                        point.Time = ReadContentAsDateTime(reader);
                        break;

                    case "magvar":
                        point.MagneticVar = ReadContentAsDouble(reader);
                        break;

                    case "geoidheight":
                        point.GeoidHeight = ReadContentAsDouble(reader);
                        break;

                    case "fix":
                        point.FixType = ReadContentAsString(reader);
                        break;

                    case "sat":
                        point.Satelites = ReadContentAsInt(reader);
                        break;

                    case "hdop":
                        point.Hdop = ReadContentAsDouble(reader);
                        break;

                    case "vdop":
                        point.Vdop = ReadContentAsDouble(reader);
                        break;

                    case "pdop":
                        point.Pdop = ReadContentAsDouble(reader);
                        break;

                    case "ageofdgpsdata":
                        point.AgeOfData = ReadContentAsDouble(reader);
                        break;

                    case "dgpsid":
                        point.DgpsId = ReadContentAsInt(reader);
                        break;

                    case "extensions":
                        ReadTrackPointExtensions(reader);
                        break;

                    case "name":
                    case "cmt":
                    case "desc":
                    case "src":
                    case "link":
                    case "sym":
                    case "type":
                        SkipElement(reader);
                        break;

                    default:
                        throw new FormatException(reader.Name);
                    }

                    break;

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

            throw new FormatException(elementName);
        }