Ejemplo n.º 1
0
        /// <summary>
        /// 获取一组点经过滤波后的速度
        /// </summary>
        /// <param name="points">点的集合</param>
        /// <param name="sampleCount">每一组采样点的个数</param>
        /// <param name="jump">每一次循环跳跃的个数。比如设置5,采样10,那么第一轮1-10,第二轮6-15</param>
        /// <returns></returns>
        public static IEnumerable <SpeedInfo> GetMeanFilteredSpeeds(GpxPointCollection points, int sampleCount, int jump, double min = double.MinValue, double max = double.MaxValue)
        {
            var sortedPoints = points.TimeOrderedPoints;

            if (sampleCount > sortedPoints.Count)
            {
                return(new SpeedInfo[] { new SpeedInfo(sortedPoints) });
            }
            GpxPoint      last      = null;
            List <double> distances = new List <double>();

            foreach (var point in points)
            {
                if (last != null)
                {
                    distances.Add(Calculate.Distance(last, point));
                }
                last = point;
            }
            List <SpeedInfo> speedList = new List <SpeedInfo>();

            for (int i = sampleCount - 1; i < sortedPoints.Count; i += jump)
            {
                DateTime minTime       = sortedPoints[i - sampleCount + 1].Time;
                DateTime maxTime       = sortedPoints[i].Time;
                double   totalDistance = 0;
                for (int j = i - sampleCount + 1; j < i; j++)
                {
                    totalDistance += distances[j];
                }
                double speed = totalDistance / (maxTime - minTime).TotalSeconds;
                if (speed < min)
                {
                    continue;
                }
                if (speed > max)
                {
                    continue;
                }
                speedList.Add(new SpeedInfo(minTime, maxTime, speed));
            }
            return(speedList);
        }
Ejemplo n.º 2
0
        public static IEnumerable <SpeedInfo> GetSpeeds(GpxPointCollection points, int sampleCount = 2)
        {
            Queue <GpxPoint> previousPoints = new Queue <GpxPoint>();

            foreach (var point in points.TimeOrderedPoints)
            {
                if (previousPoints.Count < sampleCount - 1)
                {
                    previousPoints.Enqueue(point);
                }
                else
                {
                    previousPoints.Enqueue(point);
                    yield return(new SpeedInfo(previousPoints));

                    previousPoints.Dequeue();
                }
            }
        }
        /// <summary>
        /// Parses a stream of a gpx file and returns a list of all gpx points in the track(s).
        /// </summary>
        /// <param name="stream">stream of a gpx file</param>
        /// <returns>list of all gpx points in the track(s)</returns>
        public static GpxPointCollection <GpxPoint> parseGpx(Stream stream)
        {
            GpxPointCollection <GpxPoint> pointList = new GpxPointCollection <GpxPoint>();

            using (GpxReader gpxReader = new GpxReader(stream))
            {
                while (gpxReader.Read())
                {
                    // track found
                    if (gpxReader.ObjectType == GpxObjectType.Track)
                    {
                        // add points of the track
                        GpxPointCollection <GpxPoint> pointsToAdd = gpxReader.Track.ToGpxPoints();
                        foreach (GpxPoint point in pointsToAdd)
                        {
                            pointList.AddPoint(point);
                        }
                    }
                }
            }
            return(pointList);
        }
