예제 #1
0
        public GpxWriterTests()
        {
            _pointMetadata = new GpxPointMetadata();
            _pointMetadata.AgeOfDgpsData = 45;
            _pointMetadata.DgpsId = 124;
            _pointMetadata.Fix = GpsFix.Fix3D;
            _pointMetadata.GeoidHeight = 12.5;
            _pointMetadata.Hdop = 5.1;
            _pointMetadata.MagVar = 0.98;
            _pointMetadata.Pdop = 10.8;
            _pointMetadata.SatellitesCount = 8;
            _pointMetadata.Symbol = "WPT Symbol";
            _pointMetadata.Vdop = 8.1;

            _pointMetadata.Comment = "WPT Comment";
            _pointMetadata.Description = "WPT Description";
            _pointMetadata.Name = "WPT Name";
            _pointMetadata.Source = "WPT Source";
            _pointMetadata.Links.Add(new GpxLink(new Uri("http://www.topografix.com")) { Text = "Link text", Type = "plain/text" });
            _waypointWithMetadata.Metadata = _pointMetadata;

            _routeMetadata = new GpxTrackMetadata();
            _routeMetadata.Comment = "RTE Comment";
            _routeMetadata.Description = "RTE Description";
            _routeMetadata.Name = "RTE Name";
            _routeMetadata.Source = "RTE Source";
            _routeMetadata.Type = "RTE Type";
            _routeMetadata.Links.Add(new GpxLink(new Uri("http://www.topografix.com")) { Text = "Link text", Type = "plain/text" });
            _routeWithMetadata.Metadata = _routeMetadata;

            _trackMetadata = new GpxTrackMetadata();
            _trackMetadata.Comment = "TRK Comment";
            _trackMetadata.Description = "TRK Description";
            _trackMetadata.Name = "TRK Name";
            _trackMetadata.Source = "TRK Source";
            _trackMetadata.Type = "TRK Type";
            _trackMetadata.Links.Add(new GpxLink(new Uri("http://www.topografix.com")) { Text = "Link text", Type = "plain/text" });

            _track = new GpxTrack(new GpxTrackSegment[] { _segment });
            _trackWithMetadata = new GpxTrack(new GpxTrackSegment[] { _segment });
            _trackWithMetadata.Metadata = _trackMetadata;
        }
예제 #2
0
        /// <summary>
        /// Reads waypoint metadata from the internal XmlReader.
        /// </summary>
        /// <param name="metadata">Objecto to store read metadata</param>
        /// <returns>true if piece of metadata was read, otherwise returns false</returns>
        private bool TryReadPointMetadata(GpxPointMetadata metadata)
        {
            switch (_xmlReader.Name) {
                case "name":
                    metadata.Name = _xmlReader.ReadElementString(); return true;
                case "cmt":
                    metadata.Comment = _xmlReader.ReadElementString(); return true;
                case "desc":
                    metadata.Description = _xmlReader.ReadElementString(); return true;
                case "src":
                    metadata.Source = _xmlReader.ReadElementString(); return true;
                case "link":
                    metadata.Links.Add(ReadLink()); return true;
                case "magvar":
                    string magvarValue = _xmlReader.ReadElementString();
                    metadata.MagVar = double.Parse(magvarValue, _invariantCulture); return true;
                case "geoidheight":
                    string geoidHeightValue = _xmlReader.ReadElementString();
                    metadata.GeoidHeight = double.Parse(geoidHeightValue, _invariantCulture); return true;
                case "hdop":
                    string HdopValue = _xmlReader.ReadElementString();
                    metadata.Hdop = double.Parse(HdopValue, _invariantCulture); return true;
                case "vdop":
                    string vdopValue = _xmlReader.ReadElementString();
                    metadata.Vdop = double.Parse(vdopValue, _invariantCulture); return true;
                case "pdop":
                    string pdopValue = _xmlReader.ReadElementString();
                    metadata.Pdop = double.Parse(pdopValue, _invariantCulture); return true;
                case "ageofdgpsdata":
                    string ageValue = _xmlReader.ReadElementString();
                    metadata.AgeOfDgpsData = double.Parse(ageValue, _invariantCulture); return true;
                case "sat":
                    string satValue = _xmlReader.ReadElementString();
                    metadata.SatellitesCount = int.Parse(satValue, _invariantCulture); return true;
                case "dgpsid":
                    string dgpsidValue = _xmlReader.ReadElementString();
                    metadata.DgpsId = int.Parse(dgpsidValue, _invariantCulture); return true;
                case "fix":
                    string fixValue = _xmlReader.ReadElementString();
                    metadata.Fix = GpxFixHelper.ParseGpsFix(fixValue); return true;
            }

            return false;
        }
