public void GPXXmlDataWriterWriteRouteWritesRoute()
        {
            MemoryStream ms = new MemoryStream();

            GPXRoute route = new GPXRoute("ROUTE NAME");
            GPXPoint point1 = new GPXPoint(18.5, 50.1);
            GPXPoint point2 = new GPXPoint(10.3, 20.5);

            route.Nodes.Add(point1);
            route.Nodes.Add(point2);

            using (GPXXmlDataWriter target = new GPXXmlDataWriter(ms)) {
                target.WriteRoute(route);
            }

            ms.Seek(0, 0);

            XElement gpxRoot = XDocument.Load(new StreamReader(ms)).Root;
            XElement routeElement = gpxRoot.Element("rte");

            Assert.NotNull(routeElement);

            Assert.Equal(route.Name, routeElement.Element("name").Value);

            var points = routeElement.Elements("rtept").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));
        }
Example #2
0
        public void GPXRouteImplementsIPolyline()
        {
            GPXRoute target = new GPXRoute();

            LK.GeoUtils.Geometry.IPolyline<GPXPoint> castedTarget = target as LK.GeoUtils.Geometry.IPolyline<GPXPoint>;

            Assert.NotNull(castedTarget);
        }
Example #3
0
        /// <summary>
        /// Raises the RouteRead event
        /// </summary>
        /// <param name="node">The route read from the xml</param>
        protected void OnRouteRead(GPXRoute route)
        {
            GPXRouteReadHandler temp = RouteRead;

            if (temp != null)
            {
                temp(route);
            }
        }
Example #4
0
        /// <summary>
        /// Writes the specific route to the output
        /// </summary>
        /// <param name="route">The route to be written</param>
        public void WriteRoute(GPXRoute route)
        {
            _xmlWriter.WriteStartElement("rte");

            if (string.IsNullOrEmpty(route.Name) == false)
            {
                _xmlWriter.WriteElementString("name", route.Name);
            }

            foreach (GPXPoint point in route.Nodes)
            {
                WritePointData(point, "rtept");
            }

            _xmlWriter.WriteEndElement();
        }
Example #5
0
        /// <summary>
        /// Reads route from the gpx
        /// </summary>
        private void ReadRoute()
        {
            GPXRoute parsedRoute = new GPXRoute();

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

                while (_xmlReader.NodeType != XmlNodeType.EndElement)
                {
                    if (_xmlReader.NodeType == XmlNodeType.Element)
                    {
                        switch (_xmlReader.Name)
                        {
                        case "rtept":
                            parsedRoute.Nodes.Add(ReadPoint());
                            break;

                        case "name":
                            parsedRoute.Name = _xmlReader.ReadString();
                            _xmlReader.Skip();
                            break;

                        default:
                            _xmlReader.Skip();
                            break;
                        }
                    }
                    else
                    {
                        _xmlReader.Skip();
                    }
                }
            }

            _xmlReader.Skip();
            OnRouteRead(parsedRoute);
        }
 void ProcessRoute(GPXRoute route)
 {
     _routes.Add(route);
 }
        /// <summary>
        /// Reads route from the gpx
        /// </summary>
        private void ReadRoute()
        {
            GPXRoute parsedRoute = new GPXRoute();

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

                while (_xmlReader.NodeType != XmlNodeType.EndElement) {
                    if (_xmlReader.NodeType == XmlNodeType.Element) {
                        switch (_xmlReader.Name) {
                            case "rtept":
                                parsedRoute.Nodes.Add(ReadPoint());
                                break;
                            case "name":
                                parsedRoute.Name = _xmlReader.ReadString();
                                _xmlReader.Skip();
                                break;
                            default:
                                _xmlReader.Skip();
                                break;
                        }
                    }
                    else {
                        _xmlReader.Skip();
                    }
                }
            }

            _xmlReader.Skip();
            OnRouteRead(parsedRoute);
        }
 /// <summary>
 /// Raises the RouteRead event
 /// </summary>
 /// <param name="node">The route read from the xml</param>
 protected void OnRouteRead(GPXRoute route)
 {
     GPXRouteReadHandler temp = RouteRead;
     if (temp != null) {
         temp(route);
     }
 }
Example #9
0
        public void GPXRouteConstructorCreatesRouteWithName()
        {
            GPXRoute target = new GPXRoute("ROUTE");

            Assert.Equal("ROUTE", target.Name);
        }
        /// <summary>
        /// Writes the specific route to the output
        /// </summary>
        /// <param name="route">The route to be written</param>
        public void WriteRoute(GPXRoute route)
        {
            _xmlWriter.WriteStartElement("rte");

            if (string.IsNullOrEmpty(route.Name) == false) {
                _xmlWriter.WriteElementString("name", route.Name);
            }

            foreach (GPXPoint point in route.Nodes) {
                WritePointData(point, "rtept");
            }

            _xmlWriter.WriteEndElement();
        }
        public void GPXXmlDataWriterWriteRouteWritesRoutePointsWithAllAttributes()
        {
            MemoryStream ms = new MemoryStream();

            GPXRoute route = new GPXRoute();

            GPXPoint point = new GPXPoint(18.5, 50.1);
            point.Elevation = 1600;
            point.Time = new DateTime(2009, 12, 31, 23, 50, 0, DateTimeKind.Utc);
            point.Name = "NAME";
            point.Description = "DESCRIPTION";
            point.Commenet = "COMMENT";

            route.Nodes.Add(point);

            using (GPXXmlDataWriter target = new GPXXmlDataWriter(ms)) {
                target.WriteRoute(route);
            }

            ms.Seek(0, 0);

            XElement gpxRoot = XDocument.Load(new StreamReader(ms)).Root;
            XElement routeElement = gpxRoot.Element("rte");

            Assert.NotNull(routeElement);

            XElement pointElement = routeElement.Element("rtept");

            Assert.NotNull(pointElement);

            Assert.Equal(point.Latitude, double.Parse(pointElement.Attribute("lat").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point.Longitude, double.Parse(pointElement.Attribute("lon").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point.Elevation, double.Parse(pointElement.Element("ele").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point.Time, DateTime.Parse(pointElement.Element("time").Value, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal));
            Assert.Equal(point.Name, pointElement.Element("name").Value);
            Assert.Equal(point.Description, pointElement.Element("desc").Value);
            Assert.Equal(point.Commenet, pointElement.Element("cmt").Value);
        }