Exemplo n.º 1
0
        public void Read_ReadsWaypointUnsortedMetadataAndExtension()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_waypoint_with_metadata);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = true });
            var result = target.Read() as GpxPoint;

            Assert.Equal(0.98, result.Metadata.MagVar);
            Assert.Equal(12.5, result.Metadata.GeoidHeight);
            Assert.Equal(GpsFix.Fix3D, result.Metadata.Fix);
            Assert.Equal(8, result.Metadata.SatellitesCount);
            Assert.Equal(5.1, result.Metadata.Hdop);
            Assert.Equal(8.1, result.Metadata.Vdop);
            Assert.Equal(10.8, result.Metadata.Pdop);
            Assert.Equal(45, result.Metadata.AgeOfDgpsData);
            Assert.Equal(124, result.Metadata.DgpsId);

            Assert.Equal("WPT Comment", result.Metadata.Comment);
            Assert.Equal("WPT Description", result.Metadata.Description);
            Assert.Equal("WPT Name", result.Metadata.Name);
            Assert.Equal("WPT Source", result.Metadata.Source);

            Assert.Equal(1, result.Metadata.Links.Count);
            GpxLink link = result.Metadata.Links.Single();
            Assert.Equal("http://www.topografix.com", link.Url.OriginalString);
            Assert.Equal("Link text", link.Text);
            Assert.Equal("plain/text", link.Type);
        }
Exemplo n.º 2
0
        public void Read_SetsMetadataIfReadMetadataIsTrue()
        {
            var data = new MemoryStream(GpxTestData.gpx_waypoint_simple);
            var expectedCoordinate = new Coordinate(-71.119277, 42.438878);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = true });
            var result = target.Read() as GpxPoint;

            Assert.NotNull(result.Metadata);
        }
Exemplo n.º 3
0
        public void Read_ParsesWaypointWithLatLonElevationAndTime()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_waypoint_with_metadata);
            Coordinate expectedCoordinate = new Coordinate(-71.119277, 42.438878, 44.586548);
            DateTime expectedTime = new DateTime(2001, 11, 28, 21, 5, 28, DateTimeKind.Utc);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });
            var result = target.Read() as GpxPoint;

            Assert.Equal(result.Position, expectedCoordinate);
            Assert.Equal(result.Timestamp, expectedTime);
        }
Exemplo n.º 4
0
        public void Read_ReadsAllEntitiesFromRealGpxFile()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_real_file);
            List<IGpxGeometry> parsed = new List<IGpxGeometry>();

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = true });

            IGpxGeometry geometry = null;
            while ((geometry = target.Read()) != null) {
                parsed.Add(geometry);
            }

            // waypoints
            Assert.Equal(3, parsed.Where(g => g.GeometryType == GpxGeometryType.Waypoint).Count());

            // routes
            Assert.Equal(2, parsed.Where(g => g.GeometryType == GpxGeometryType.Route).Count());

            // tracks
            Assert.Equal(1, parsed.Where(g => g.GeometryType == GpxGeometryType.Track).Count());
        }
Exemplo n.º 5
0
        public void Read_ParsesMultipleRoutes()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_route_multiple_routes);
            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });

            var result1 = target.Read() as GpxRoute;
            var result2 = target.Read() as GpxRoute;

            Assert.Equal(3, result1.Points.Count);
            Assert.Equal(2, result2.Points.Count);
        }
Exemplo n.º 6
0
        public void Read_ParsesTrackWithSingleSegmentAndExtensions()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_track_single_track_segment);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });
            var result = target.Read() as GpxTrack;

            Assert.Equal(1, result.Geometries.Count);

            GpxTrackSegment segment = result.Geometries[0];
        }
Exemplo n.º 7
0
        public void Read_ParsesTrackWithEmptySegment()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_track_empty_track_segment);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });
            var result = target.Read() as GpxTrack;

            Assert.Equal(1, result.Geometries.Count);
            Assert.Empty(result.Geometries[0].Points);
        }
Exemplo n.º 8
0
        public void Read_DoesntSetMetadataIfReadMetadataIsFalse()
        {
            var data = new MemoryStream(GpxTestData.gpx_waypoint_with_metadata);
            var expectedCoordinate = new Coordinate(-71.119277, 42.438878);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });
            var result = target.Read() as GpxPoint;

            Assert.Null(result.Metadata);
        }
Exemplo n.º 9
0
        public void Read_ParsesSingleRouteWithExtensions()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_route_with_metadata_and_extensions);
            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });

            var result = target.Read() as GpxRoute;

            Assert.Equal(3, result.Points.Count);
        }
