Пример #1
0
        private TracksOptimiserOptions GetTrackOptions()
        {
            TracksOptimiserOptions options = new TracksOptimiserOptions();

            options.TrackColor                  = btnTrackColor.ForeColor;
            options.TrackWidth                  = (int)numTrackWidth.Value;
            options.TracksStyles                = (TracksStyles)cmbPlotStyle.SelectedIndex;
            options.BackgroundColor             = btnTrackBakground.BackColor;
            options.BackgroundColor2            = btnTrackBakground2.BackColor;
            options.TrackBackgroundWidth        = Convert.ToDouble(numBakgroundWidth.Value);
            options.TrackBackground2Width       = Convert.ToDouble(numBakground2Width.Value);
            options.DisconnectGapPoints         = chkDisconnectGapPoints.Checked;
            options.DisconnectTrackGapsMultiple = Convert.ToDouble(numDisconnectTrackGaps.Value);

            return(options);
        }
Пример #2
0
        public void Run(GMapControl gMap, List <Geo.Gps.Track> tracks, TracksOptimiserOptions options)
        {
            if (tracks == null)
            {
                return;
            }
            this.gMap    = gMap;
            this.options = options;

            int minPixels = 10;

            switch (options.TracksStyles)
            {
            case TracksStyles.Simple: minPixels = 3; break;

            case TracksStyles.With_background: minPixels = 7; break;

            default: break;
            }

            double      minimimDistance = minPixels /* at least 3 pixels */ * gMap.ViewArea.WidthLng / gMap.Size.Width;
            int         oldCount = 0, newCount = 0;
            GMapOverlay tracksPolygonsOverlay  = FindOverlay(Constants.TracksPolygonsId, gMap);
            GMapOverlay tracksPolygons2Overlay = FindOverlay(Constants.TracksPolygons2Id, gMap);
            GMapOverlay tracksPolygons3Overlay = FindOverlay(Constants.TracksPolygons3Id, gMap);

            if (tracksPolygonsOverlay == null)
            {
                tracksPolygonsOverlay  = new GMapOverlay(Constants.TracksPolygonsId);
                tracksPolygons2Overlay = new GMapOverlay(Constants.TracksPolygons2Id);
                tracksPolygons3Overlay = new GMapOverlay(Constants.TracksPolygons3Id);

                gMap.Overlays.Add(tracksPolygons3Overlay);
                gMap.Overlays.Add(tracksPolygons2Overlay);
                gMap.Overlays.Add(tracksPolygonsOverlay);
            }

            tracksPolygonsOverlay.Routes.Clear();
            tracksPolygons2Overlay.Routes.Clear();
            tracksPolygons3Overlay.Routes.Clear();

            foreach (var track in tracks)
            {
                Geo.Gps.Fix lastPoint = track.GetFirstFix();
                string      tagName   = lastPoint.TimeUtc.ToShortDateString() + " " + lastPoint.TimeUtc.ToShortTimeString();
                if (track.Metadata.ContainsKey("name"))
                {
                    tagName += "; " + track.Metadata["name"].ToString();
                }
                if (track.Metadata.ContainsKey("filename"))
                {
                    tagName += "; " + track.Metadata["filename"].ToString();
                }

                // add route for each segment, segments may be separate
                foreach (var segment in track.Segments)
                {
                    List <PointLatLng> mapPoints = new List <PointLatLng>();
                    lastPoint = segment.GetFirstFix();
                    mapPoints.Add(new PointLatLng(lastPoint.Coordinate.Latitude, lastPoint.Coordinate.Longitude));

                    foreach (var point in segment.Fixes)
                    {
                        if (AddPoint(mapPoints, lastPoint, point, minimimDistance, tagName))
                        {
                            lastPoint = point;
                            newCount++;
                        }

                        oldCount++;
                    }

                    // always add last point, single gpx file may be divided by tracks
                    if (segment.GetLastFix() != lastPoint)
                    {
                        Geo.Gps.Fix newPoint = segment.GetLastFix();
                        mapPoints.Add(new PointLatLng(newPoint.Coordinate.Latitude, newPoint.Coordinate.Longitude));
                    }

                    if (mapPoints.Count > 1)
                    {
                        AddRoute(mapPoints, tagName);
                    }
                }
            }

            double ratio = (double)newCount / oldCount * 100;

            Info = "Map points: " + newCount + " (" + ratio.ToString("F0") + "%)";

            gMap.Refresh();
        }