Exemplo n.º 1
0
        public void GPXTrackConstructorCreatesEmptyTrackWithName()
        {
            string name = "Test";

            GPXTrack target = new GPXTrack(name);

            Assert.Equal(0, target.Segments.Count);
            Assert.Equal(name, target.Name);
        }
 void ProcessTrack(GPXTrack track)
 {
     _tracks.Add(track);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Reads track from the gpx
        /// </summary>
        private void ReadTrack()
        {
            GPXTrack parsedTrack = new GPXTrack();

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

                while (_xmlReader.NodeType != XmlNodeType.EndElement) {
                    if (_xmlReader.NodeType == XmlNodeType.Element) {
                        switch (_xmlReader.Name) {
                            case "trkseg":
                                parsedTrack.Segments.Add(ReadTrackSegment());
                                break;
                            case "name":
                                parsedTrack.Name = _xmlReader.ReadString();
                                _xmlReader.Skip();
                                break;
                            default:
                                _xmlReader.Skip();
                                break;
                        }
                    }
                    else {
                        _xmlReader.Skip();
                    }
                }
            }

            _xmlReader.Skip();
            OnTrackRead(parsedTrack);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Raises the TrackRead event
 /// </summary>
 /// <param name="node">The track read from the xml</param>
 protected void OnTrackRead(GPXTrack track)
 {
     GPXTrackReadHandler temp = TrackRead;
     if (temp != null) {
         temp(track);
     }
 }
Exemplo n.º 5
0
        public void GPXTrackConstructorCreatesEmptyTrack()
        {
            GPXTrack target = new GPXTrack();

            Assert.Equal(0, target.Segments.Count);
        }
        public void GPXXmlDataWriterWriteTrackWithMultipleSegments()
        {
            MemoryStream ms = new MemoryStream();

            GPXTrack track = new GPXTrack();
            track.Name = "TRACK NAME";

            GPXPoint point1 = new GPXPoint(18.5, 50.1);
            GPXPoint point2 = new GPXPoint(10.3, 20.5);
            GPXPoint point3 = new GPXPoint(8.2, 28.8);

            GPXTrackSegment segment1 = new GPXTrackSegment();
            segment1.Nodes.Add(point1);
            segment1.Nodes.Add(point2);
            segment1.Nodes.Add(point3);
            track.Segments.Add(segment1);

            GPXTrackSegment segment2 = new GPXTrackSegment();
            segment2.Nodes.Add(point1);
            segment2.Nodes.Add(point2);
            track.Segments.Add(segment2);

            using (GPXXmlDataWriter target = new GPXXmlDataWriter(ms)) {
                target.WriteTrack(track);
            }

            ms.Seek(0, 0);

            XElement gpxRoot = XDocument.Load(new StreamReader(ms)).Root;

            XElement trackElement = gpxRoot.Element("trk");
            Assert.NotNull(trackElement);
            Assert.Equal(track.Name, trackElement.Element("name").Value);

            var trackSegments = trackElement.Elements("trkseg").ToList();
            Assert.Equal(track.Segments.Count, trackSegments.Count);

            var points = trackSegments[0].Elements("trkpt").ToList();
            Assert.Equal(track.Segments[0].NodesCount, points.Count);

            points = trackSegments[1].Elements("trkpt").ToList();
            Assert.Equal(track.Segments[1].NodesCount, points.Count);
        }
        public void GPXXmlDataWriterWriteSimpleTrack()
        {
            MemoryStream ms = new MemoryStream();

            GPXTrack track = new GPXTrack();
            track.Name = "TRACK NAME";

            GPXPoint point1 = new GPXPoint(18.5, 50.1);
            GPXPoint point2 = new GPXPoint(10.3, 20.5);

            GPXTrackSegment segment = new GPXTrackSegment();
            segment.Nodes.Add(point1);
            segment.Nodes.Add(point2);

            track.Segments.Add(segment);

            using (GPXXmlDataWriter target = new GPXXmlDataWriter(ms)) {
                target.WriteTrack(track);
            }

            ms.Seek(0, 0);

            XElement gpxRoot = XDocument.Load(new StreamReader(ms)).Root;

            XElement trackElement = gpxRoot.Element("trk");
            Assert.NotNull(trackElement);
            Assert.Equal(track.Name, trackElement.Element("name").Value);

            XElement trackSegmentElement = trackElement.Element("trkseg");
            Assert.NotNull(trackSegmentElement);

            var points = trackSegmentElement.Elements("trkpt").ToList();
            Assert.Equal(2, points.Count);
            Assert.Equal(point1.Latitude, double.Parse(points[0].Attribute("lat").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point1.Longitude, double.Parse(points[0].Attribute("lon").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point2.Latitude, double.Parse(points[1].Attribute("lat").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point2.Longitude, double.Parse(points[1].Attribute("lon").Value, System.Globalization.CultureInfo.InvariantCulture));
        }