Exemplo n.º 1
0
        public void Constructor_Coordinate_CreatesPointWithPositionAndNullTimestamp()
        {
            var target = new GpxPoint(_coordinate);

            Assert.Equal(_coordinate, target.Position);
            Assert.Null(target.Timestamp);
        }
Exemplo n.º 2
0
        public void Constructor_LonLatElevationTimestamp_CreatesPointWithPositionAndTimestamp()
        {
            var timestamp = DateTime.Now;
            var target = new GpxPoint(_xOrdinate, _yOrdinate, _zOrdinate, timestamp);

            Assert.Equal(_coordinate, target.Position);
            Assert.Equal(timestamp, target.Timestamp);
        }
Exemplo n.º 3
0
        public void Save_IGpxWriter_WritesDataToWriter()
        {
            var waypoint = new GpxPoint();
            var route = new GpxRoute();
            var track = new GpxTrack();

            Mock<IGpxWriter> writerM = new Mock<IGpxWriter>();
            writerM.Setup(w => w.Write(waypoint)).Verifiable();
            writerM.Setup(w => w.Write(route)).Verifiable();
            writerM.Setup(w => w.Write(track)).Verifiable();

            var target = new GpxDocument(new[] { waypoint }, new[] { route }, new[] { track });
            target.Save(writerM.Object);

            writerM.Verify(w => w.Write(waypoint), Times.Once());
            writerM.Verify(w => w.Write(route), Times.Once());
            writerM.Verify(w => w.Write(track), Times.Once());
        }
Exemplo n.º 4
0
 /// <summary>
 /// Writes the given waypoint to the output stream
 /// </summary>
 /// <param name="waypoint">The waypoint to write</param>
 public void Write(GpxPoint waypoint)
 {
     WritePoint(waypoint, "wpt");
 }
Exemplo n.º 5
0
        /// <summary>
        /// Writes the given point to the output stream
        /// </summary>
        /// <param name="point">The point to be written</param>
        /// <param name="pointElementName">The name of the XML element the point is to be written to</param>
        private void WritePoint(GpxPoint point, string pointElementName)
        {
            _xmlWriter.WriteStartElement(pointElementName);
            _xmlWriter.WriteAttributeString("lat", point.Position.Y.ToString(_invariantCulture));
            _xmlWriter.WriteAttributeString("lon", point.Position.X.ToString(_invariantCulture));

            if (!double.IsNaN(point.Position.Z)) {
                _xmlWriter.WriteElementString("ele", point.Position.Z.ToString(_invariantCulture));
            }

            if (point.Timestamp != null) {
                _xmlWriter.WriteElementString("time", point.Timestamp.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", _invariantCulture));
            }

            if (this.Settings.WriteMetadata) {
                this.WritePointMetadata(point.Metadata);
            }

            _xmlWriter.WriteEndElement();
        }
Exemplo n.º 6
0
        public void GeometryType_ReturnsWaypoint()
        {
            GpxPoint target = new GpxPoint();

            Assert.Equal(GpxGeometryType.Waypoint, target.GeometryType);
        }
Exemplo n.º 7
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;
        }