Exemplo n.º 1
0
        static List <GPXTrack> getAllGpxTrackList(string file)
        {
            GPXDocument            gpx          = new GPXDocument();
            List <GPXTrack>        gpxTrackList = new List <GPXTrack>();
            List <GPXTrackSegment> gpxTrackSegList;

            gpx.Load(file);

            foreach (var trk in gpx.Tracks)
            {
                gpxTrackSegList = new List <GPXTrackSegment>();

                // Sanatizing the data, some segments have zero nodes.
                foreach (var seg in trk.Segments)
                {
                    if (seg.Nodes.Count != 0)
                    {
                        gpxTrackSegList.Add(seg);
                    }
                }

                // Clearing the olds
                trk.Segments.Clear();
                // Assigning the new ones.
                trk.Segments.AddRange(gpxTrackSegList);

                if (trk.Segments.Count != 0)
                {
                    gpxTrackList.Add(trk);
                }
            }

            return(gpxTrackList);
        }
Exemplo n.º 2
0
        static void ProcessGPXFile(string path, STMatching processor, PathReconstructer reconstructor, string outputPath, int samplingPeriod, bool filterOutput)
        {
            GPXUtils.Filters.FrequencyFilter filter = new GPXUtils.Filters.FrequencyFilter();

            Console.Write("Loading {0} ...", Path.GetFileName(path));
            GPXDocument gpx = new GPXDocument();

            gpx.Load(path);

            Console.WriteLine("[{0} track(s); {1} segment(s)]", gpx.Tracks.Count, gpx.Tracks.Sum(track => track.Segments.Count));
            for (int trackIndex = 0; trackIndex < gpx.Tracks.Count; trackIndex++)
            {
                for (int segmentIndex = 0; segmentIndex < gpx.Tracks[trackIndex].Segments.Count; segmentIndex++)
                {
                    string name = string.IsNullOrEmpty(gpx.Tracks[trackIndex].Name) ? "t" + trackIndex.ToString() : gpx.Tracks[trackIndex].Name.Replace('\\', '-').Replace(":", "");
                    name += "_s" + segmentIndex.ToString();
                    Console.Write("\t" + name + " ");

                    try {
                        GPXTrackSegment toProcess = gpx.Tracks[trackIndex].Segments[segmentIndex];
                        if (samplingPeriod > 0)
                        {
                            toProcess = filter.Filter(new TimeSpan(0, 0, samplingPeriod), toProcess);
                        }

                        var result = processor.Match(toProcess);
                        Console.Write(".");

                        var reconstructedPath = reconstructor.Reconstruct(result);
                        Console.Write(".");

                        if (filterOutput)
                        {
                            reconstructor.FilterUturns(reconstructedPath, 100);
                        }
                        var pathOsm = reconstructor.SaveToOSM(reconstructedPath);

                        pathOsm.Save(Path.Combine(outputPath, Path.GetFileNameWithoutExtension(path) + "_" + name + ".osm"));
                        Console.WriteLine(".");
                    }
                    catch (Exception e) {
                        Console.WriteLine("Error: " + e.Message);
                    }
                }
            }
        }
Exemplo n.º 3
0
        static void ProcessGPXFile(string path, List <Double> tlist, int samplingPeriod, bool filterOutput)
        {
            LK.GPXUtils.Filters.FrequencyFilter filter = new LK.GPXUtils.Filters.FrequencyFilter();

            Console.Write("Loading {0} ...", Path.GetFileName(path));
            GPXDocument gpx = new GPXDocument();

            gpx.Load(path);

            Console.WriteLine("[{0} track(s); {1} segment(s)]", gpx.Tracks.Count, gpx.Tracks.Sum(track => track.Segments.Count));
            for (int trackIndex = 0; trackIndex < gpx.Tracks.Count; trackIndex++)
            {
                for (int segmentIndex = 0; segmentIndex < gpx.Tracks[trackIndex].Segments.Count; segmentIndex++)
                {
                    string name = string.IsNullOrEmpty(gpx.Tracks[trackIndex].Name) ? "t" + trackIndex.ToString() : gpx.Tracks[trackIndex].Name.Replace('\\', '-').Replace(":", "");
                    name += "_s" + segmentIndex.ToString();
                    //Console.Write("\t" + name + " ");

                    try
                    {
                        GPXTrackSegment toProcess = gpx.Tracks[trackIndex].Segments[segmentIndex];
                        if (samplingPeriod > 0)
                        {
                            toProcess = filter.Filter(new TimeSpan(0, 0, samplingPeriod), toProcess);
                        }


                        foreach (var t in toProcess.Nodes)
                        {
                            tlist.Add(Utils.Time2Double(t.Time));
                        }
                        //Console.WriteLine(".");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error: " + e.Message);
                    }
                }
            }
        }
Exemplo n.º 4
0
        static void ProcessGPXFile(string path, TMM processor, PathReconstructer reconstructor, string outputPath, int samplingPeriod,
                                   bool filterOutput, List <Bucket> buckets)
        {
            GPXUtils.Filters.FrequencyFilter filter = new GPXUtils.Filters.FrequencyFilter();

            Console.Write("Loading {0} ...", Path.GetFileName(path));
            GPXDocument gpx = new GPXDocument();

            gpx.Load(path);

            Console.WriteLine("[{0} track(s); {1} segment(s)]", gpx.Tracks.Count, gpx.Tracks.Sum(track => track.Segments.Count));
            for (int trackIndex = 0; trackIndex < gpx.Tracks.Count; trackIndex++)
            {
                Console.WriteLine(gpx.Tracks[trackIndex].Name);

                for (int segmentIndex = 0; segmentIndex < gpx.Tracks[trackIndex].Segments.Count; segmentIndex++)
                {
                    string name = string.IsNullOrEmpty(gpx.Tracks[trackIndex].Name) ? "t" + trackIndex.ToString() : gpx.Tracks[trackIndex].Name.Replace('\\', '-').Replace(":", "");
                    name += "_s" + segmentIndex.ToString();
                    Console.Write("\t" + name + " ");

                    try
                    {
                        GPXTrackSegment toProcess = gpx.Tracks[trackIndex].Segments[segmentIndex];

                        if (samplingPeriod > 0)
                        {
                            toProcess = filter.Filter(new TimeSpan(0, 0, samplingPeriod), toProcess);
                        }

                        if (toProcess.NodesCount > 1)
                        {
                            var result = processor.Match(toProcess);
                            Console.Write(".");

                            var reconstructedPath = reconstructor.Reconstruct(result);

                            Console.Write(".");

                            if (filterOutput)
                            {
                                reconstructor.FilterUturns(reconstructedPath, 100);
                            }

                            Console.WriteLine(".");

                            var trackId = gpx.Tracks[trackIndex].Name.Replace("trk_", "");
                            buckets = GetUpdatedBuckets(toProcess, reconstructedPath, buckets, trackId);
                        }
                        else
                        {
                            throw new Exception(string.Format("Track segment discarded because number of nodes is less than 2."));
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error: " + e.Message);
                    }
                }
            }
        }