public void GPXXmlDataReaderCanComplexPoint()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.WaypointRead += new GPXWaypointReadHandler(ProcessWaypoint);

            // <wpt lat="50.4522196" lon="16.1117968">
            //   <cmt>COMMENT</cmt>
            //   <desc>DESCRIPTION</desc>
            //   <ele>433.4368896</ele>
            //   <name>POINT 001</name>
            //   <time>2009-06-18T08:03:26Z</time>
            // </wpt>
            // <wpt lat="50.4522196" lon="16.1117968">
            //   <name>POINT 002</name>
            // </wpt>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_complex_waypoint));

            Assert.Equal(2, _waypoints.Count);

            Assert.Equal(50.4522196, _waypoints[0].Latitude);
            Assert.Equal(16.1117968, _waypoints[0].Longitude);
            Assert.Equal(433.4368896, _waypoints[0].Elevation);
            Assert.Equal("DESCRIPTION", _waypoints[0].Description);
            Assert.Equal("COMMENT", _waypoints[0].Commenet);
            Assert.Equal("POINT 001", _waypoints[0].Name);
            Assert.Equal(new DateTime(2009, 6, 18, 8, 3, 26, DateTimeKind.Utc), _waypoints[0].Time);

            Assert.Equal("POINT 002", _waypoints[1].Name);
        }
        public void GPXXmlDataReaderReadWaypointWithMissingLongitudeThrowsException()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.WaypointRead += new GPXWaypointReadHandler(ProcessWaypoint);

            // <wpt lat="-50.4551789" />

            Assert.Throws<XmlException>(delegate { target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_simple_waypoint_missing_lon)); });
        }
        public void GPXXmlDataReaderReadWaypointWithIncorrectLatitudeThrowsException()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.WaypointRead += new GPXWaypointReadHandler(ProcessWaypoint);

            // <wpt lat="ERROR" lon="-16.1174158" />

            Assert.Throws<FormatException>(delegate { target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_simple_waypoint_incorrect_lat)); });
        }
 public void GPXXmlDataReaderReadThrowsExceptionReadingInvalidRootElement()
 {
     GPXXmlDataReader target = new GPXXmlDataReader();
     Assert.Throws<XmlException>(delegate { target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_invalid_root_element)); });
 }
 public void GPXXmlDataReaderReadThrowsExceptionIfFileDoesnotExist()
 {
     GPXXmlDataReader target = new GPXXmlDataReader();
     Assert.Throws<FileNotFoundException>(delegate { target.Read("non-existing-file.osm"); });
 }
        public void GPXXmlDataReaderCanReadTrackWithName()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.TrackRead += new GPXTrackReadHandler(ProcessTrack);

            // <trk>
            //   <name>TRACK NAME</name>
            //   <trkseg>
            //     <trkpt lat="50.4950254" lon="16.1050424" />
            //     <trkpt lat="50.49503" lon="16.10503" />
            //   </trkseg>
            // </trk>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_simple_named_track));

            Assert.Equal(1, _tracks.Count);

            Assert.Equal("TRACK NAME", _tracks[0].Name);
            Assert.Equal(1, _tracks[0].Segments.Count);
            Assert.Equal(2, _tracks[0].Segments[0].NodesCount);
        }
        public void GPXXmlDataReaderCanReadTrackWithMultipleSegments()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.TrackRead += new GPXTrackReadHandler(ProcessTrack);

            // <trk>
            //   <trkseg>
            //     <trkpt lat="50.4950254" lon="16.1050424" />
            //     <trkpt lat="50.4950254" lon="16.1050424" />
            //   </trkseg>
            //   <trkseg>
            //     <trkpt lat="50.4950254" lon="16.1050424" />
            //     <trkpt lat="50.4950254" lon="16.1050424" />
            //     <trkpt lat="50.4950254" lon="16.1050424" />
            //   </trkseg>
            // </trk>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_track_multiple_segments));

            Assert.Equal(1, _tracks.Count);

            Assert.Equal(2, _tracks[0].Segments.Count);

            Assert.Equal(2, _tracks[0].Segments[0].NodesCount);
            Assert.Equal(3, _tracks[0].Segments[1].NodesCount);
        }
        public void GPXXmlDataReaderCanReadNamedRoute()
        {
            Clear();

            GPXXmlDataReader target = new GPXXmlDataReader();
            target.RouteRead += new GPXRouteReadHandler(ProcessRoute);

            // <rte>
            //   <name>ROUTE NAME</name>
            //   <rtept lat="50.0405788" lon="14.4694233">
            //   </rtept>
            //   <rtept lat="49.9116083" lon="14.7193313">
            //   </rtept>
            //   <rtept lat="49.8448186" lon="14.7991063">
            //   </rtept>
            // </rte>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_named_route));

            Assert.Equal(1, _routes.Count);
            Assert.Equal("ROUTE NAME", _routes[0].Name);
            Assert.Equal(3, _routes[0].NodesCount);
        }
        public void GPXXmlDataReaderCanReadSimpleRoute()
        {
            Clear();

            GPXXmlDataReader target = new GPXXmlDataReader();
            target.RouteRead +=new GPXRouteReadHandler(ProcessRoute);

            // <rte>
            //   <rtept lat="50.0405788" lon="14.4694233" />
            //   <rtept lat="49.9116083" lon="14.7193313">
            //   </rtept>
            // </rte>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_simple_route));

            Assert.Equal(1, _routes.Count);
            Assert.Equal(2, _routes[0].NodesCount);
        }
        public void GPXXmlDataReaderCanReadRealGPXFile()
        {
            Clear();

            GPXXmlDataReader target = new GPXXmlDataReader();
            target.WaypointRead += new GPXWaypointReadHandler(ProcessWaypoint);
            target.TrackRead += new GPXTrackReadHandler(ProcessTrack);
            target.RouteRead += new GPXRouteReadHandler(ProcessRoute);

            // 3 waypoints
            // 2 routes (3 and 1) points
            // 2 tracks
            //  1 segment, 2 points
            //  2 segments, 998 points and 10 points
            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_real));

            Assert.Equal(3, _waypoints.Count);

            Assert.Equal(2, _routes.Count);
            Assert.Equal(3, _routes[0].NodesCount);
            Assert.Equal(1, _routes[1].NodesCount);

            Assert.Equal(2, _tracks.Count);

            Assert.Equal(1, _tracks[0].Segments.Count);
            Assert.Equal(2, _tracks[0].Segments[0].NodesCount);

            Assert.Equal(2, _tracks[1].Segments.Count);
            Assert.Equal(998, _tracks[1].Segments[0].NodesCount);
            Assert.Equal(10, _tracks[1].Segments[1].NodesCount);
        }
        public void GPXXmlDataReaderCanReadPointsTime()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.WaypointRead += new GPXWaypointReadHandler(ProcessWaypoint);

            // <wpt lat="50.4522196" lon="16.1117968">
            //   <time>2009-06-18T08:03:26Z</time>
            // </wpt>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_waypoint_with_time));

            Assert.Equal(1, _waypoints.Count);

            Assert.Equal(50.4522196, _waypoints[0].Latitude);
            Assert.Equal(16.1117968, _waypoints[0].Longitude);
            Assert.Equal(new DateTime(2009, 6, 18, 8, 3, 26, DateTimeKind.Utc), _waypoints[0].Time);
        }
        public void GPXXmlDataReaderCanReadPointsName()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.WaypointRead += new GPXWaypointReadHandler(ProcessWaypoint);

            // <wpt lat="50.4522196" lon="16.1117968">
            //   <name>POINT 001</name>
            // </wpt>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_waypoint_with_name));

            Assert.Equal(1, _waypoints.Count);

            Assert.Equal(50.4522196, _waypoints[0].Latitude);
            Assert.Equal(16.1117968, _waypoints[0].Longitude);
            Assert.Equal("POINT 001", _waypoints[0].Name);
        }
        public void GPXXmlDataReaderCanReadPointsElevtion()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.WaypointRead += new GPXWaypointReadHandler(ProcessWaypoint);

            // <wpt lat="50.4522196" lon="16.1117968">
            //   <ele>433.4368896</ele>
            // </wpt>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_waypoint_with_elevation));

            Assert.Equal(1, _waypoints.Count);

            Assert.Equal(50.4522196, _waypoints[0].Latitude);
            Assert.Equal(16.1117968, _waypoints[0].Longitude);
            Assert.Equal(433.4368896, _waypoints[0].Elevation);
        }
        public void GPXXmlDataReaderCanReadPointsDescription()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.WaypointRead += new GPXWaypointReadHandler(ProcessWaypoint);

            // <wpt lat="50.4522196" lon="16.1117968">
            //   <desc>DESCRIPTION</desc>
            // </wpt>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_waypoint_with_desc));

            Assert.Equal(1, _waypoints.Count);

            Assert.Equal(50.4522196, _waypoints[0].Latitude);
            Assert.Equal(16.1117968, _waypoints[0].Longitude);
            Assert.Equal("DESCRIPTION", _waypoints[0].Description);
        }
        public void GPXXmlDataReaderCanReadPointsComment()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.WaypointRead += new GPXWaypointReadHandler(ProcessWaypoint);

            // <wpt lat="50.4522196" lon="16.1117968">
            //   <cmt>COMMENT</cmt>
            // </wpt>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_waypoint_with_comment));

            Assert.Equal(1, _waypoints.Count);

            Assert.Equal(50.4522196, _waypoints[0].Latitude);
            Assert.Equal(16.1117968, _waypoints[0].Longitude);
            Assert.Equal("COMMENT", _waypoints[0].Commenet);
        }
        public void GPXXmlDataReaderCanReadSimpleWaypoint()
        {
            Clear();
            GPXXmlDataReader target = new GPXXmlDataReader();
            target.WaypointRead += new GPXWaypointReadHandler(ProcessWaypoint);

            //<wpt lat="50.4522196" lon="16.1117968">
            //</wpt>
            //<wpt lat="-50.4551789" lon="-16.1174158" />

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_simple_waypoints));

            Assert.Equal(2, _waypoints.Count);

            Assert.Equal(50.4522196, _waypoints[0].Latitude);
            Assert.Equal(16.1117968, _waypoints[0].Longitude);

            Assert.Equal(-50.4551789, _waypoints[1].Latitude);
            Assert.Equal(-16.1174158, _waypoints[1].Longitude);
        }
        public void GPXXmlDataReaderCanMultipleRoutes()
        {
            Clear();

            GPXXmlDataReader target = new GPXXmlDataReader();
            target.RouteRead += new GPXRouteReadHandler(ProcessRoute);

            //<rte>
            //  <name>TRACK 001</name>
            //  <rtept lat="50.0405788" lon="14.4694233">
            //  </rtept>
            //  <rtept lat="49.9116083" lon="14.7193313">
            //  </rtept>
            //  <rtept lat="49.8448186" lon="14.7991063">
            //  </rtept>
            //</rte>

            //<rte>
            //  <name>TRACK 002</name>
            //  <rtept lat="50.0405788" lon="14.4694233">
            //  </rtept>
            //  <rtept lat="49.9116083" lon="14.7193313">
            //  </rtept>
            //</rte>

            target.Read(new MemoryStream(GPXUtils.Tests.TestData.gpx_multiple_routes));

            Assert.Equal(2, _routes.Count);

            Assert.Equal("TRACK 001", _routes[0].Name);
            Assert.Equal(3, _routes[0].NodesCount);

            Assert.Equal("TRACK 002", _routes[1].Name);
            Assert.Equal(2, _routes[1].NodesCount);
        }
Example #18
0
        /// <summary>
        /// Loads a GPX document from the input stream
        /// </summary>
        /// <param name="input">Stream with the GPX file</param>
        public void Load(Stream input)
        {
            GPXXmlDataReader reader = new GPXXmlDataReader();
            reader.WaypointRead += new GPXWaypointReadHandler(waypoint => _waypoins.Add(waypoint));
            reader.RouteRead +=new GPXRouteReadHandler(route => _routes.Add(route));
            reader.TrackRead +=new GPXTrackReadHandler(track => _tracks.Add(track));

            reader.Read(input);
        }