Beispiel #1
0
        public Track(Gpx.GpxTrack oldtrk) : this()
        {
            Comment = oldtrk.Comment;
            Description = oldtrk.Description;
            Name = oldtrk.Name;
            number = oldtrk.Number.ToString();
            srcField = oldtrk.Source;

            foreach (Gpx.GpxTrackSegment oldseg in oldtrk.Segments)
            {
                TrackSegment seg = new TrackSegment();
                foreach (Gpx.GpxPoint pt in oldseg.TrackPoints)
                {
                    seg.WayPoints.Add(new WayPoint(pt));
                }
                TrackSegments.Add(seg);
            }
        }
Beispiel #2
0
        public static Track FromRoute(Route route)
        {
            Track retVal = new Track();
            retVal.Classification = route.Classification;
            retVal.Comment = route.Comment;
            retVal.Description = route.Description;
            retVal.Link = route.Link;
            retVal.Name = route.Name;
            retVal.number = route.Number;
            retVal.Source = route.src;

            retVal.TrackSegments = new List<TrackSegment>();
            TrackSegment segment = new TrackSegment();
            segment.WayPoints = new List<WayPoint>();
            foreach (WayPoint wp in route.rtept)
            {
                segment.WayPoints.Add(wp);
            }
            retVal.TrackSegments.Add(segment);
            return retVal;
        }
Beispiel #3
0
        public TrackSegment Compress(double neighbourDistance, double lineDistance, double angle)
        {
            TrackSegment retVal = new TrackSegment(true);
            TrackSegment original = this;

            double neighbourDistanceSquare = neighbourDistance * neighbourDistance;
            double lineDistanceSquare = lineDistance * lineDistance;
            double angleRad = angle * Math.PI / 180.0;
            double angleSine = Math.Sin(angleRad);
            double angleSineSquare = angleSine * angleSine;

            int numRemoved = 0;
            do
            {
                numRemoved = 0;
                bool previousDeleted = false;
                foreach (WayPoint wp in original.WayPoints)
                {
                    WayPoint previous = wp.PreviousWaypoint;
                    if (previousDeleted)
                    {
                        previousDeleted = false;
                        //skip this point and 
                        //add it to the new track segment
                        WayPoint copy = wp.Copy();
                        retVal.WayPoints.Add(copy);
                        continue; 
                    }
                    if (CanDelete(wp, previous, neighbourDistanceSquare, lineDistanceSquare, angleSineSquare))
                    {
                        previousDeleted = true;
                        numRemoved++;
                    }
                    else
                    {
                        previousDeleted = false;
                        //add to the new track segment
                        WayPoint copy = wp.Copy();
                        retVal.WayPoints.Add(copy);
                    }
                }
                if (numRemoved > 0)
                {
                    original = retVal;
                    original.Recalculate();
                    retVal = new TrackSegment(true);
                }
            }
            while (numRemoved > 0);
            return retVal;
        }