Example #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;
        }
Example #2
0
 /// <summary>
 /// Writes content of the GpxEntityDetails class to the current position of output stream
 /// </summary>
 /// <param name="metadata">A GpxEntityDetails object to be written</param>
 private void WriteTrackMetadata(GpxTrackMetadata 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.Comment != null)
             _xmlWriter.WriteElementString("type", metadata.Type);
     }
 }
Example #3
0
        /// <summary>
        /// Reades a GPX track from the internal XmlReader
        /// </summary>
        /// <returns>the track parsed form the XmlReader</returns>
        private GpxTrack ReadTrack()
        {
            GpxTrack result = new GpxTrack();

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

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

                while ((_xmlReader.NodeType == XmlNodeType.EndElement && _xmlReader.Name == "trk") == false) {
                    bool elementParsed = false;
                    if (_xmlReader.Name == "trkseg") {
                        GpxTrackSegment segment = ReadTrackSegment();
                        result.Geometries.Add(segment);
                        elementParsed = true;
                    }

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

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

                result.Metadata = metadata;
            }
            _xmlReader.Skip();

            return result;
        }
Example #4
0
        /// <summary>
        /// Reads track/route 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 TryReadTrackMetadata(GpxTrackMetadata 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 "type":
                    metadata.Type = _xmlReader.ReadElementString(); return true;
                case "link":
                    metadata.Links.Add(ReadLink()); return true;
            }

            return false;
        }
Example #5
0
        /// <summary>
        /// Reads a GPX route from the internal XmlReader
        /// </summary>
        /// <returns>the route parsed from the XmlReader</returns>
        private GpxRoute ReadRoute()
        {
            GpxRoute result = new GpxRoute();

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

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

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

                    if (_xmlReader.Name == "rtept") {
                        result.Points.Add(ReadPoint("rtept"));
                        elementParsed = true;
                    }

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

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

                result.Metadata = metadata;
            }
            _xmlReader.Skip();

            return result;
        }