Ejemplo n.º 4
0
        private void LoadGpx(string fileName)
        {
            if (string.IsNullOrEmpty(textBoxGpxFile.Text) || !File.Exists(textBoxGpxFile.Text))
            {
                return;
            }

            FileStream fs = null;

            try
            {
                fs = new FileStream(fileName, FileMode.Open);
                using (GpxReader gpxReader = new GpxReader(fs))
                {
                    while (gpxReader.Read())
                    {
                        switch (gpxReader.ObjectType)
                        {
                        case GpxObjectType.Track:
                            gpxPoints = gpxReader.Track.ToGpxPoints();
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Ejemplo n.º 5
0
        public static void trackGPXfile_API_2(GpxFile file, List <GMapRoute> polylineList_2, GMapControl mapControl_2)
        {
            if (file.reader.Track.Segments != null)
            {
                IList <GpxTrackSegment> segmentList = new List <GpxTrackSegment>();
                segmentList = file.reader.Track.Segments;

                foreach (GpxTrackSegment segment in segmentList)
                {
                    GpxPointCollection <GpxTrackPoint> trackPointsList = new GpxPointCollection <GpxTrackPoint>();
                    foreach (GpxTrackPoint point in segment.TrackPoints)
                    {
                        trackPointsList.AddPoint(point);
                    }

                    List <PointLatLng> lokalizacjeLista = new List <PointLatLng>();
                    foreach (GpxTrackPoint point in trackPointsList)
                    {
                        lokalizacjeLista.Add(new PointLatLng(point.Latitude, point.Longitude));
                    }
                    drawTraceAndRouteOnMap_API_2(lokalizacjeLista, polylineList_2, file, mapControl_2);
                }
            }
        }
Ejemplo n.º 6
0
        public static void trackGPXfile_API_1(GpxFile file, List <MapPolyline> polylineList_1, Map mapControl_1)
        {
            if (file.reader.Track.Segments != null)
            {
                IList <GpxTrackSegment> segmentList = new List <GpxTrackSegment>();
                segmentList = file.reader.Track.Segments;

                foreach (GpxTrackSegment segment in segmentList)
                {
                    GpxPointCollection <GpxTrackPoint> trackPointsList = new GpxPointCollection <GpxTrackPoint>();
                    foreach (GpxTrackPoint point in segment.TrackPoints)
                    {
                        trackPointsList.AddPoint(point);
                    }

                    LocationCollection lokalizacjeLista = new LocationCollection();
                    foreach (GpxTrackPoint point in trackPointsList)
                    {
                        lokalizacjeLista.Add(new Location(point.Latitude, point.Longitude));
                    }
                    drawTraceAndRouteOnMap_API_1(lokalizacjeLista, polylineList_1, file, mapControl_1);
                }
            }
        }
Ejemplo n.º 7
0
        public static IEnumerable <SpeedInfo> GetMedianFilteredSpeeds(GpxPointCollection points,
                                                                      int sampleCount, int jump, TimeSpan?maxTimeSpan = null,
                                                                      double min = double.MinValue, double max = double.MaxValue
                                                                      )
        {
            var filterResult = Filter.MedianValueFilter(GetSpeeds(points), p => p.Speed, sampleCount, jump);

            //List<SpeedInfo> speeds = new List<SpeedInfo>();
            foreach (var item in filterResult)
            {
                if (item.SelectedItem.Speed > max || item.SelectedItem.Speed < min)
                {
                    continue;
                }
                var maxTime = item.ReferenceItems.First().CenterTime;
                var minTime = item.ReferenceItems.Last().CenterTime;
                if (maxTimeSpan.HasValue && maxTime - minTime > maxTimeSpan)
                {
                    continue;
                }
                SpeedInfo speed = new SpeedInfo(minTime, maxTime, item.SelectedItem.Speed);
                yield return(speed);
            }

            //var sortedPoints = points.TimeOrderedPoints;
            //if (sampleCount > sortedPoints.Count)
            //{
            //    return new SpeedInfo[] { new SpeedInfo(sortedPoints) };
            //}
            //GpxPoint last = null;
            //List<double> distances = new List<double>();
            //foreach (var point in points)
            //{
            //    if (last != null)
            //    {
            //        distances.Add(Calculate.Distance(last, point));
            //    }
            //    last = point;
            //}
            //List<SpeedInfo> speedList = new List<SpeedInfo>();
            //for (int i = sampleCount - 1; i < sortedPoints.Count; i+=jump)
            //{
            //    DateTime minTime = sortedPoints[i - sampleCount + 1].Time;
            //    DateTime maxTime = sortedPoints[i].Time;
            //    double totalDistance = 0;
            //    for (int j = i - sampleCount + 1; j < i; j++)
            //    {
            //        totalDistance += distances[j];
            //    }
            //    double speed = totalDistance / (maxTime - minTime).TotalSeconds;
            //    if(speed<min)
            //    {
            //        continue;
            //    }
            //    if(speed>max)
            //    {
            //        continue;
            //    }
            //    speedList.Add(new SpeedInfo(minTime, maxTime, speed));

            //}
            //return speedList;
        }