예제 #1
0
        private GpxPoint ReadGarminAutoRoutePoint()
        {
            GpxPoint point = new GpxPoint();

            string elementName    = Reader_.Name;
            bool   isEmptyElement = Reader_.IsEmptyElement;

            GetPointLocation(point);
            if (isEmptyElement)
            {
                return(point);
            }

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                case XmlNodeType.Element:
                    SkipElement();
                    break;

                case XmlNodeType.EndElement:
                    if (Reader_.Name != elementName)
                    {
                        throw new FormatException(Reader_.Name);
                    }
                    return(point);
                }
            }

            throw new FormatException(elementName);
        }
예제 #2
0
        private void WriteSubPoint(GpxPoint point)
        {
            Writer_.WriteStartElement("rpt", GpxNamespaces.GARMIN_EXTENSIONS_NAMESPACE);

            Writer_.WriteAttributeString("lat", point.Latitude.ToString(CultureInfo.InvariantCulture));
            Writer_.WriteAttributeString("lon", point.Longitude.ToString(CultureInfo.InvariantCulture));

            Writer_.WriteEndElement();
        }
예제 #3
0
        private void GetPointLocation(GpxPoint point)
        {
            while (Reader_.MoveToNextAttribute())
            {
                switch (Reader_.Name)
                {
                case "lat":
                    point.Latitude = double.Parse(Reader_.Value, CultureInfo.InvariantCulture.NumberFormat);
                    break;

                case "lon":
                    point.Longitude = double.Parse(Reader_.Value, CultureInfo.InvariantCulture.NumberFormat);
                    break;
                }
            }
        }
예제 #4
0
        public GpxPointCollection <GpxPoint> ToGpxPoints()
        {
            GpxPointCollection <GpxPoint> points = new GpxPointCollection <GpxPoint>();

            foreach (T gpxPoint in Points_)
            {
                GpxPoint point = new GpxPoint
                {
                    Longitude = gpxPoint.Longitude,
                    Latitude  = gpxPoint.Latitude,
                    Elevation = gpxPoint.Elevation,
                    Time      = gpxPoint.Time
                };

                points.Add(point);
            }

            return(points);
        }
예제 #5
0
        public double GetDistanceFrom(GpxPoint other)
        {
            double thisLatitude   = this.Latitude;
            double otherLatitude  = other.Latitude;
            double thisLongitude  = this.Longitude;
            double otherLongitude = other.Longitude;

            double deltaLatitude  = Math.Abs(this.Latitude - other.Latitude);
            double deltaLongitude = Math.Abs(this.Longitude - other.Longitude);

            thisLatitude   *= RADIAN;
            otherLatitude  *= RADIAN;
            deltaLongitude *= RADIAN;

            double cos = Math.Cos(deltaLongitude) * Math.Cos(thisLatitude) * Math.Cos(otherLatitude) +
                         Math.Sin(thisLatitude) * Math.Sin(otherLatitude);

            return(EARTH_RADIUS * Math.Acos(cos));
        }
예제 #6
0
        private bool ProcessPointField(GpxPoint point)
        {
            switch (Reader_.Name)
            {
            case "ele":
                point.Elevation = ReadContentAsDouble();
                return(true);

            case "time":
                point.Time = ReadContentAsDateTime();
                return(true);

            case "magvar":
                point.MagneticVar = ReadContentAsDouble();
                return(true);

            case "geoidheight":
                point.GeoidHeight = ReadContentAsDouble();
                return(true);

            case "name":
                point.Name = ReadContentAsString();
                return(true);

            case "cmt":
                point.Comment = ReadContentAsString();
                return(true);

            case "desc":
                point.Description = ReadContentAsString();
                return(true);

            case "src":
                point.Source = ReadContentAsString();
                return(true);

            case "link":
                point.Links.Add(ReadGpxLink());
                return(true);

            case "sym":
                point.Symbol = ReadContentAsString();
                return(true);

            case "type":
                point.Type = ReadContentAsString();
                return(true);

            case "fix":
                point.FixType = ReadContentAsString();
                return(true);

            case "sat":
                point.Satelites = ReadContentAsInt();
                return(true);

            case "hdop":
                point.Hdop = ReadContentAsDouble();
                return(true);

            case "vdop":
                point.Vdop = ReadContentAsDouble();
                return(true);

            case "pdop":
                point.Pdop = ReadContentAsDouble();
                return(true);

            case "ageofdgpsdata":
                point.AgeOfData = ReadContentAsDouble();
                return(true);

            case "dgpsid":
                point.DgpsId = ReadContentAsInt();
                return(true);
            }

            return(false);
        }
예제 #7
0
        private void WritePoint(GpxPoint point)
        {
            Writer_.WriteAttributeString("lat", point.Latitude.ToString(CultureInfo.InvariantCulture));
            Writer_.WriteAttributeString("lon", point.Longitude.ToString(CultureInfo.InvariantCulture));
            if (point.Elevation != null)
            {
                Writer_.WriteElementString("ele", point.Elevation.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (point.Time != null)
            {
                Writer_.WriteElementString("time", ToGpxDateString(point.Time.Value));
            }
            if (point.MagneticVar != null)
            {
                Writer_.WriteElementString("magvar", point.MagneticVar.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (point.GeoidHeight != null)
            {
                Writer_.WriteElementString("geoidheight", point.GeoidHeight.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (point.Name != null)
            {
                Writer_.WriteElementString("name", point.Name);
            }
            if (point.Comment != null)
            {
                Writer_.WriteElementString("cmt", point.Comment);
            }
            if (point.Description != null)
            {
                Writer_.WriteElementString("desc", point.Description);
            }
            if (point.Source != null)
            {
                Writer_.WriteElementString("src", point.Source);
            }

            foreach (GpxLink link in point.Links)
            {
                WriteLink("link", link);
            }

            if (point.Symbol != null)
            {
                Writer_.WriteElementString("sym", point.Symbol);
            }
            if (point.Type != null)
            {
                Writer_.WriteElementString("type", point.Type);
            }
            if (point.FixType != null)
            {
                Writer_.WriteElementString("fix", point.FixType);
            }
            if (point.Satelites != null)
            {
                Writer_.WriteElementString("sat", point.Satelites.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (point.Hdop != null)
            {
                Writer_.WriteElementString("hdop", point.Hdop.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (point.Vdop != null)
            {
                Writer_.WriteElementString("vdop", point.Vdop.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (point.Pdop != null)
            {
                Writer_.WriteElementString("pdop", point.Pdop.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (point.AgeOfData != null)
            {
                Writer_.WriteElementString("ageofdgpsdata", point.AgeOfData.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (point.DgpsId != null)
            {
                Writer_.WriteElementString("dgpsid", point.DgpsId.Value.ToString(CultureInfo.InvariantCulture));
            }
        }