예제 #1
0
        public void OSMDatabaseLoadCanLoadDataFromOSMFile()
        {
            OSMDB target = new OSMDB();
            target.Load(new MemoryStream(OSMUtils.Tests.TestData.real_osm_file));

            Assert.Equal(408, target.Nodes.Count);
            Assert.Equal(22, target.Ways.Count);
            Assert.Equal(2, target.Relations.Count);
        }
예제 #2
0
        public void FromMatchedTrackFindsStartAndEndTimesForSegmentsThatStartAndEndsOnCrossroads()
        {
            OSMDB track = new OSMDB();
            track.Load(new MemoryStream(TestData.osm_2_segments_without_incolmpete_parts));

            var target = TravelTime.FromMatchedTrack(track).ToList();

            Assert.Equal(2, target.Count());
            Assert.Equal(new DateTime(2010, 5, 21, 16, 48, 10), target[0].TimeStart);
            Assert.Equal(new DateTime(2010, 5, 21, 16, 48, 15), target[0].TimeEnd);

            Assert.Equal(new DateTime(2010, 5, 21, 16, 48, 15), target[1].TimeStart);
            Assert.Equal(new DateTime(2010, 5, 21, 16, 49, 19), target[1].TimeEnd);
        }
예제 #3
0
        public void FromMatchedTrackIgnoresFirstAndLastIncompleteSegments()
        {
            OSMDB track = new OSMDB();
            track.Load(new MemoryStream(TestData.osm_2_complete_segments));

            var target = TravelTime.FromMatchedTrack(track).ToList();

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

            SegmentInfo expectedFirstSegment = new SegmentInfo() { NodeFromID = 411888806, NodeToID = 415814332, WayID = 36881783 };
            SegmentInfo expectedSecondSegment = new SegmentInfo() { NodeFromID = 415814332, NodeToID = 74165639, WayID = 36881783 };

            Assert.Equal(expectedFirstSegment, target[0].Segment);
            Assert.Equal(expectedSecondSegment, target[1].Segment);
        }
예제 #4
0
        public void AnalyzeDetectsStopAtTrafficSignals()
        {
            OSMDB track = new OSMDB();
            track.Load(new MemoryStream(TestData.osm_real_traffic_signals));

            var travelTimeAtSignals = TravelTime.FromMatchedTrack(track).First();

            OSMDB map = new OSMDB();
            map.Load(new MemoryStream(TestData.osm_traffic_signals_map));

            TTAnalyzer analyzer = new TTAnalyzer(map);
            Model target = analyzer.Analyze(new TravelTime[] { travelTimeAtSignals }, travelTimeAtSignals.Segment);

            Assert.Equal(30, target.TrafficSignalsDelay.Length);
            Assert.Equal(1.0, target.TrafficSignalsDelay.Probability);
        }
예제 #5
0
        public void OSMDatabaseSaveCanSaveDataToOSMFile()
        {
            OSMDB target = new OSMDB();

            target.Load(new MemoryStream(OSMUtils.Tests.TestData.real_osm_file));

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

            writtenDb.Seek(0, 0);
            OSMDB readDB = new OSMDB();
            readDB.Load(writtenDb);

            Assert.Equal(408, readDB.Nodes.Count);
            Assert.Equal(22, readDB.Ways.Count);
            Assert.Equal(2, readDB.Relations.Count);
        }
예제 #6
0
        static void AddTrackToDB(ITravelTimesDB db, string path)
        {
            OSMDB track = new OSMDB();

            Console.Write("Loading {0} ...", Path.GetFileName(path));
            track.Load(path);

            try {
                var travelTimes = TravelTime.FromMatchedTrack(track);
                foreach (var travelTime in travelTimes) {
                    db.AddTravelTime(travelTime);
                }

                Console.WriteLine(".");
            }
            catch (Exception e) {
                Console.WriteLine("Error: " + e.Message);
            }
        }