Exemplo n.º 10
0
        public void Read_ParsesTrackMetadata()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_track_with_metadata);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = true });
            var result = target.Read() as GpxTrack;

            Assert.Equal("TRK Comment", result.Metadata.Comment);
            Assert.Equal("TRK Description", result.Metadata.Description);
            Assert.Equal("TRK Name", result.Metadata.Name);
            Assert.Equal("TRK Source", result.Metadata.Source);
            Assert.Equal("TRK Type", result.Metadata.Type);

            GpxLink link = result.Metadata.Links.Single();
            Assert.Equal("http://www.topografix.com", link.Url.OriginalString);
            Assert.Equal("Link text", link.Text);
            Assert.Equal("plain/text", link.Type);
        }
Exemplo n.º 11
0
        public void Read_ParsesSingleRoute()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_route_single_route);
            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });

            var result = target.Read() as GpxRoute;

            Assert.Equal(new Coordinate(-76.638178825, 39.449270368), result.Points[0].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 23, DateTimeKind.Utc), result.Points[0].Timestamp);
            Assert.Equal(new Coordinate(-76.638012528, 39.449130893), result.Points[1].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 28, DateTimeKind.Utc), result.Points[1].Timestamp);
            Assert.Equal(new Coordinate(-76.637980342, 39.449098706), result.Points[2].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 33, DateTimeKind.Utc), result.Points[2].Timestamp);
        }
Exemplo n.º 12
0
        public void Read_ParsesMultipleWaypoints()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_waypoint_multiple);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });
            GpxPoint result = null;

            int count = 0;
            while ((result = target.Read() as GpxPoint) != null) {
                count++;
            }

            Assert.Equal(3, count);
        }
Exemplo n.º 13
0
        public void Read_ParsesMultipleTracks()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_track_multiple_tracks);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });
            var result1 = target.Read() as GpxTrack;
            var result2 = target.Read() as GpxTrack;

            //segments - first track
            Assert.Equal(2, result1.Geometries.Count);
            //points in segments - first track
            Assert.Equal(3, result1.Geometries[0].Points.Count);
            Assert.Equal(2, result1.Geometries[1].Points.Count);

            //segments - second track
            Assert.Equal(1, result2.Geometries.Count);
            //points in segments - second track
            Assert.Equal(2, result2.Geometries[0].Points.Count);
        }
Exemplo n.º 14
0
        public void Read_SetsTrackMetadataToNullIfReadMetadataIsFalse()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_track_with_metadata);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });
            var result = target.Read() as GpxTrack;

            Assert.Null(result.Metadata);
        }
Exemplo n.º 15
0
        public void Read_ParsesTrackWithMultipleSegments()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_track_2_track_segments);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });
            var result = target.Read() as GpxTrack;

            //segments
            Assert.Equal(2, result.Geometries.Count);
            //points in segments
            Assert.Equal(3, result.Geometries[0].Points.Count);
            Assert.Equal(2, result.Geometries[1].Points.Count);
        }
Exemplo n.º 16
0
        public void Read_ThrowsExceptionIfWaypointHasntLon()
        {
            GpxReader target = new GpxReader(new MemoryStream(GpxTestData.gpx_waypoint_without_lon), new GpxReaderSettings() { ReadMetadata = false });

            Assert.Throws<InvalidDataException>(() => target.Read());
        }
Exemplo n.º 17
0
        public void Read_ParsesTrackWithSingleSegment()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_track_single_track_segment);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });
            var result = target.Read() as GpxTrack;

            Assert.Equal(1, result.Geometries.Count);

            GpxTrackSegment segment = result.Geometries[0];
            Assert.Equal(new Coordinate(-76.638178825, 39.449270368), segment.Points[0].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 23, DateTimeKind.Utc), segment.Points[0].Timestamp);
            Assert.Equal(new Coordinate(-76.638012528, 39.449130893), segment.Points[1].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 28, DateTimeKind.Utc), segment.Points[1].Timestamp);
            Assert.Equal(new Coordinate(-76.637980342, 39.449098706), segment.Points[2].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 33, DateTimeKind.Utc), segment.Points[2].Timestamp);
        }
Exemplo n.º 18
0
        public void Read_ParsesEmptyRoute()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_route_empty);
            GpxReader target = new GpxReader(data, new GpxReaderSettings() {ReadMetadata = false});

            var result = target.Read() as GpxRoute;

            Assert.Equal(0, result.Points.Count);
        }
Exemplo n.º 19
0
        public void Read_ParsesEmptyTrack()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_track_empty);

            GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = false });
            var result = target.Read() as GpxTrack;

            Assert.Equal(0, result.Geometries.Count);
        }