예제 #3
0
        /// <summary>
        /// Writes content of the GpxPointDetails class to the current position of output stream
        /// </summary>
        /// <param name="metadata">A GpxEntityDetails object to be written</param>
        private void WritePointMetadata(GpxPointMetadata metadata)
        {
            if (metadata != null) {
                if (metadata.Name != null) {
                    _xmlWriter.WriteElementString("name", metadata.Name);
                }
                if (metadata.Comment != null) {
                    _xmlWriter.WriteElementString("cmt", metadata.Comment);
                }
                if (metadata.Description != null) {
                    _xmlWriter.WriteElementString("desc", metadata.Description);
                }
                if (metadata.Source != null) {
                    _xmlWriter.WriteElementString("src", metadata.Source);
                }

                foreach (var link in metadata.Links) {
                    this.WriteLink(link);
                }

                if (metadata.MagVar.HasValue) {
                    _xmlWriter.WriteElementString("magvar", metadata.MagVar.Value.ToString(_invariantCulture));
                }
                if (metadata.GeoidHeight.HasValue) {
                    _xmlWriter.WriteElementString("geoidheight", (metadata.GeoidHeight ?? 0).ToString(_invariantCulture));
                }
                if (metadata.Symbol != null) {
                    _xmlWriter.WriteElementString("sym", metadata.Symbol);
                }
                if (metadata.Fix.HasValue) {
                    _xmlWriter.WriteElementString("fix", GpxFixHelper.GpsFixToString(metadata.Fix.Value));
                }
                if (metadata.SatellitesCount.HasValue) {
                    _xmlWriter.WriteElementString("sat", metadata.SatellitesCount.Value.ToString(_invariantCulture));
                }
                if (metadata.Hdop.HasValue) {
                    _xmlWriter.WriteElementString("hdop", metadata.Hdop.Value.ToString(_invariantCulture));
                }
                if (metadata.Vdop.HasValue) {
                    _xmlWriter.WriteElementString("vdop", metadata.Vdop.Value.ToString(_invariantCulture));
                }
                if (metadata.Pdop.HasValue) {
                    _xmlWriter.WriteElementString("pdop", metadata.Pdop.Value.ToString(_invariantCulture));
                }
                if (metadata.AgeOfDgpsData.HasValue) {
                    _xmlWriter.WriteElementString("ageofdgpsdata", metadata.AgeOfDgpsData.Value.ToString(_invariantCulture));
                }
                if (metadata.DgpsId.HasValue) {
                    _xmlWriter.WriteElementString("dgpsid", metadata.DgpsId.Value.ToString(_invariantCulture));
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Reads a GPX point from the internal XmlReader
        /// </summary>
        /// <param name="pointElementName">The name of the surrounding xml element</param>
        /// <returns>the point parsed from the XmlReader</returns>
        private GpxPoint ReadPoint(string pointElementName)
        {
            string latValue = _xmlReader.GetAttribute("lat");
            if (string.IsNullOrEmpty(latValue))
                throw new InvalidDataException("Requested attribute 'lat' not found.");
            double lat = double.Parse(latValue, _invariantCulture);

            string lonValue = _xmlReader.GetAttribute("lon");
            if (string.IsNullOrEmpty(lonValue))
                throw new InvalidDataException("Requested attribute 'lon' not found.");
            double lon = double.Parse(lonValue, _invariantCulture);

            double ele = double.NaN;
            DateTime timestamp = new DateTime();

            GpxPointMetadata metadata = null;
            if (this.Settings.ReadMetadata) {
                metadata = new GpxPointMetadata();
            }

            if (_xmlReader.IsEmptyElement == false) {
                _xmlReader.Read();

                while ((_xmlReader.NodeType == XmlNodeType.EndElement && _xmlReader.Name == pointElementName) == false) {
                    bool elementParsed = false;

                    if (_xmlReader.Name == "ele") {
                        string eleValue = _xmlReader.ReadElementString();
                        ele = double.Parse(eleValue, _invariantCulture);
                        elementParsed = true;
                    }

                    if (_xmlReader.Name == "time") {
                        string timeValue = _xmlReader.ReadElementString();
                        timestamp = DateTime.ParseExact(timeValue, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", _invariantCulture);
                        elementParsed = true;
                    }

                    if (this.Settings.ReadMetadata) {
                        elementParsed = elementParsed || this.TryReadPointMetadata(metadata);
                    }

                    if (!elementParsed) {
                        _xmlReader.Skip();
                    }
                }
            }
            _xmlReader.Skip();

            GpxPoint result = new GpxPoint(lon, lat, ele, timestamp);
            result.Metadata = metadata;

            return result;
        }