예제 #7
0
        public void FromMatchedTrackProcessesInterpolatesTimeToCrossroads()
        {
            OSMDB track = new OSMDB();
            track.Load(new MemoryStream(TestData.osm_2_complete_segments));

            var target = TravelTime.FromMatchedTrack(track).ToList();

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

            DateTime expectedFirstSegmentStart = new DateTime(2010, 5, 21, 16, 48, 16, 320);
            DateTime expectedFirstSegmentEnd = new DateTime(2010, 5, 21, 16, 48, 19, 220);

            DateTime expectedSecondSegmentStart = expectedFirstSegmentEnd;
            DateTime expectedSecondSegmentEnd = new DateTime(2010, 5, 21, 16, 49, 17, 500);

            Assert.InRange(target[0].TimeStart, expectedFirstSegmentStart.AddMilliseconds(-100), expectedFirstSegmentStart.AddMilliseconds(100));
            Assert.InRange(target[0].TimeEnd, expectedFirstSegmentEnd.AddMilliseconds(-100), expectedFirstSegmentEnd.AddMilliseconds(100));
            Assert.InRange(target[1].TimeStart, expectedSecondSegmentStart.AddMilliseconds(-100), expectedSecondSegmentStart.AddMilliseconds(100));
            Assert.InRange(target[1].TimeEnd, expectedSecondSegmentEnd.AddMilliseconds(-100), expectedSecondSegmentEnd.AddMilliseconds(100));
        }
