Ejemplo n.º 1
0
        public void GPXDocumentSaveWritesDataToStream()
        {
            GPXDocument target = new GPXDocument();
            target.Load(new MemoryStream(TestData.gpx_real));

            MemoryStream writtenDocument = new MemoryStream();
            target.Save(writtenDocument);

            writtenDocument.Seek(0, 0);
            GPXDocument loadedDocument = new GPXDocument();
            loadedDocument.Load(writtenDocument);

            Assert.Equal(3, loadedDocument.Waypoints.Count);

            Assert.Equal(2, loadedDocument.Routes.Count);
            Assert.Equal(3, loadedDocument.Routes[0].NodesCount);
            Assert.Equal(1, loadedDocument.Routes[1].NodesCount);

            Assert.Equal(2, loadedDocument.Tracks.Count);

            Assert.Equal(1, loadedDocument.Tracks[0].Segments.Count);
            Assert.Equal(2, loadedDocument.Tracks[0].Segments[0].NodesCount);

            Assert.Equal(2, loadedDocument.Tracks[1].Segments.Count);
            Assert.Equal(998, loadedDocument.Tracks[1].Segments[0].NodesCount);
            Assert.Equal(10, loadedDocument.Tracks[1].Segments[1].NodesCount);
        }
Ejemplo n.º 2
0
        public void GPXDocumentConstructorInitializesCollections()
        {
            GPXDocument target = new GPXDocument();

            Assert.NotNull(target.Waypoints);
            Assert.NotNull(target.Routes);
            Assert.NotNull(target.Tracks);
        }
Ejemplo n.º 3
0
        public void GPXDocumentLoadReadsDataFromStream()
        {
            GPXDocument target = new GPXDocument();
            target.Load(new MemoryStream(TestData.gpx_real));

            Assert.Equal(3, target.Waypoints.Count);

            Assert.Equal(2, target.Routes.Count);
            Assert.Equal(3, target.Routes[0].NodesCount);
            Assert.Equal(1, target.Routes[1].NodesCount);

            Assert.Equal(2, target.Tracks.Count);

            Assert.Equal(1, target.Tracks[0].Segments.Count);
            Assert.Equal(2, target.Tracks[0].Segments[0].NodesCount);

            Assert.Equal(2, target.Tracks[1].Segments.Count);
            Assert.Equal(998, target.Tracks[1].Segments[0].NodesCount);
            Assert.Equal(10, target.Tracks[1].Segments[1].NodesCount);
        }
Ejemplo n.º 4
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);
                    }
                }
            }
        }