Beispiel #1
0
        public string GetInfo()
        {
            StringBuilder text = new StringBuilder();

            text.AppendLine(minTrackDate.ToShortDateString() + " - " + maxTrackDate.ToShortDateString());
            text.AppendLine("Tracks: " + this.Tracks.Count);
            text.AppendLine("Distance: " + (this.TotalDistance / 1000).ToString("F2") + "km");

            text.Append("Time: ");
            if (TotalTime.Days > 0)
            {
                text.Append(TotalTime.Days + "d ");
            }
            if (TotalTime.Hours > 0)
            {
                text.Append(TotalTime.Hours + "h ");
            }
            if (TotalTime.Minutes > 0)
            {
                text.Append(TotalTime.Minutes + "m ");
            }
            text.AppendLine();

            Geo.Measure.Speed speed = new Geo.Measure.Speed(this.avgSpeedSum / this.avgSpeedCount);
            text.AppendLine("Avg. speed: " + speed.ConvertTo(Geo.Measure.SpeedUnit.Kph).Value.ToString("F2") + "km/h");

            return(text.ToString());
        }
Beispiel #2
0
        private void LoadFiles(object sender, DoWorkEventArgs e)
        {
            int count = 0;

            this.TotalDistance = 0;

            foreach (string path in this.filenames)
            {
                if (chkFilenameMustContain.Checked && !(new FileInfo(path).Name.Contains(txtMustContain.Text)))
                {
                    continue;
                }

                List <Geo.Gps.Track> tracks = null;

                var gpx10 = new Gpx10Serializer();
                var gpx11 = new Gpx11Serializer();
                using (var stream = new FileStream(path, FileMode.Open))
                {
                    var streamWrapper = new StreamWrapper(stream);
                    if (gpx10.CanDeSerialize(streamWrapper))
                    {
                        var data = gpx10.DeSerialize(streamWrapper);
                        tracks = data.Tracks;
                    }
                    else if (gpx11.CanDeSerialize(streamWrapper))
                    {
                        var data = gpx11.DeSerialize(streamWrapper);
                        tracks = data.Tracks;
                    }
                }

                foreach (var track in tracks)
                {
                    if (chkAvgSpeedBetween.Checked)
                    {
                        Geo.Measure.Speed speed = track.GetAverageSpeed().ConvertTo(Geo.Measure.SpeedUnit.Kph);
                        if (speed.Value < Convert.ToDouble(numSpeedFrom.Value) || speed.Value > Convert.ToDouble(numSpeedTo.Value))
                        {
                            continue;
                        }
                    }

                    bool isAnyPointOnMap = false;

                    if (chkLoadForVisibleMap.Checked)
                    {
                        foreach (var segment in track.Segments)
                        {
                            for (int idx = segment.Fixes.Count - 1; idx >= 0; idx--)
                            {
                                if (segment.Fixes[idx].Coordinate.Latitude >= ViewArea.Bottom && segment.Fixes[idx].Coordinate.Latitude <= ViewArea.Top &&
                                    segment.Fixes[idx].Coordinate.Longitude >= ViewArea.Left && segment.Fixes[idx].Coordinate.Longitude <= ViewArea.Right)
                                {
                                    isAnyPointOnMap = true;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        isAnyPointOnMap = true;
                    }

                    bool betweenAnyDates = false;
                    if (chkDatesBetween.Checked)
                    {
                        foreach (var segment in track.Segments)
                        {
                            for (int idx = segment.Fixes.Count - 1; idx >= 0; idx--)
                            {
                                if (segment.Fixes[idx].TimeUtc.Date >= dtFrom.Value && segment.Fixes[idx].TimeUtc.Date <= dtTo.Value)
                                {
                                    betweenAnyDates = true;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        betweenAnyDates = true;
                    }

                    if (isAnyPointOnMap && betweenAnyDates)
                    {
                        Geo.Gps.Fix firstPoint = track.GetFirstFix();
                        if (firstPoint.TimeUtc < minTrackDate)
                        {
                            minTrackDate = firstPoint.TimeUtc;
                        }
                        if (firstPoint.TimeUtc > maxTrackDate)
                        {
                            maxTrackDate = firstPoint.TimeUtc;
                        }

                        this.TotalDistance += track.GetLength().Value;
                        this.TotalTime     += track.GetDuration();

                        Geo.Measure.Speed speed = track.GetAverageSpeed();
                        this.avgSpeedSum += speed.SiValue;
                        this.avgSpeedCount++;

                        track.Metadata.Add("filename", new FileInfo(path).Name);
                        this.Tracks.Add(track);
                    }
                }

                count++;
                ((BackgroundWorker)sender).ReportProgress((int)((double)count / (double)this.filenames.Length * 100f));
            }

            ((BackgroundWorker)sender).ReportProgress(100);
        }