예제 #8
0
        static void Main(string[] args)
        {
            string osmPath = "";
            string gpxPath = "";
            string outputPath = ".";
            int samplingPeriod = 0;
            bool showHelp = false;
            bool filter = false;

            OptionSet parameters = new OptionSet() {
                { "osm=", "path to the routable map file",																				v => osmPath = v},
                { "gpx=",	"path to the GPX file to process or to the directory to process",				v => gpxPath = v},
                { "o|output=", "path to the output directory",																		v => outputPath = v},
                { "p|period=", "sampling period of the GPX file",																	v => samplingPeriod = int.Parse(v)},
                { "f|filter", "enables output post processing",																		v => filter = v != null},
                { "h|?|help",																																			v => showHelp = v != null},
            };

            try {
                parameters.Parse(args);
            }
            catch (OptionException e) {
                Console.Write("MatchGPX2OSM: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `matchgpx2osm --help' for more information.");
                return;
            }

            if (showHelp || string.IsNullOrEmpty(osmPath) || string.IsNullOrEmpty(gpxPath) || string.IsNullOrEmpty(outputPath)) {
                ShowHelp(parameters);
                return;
            }

            Console.Write("Loading OSM file ...");
            OSMDB map = new OSMDB();
            map.Load(osmPath);
            Console.WriteLine("\t\t\tDone.");

            Console.Write("Building routable road graph ...");
            RoadGraph graph = new RoadGraph();
            graph.Build(map);
            Console.WriteLine("\tDone.");

            STMatching processor = new STMatching(graph);
            PathReconstructer reconstructor = new PathReconstructer(graph);

            // Process signle file
            if (File.Exists(gpxPath)) {
                ProcessGPXFile(gpxPath, processor, reconstructor, outputPath, samplingPeriod, filter);
            }
            // Process all GPX in directory
            else if (Directory.Exists(gpxPath)) {
                var files = Directory.GetFiles(gpxPath, "*.gpx");
                Console.WriteLine("Found {0} GPX file(s).", files.Length);

                foreach (var file in files) {
                    ProcessGPXFile(file, processor, reconstructor, outputPath, samplingPeriod, filter);
                    Console.WriteLine();
                }
            }
            else {
                Console.WriteLine("No GPX files found");
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            string dbPath = "";
            string mapPath = "";
            string trackPath = "";
            string outputPath = ".";
            bool addTracks = false;
            bool showHelp = false;
            bool analyze = false;

            OptionSet parameters = new OptionSet() {
                { "db=", "path to the travel times database",																									v => dbPath = v},
                { "add", "adds specified tracks to the DB",																										v => addTracks = v != null},
                { "track=",	"path to the matched GPS track to process or to the directory to process",				v => trackPath = v},
                { "map=", "path to the routable map",																													v => mapPath = v},
                { "a|analyze",																																								v => analyze = v != null},
                { "o|output=", "path to the output directory",																								v => outputPath = v},
                { "h|?|help",																																									v => showHelp = v != null},
            };

            try {
                parameters.Parse(args);
            }
            catch (OptionException e) {
                Console.Write("Analyzer: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `analyzer --help' for more information.");
                return;
            }

            if (showHelp || string.IsNullOrEmpty(dbPath) || string.IsNullOrEmpty(outputPath)) {
                ShowHelp(parameters);
                return;
            }

            Console.Write("Loading travel times database ...");
            XmlTravelTimeDB db = new XmlTravelTimeDB();
            if (File.Exists(dbPath)) {
                db.Load(dbPath);
            }
            Console.WriteLine("\t\t\tDone.");

            if (addTracks) {
                if (File.Exists(trackPath)) {
                    AddTrackToDB(db, trackPath);
                }
                else if (Directory.Exists(trackPath)) {
                    var files = Directory.GetFiles(trackPath, "*.osm");
                    Console.WriteLine("Found {0} GPX file(s).", files.Length);

                    foreach (var file in files) {
                        AddTrackToDB(db, file);
                    }
                }

                Console.Write("Saving travel times database ...");
                db.Save(dbPath);
                Console.WriteLine("\t\t\tDone.");
            }

            if (analyze) {
                Console.Write("Loading routable map ...");
                OSMDB map = new OSMDB();
                map.Load(mapPath);

                Console.WriteLine("\t\t\t\tDone.");

                IModelsRepository modelsRepository = new XmlModelsRepository(outputPath);

                TTAnalyzer analyzer = new TTAnalyzer(map);
                foreach (var segment in db.TravelTimesSegments) {
                    Model m = analyzer.Analyze(db.GetTravelTimes(segment), segment);
                    if (m != null) {
                        modelsRepository.AddModel(m);
                    }
                }

                Console.Write("Saving models ...");
                modelsRepository.Commit();
            }
        }
예제 #10
0
        public void FromMatchedTrackProcessesTrackThatStartsAndEndsWithCompleteSegments()
        {
            OSMDB track = new OSMDB();
            track.Load(new MemoryStream(TestData.osm_2_segments_without_incolmpete_parts));

            var target = TravelTime.FromMatchedTrack(track).ToList();

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

            SegmentInfo expectedFirstSegment = new SegmentInfo() { NodeFromID = 411888806, NodeToID = 415814332, WayID = 36881783 };
            SegmentInfo expectedSecondSegment = new SegmentInfo() { NodeFromID = 415814332, NodeToID = 74165639, WayID = 36881783 };

            Assert.Equal(expectedFirstSegment, target[0].Segment);
            Assert.Equal(expectedSecondSegment, target[1].Segment);
        }
예제 #11
0
        public void FromMatchedTrackProcessesTrackWithManySegmentsSegments()
        {
            OSMDB track = new OSMDB();
            track.Load(new MemoryStream(TestData.osm_5_segments));

            var target = TravelTime.FromMatchedTrack(track).ToList();

            Assert.Equal(5, target.Count());

            SegmentInfo expectedFirstSegment = new SegmentInfo() { NodeFromID = 411888806, NodeToID = 415814332, WayID = 36881783 };
            SegmentInfo expectedSecondSegment = new SegmentInfo() { NodeFromID = 415814332, NodeToID = 74165639, WayID = 36881783 };
            SegmentInfo expectedThirdSegment = new SegmentInfo() { NodeFromID = 74165639, NodeToID = 320275336, WayID = 29115419 };
            SegmentInfo expectedFourthSegment = new SegmentInfo() { NodeFromID = 320275336, NodeToID = 415814335, WayID = 29115419 };
            SegmentInfo expectedFifthSegment = new SegmentInfo() { NodeFromID = 415814335, NodeToID = 415814327, WayID = 29115419 };

            Assert.Equal(expectedFirstSegment, target[0].Segment);
            Assert.Equal(expectedSecondSegment, target[1].Segment);
            Assert.Equal(expectedThirdSegment, target[2].Segment);
            Assert.Equal(expectedFourthSegment, target[3].Segment);
            Assert.Equal(expectedFifthSegment, target[4].Segment);
        }