Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string osmPath    = "";
            int    eps        = -1;
            int    minTraffic = -1;
            bool   showHelp   = false;

            OptionSet parameters = new OptionSet()
            {
                { "osm=", "path to the map file", v => osmPath = v },
                { "eps=", "size of the eps-neighborhood to be considered (integer)", v => eps = Convert.ToInt32(v) },
                { "minTraffic=", "minimum traffic considered (integer)", v => minTraffic = Convert.ToInt32(v) },
                { "h|?|help", v => showHelp = v != null },
            };

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

            if (showHelp || string.IsNullOrEmpty(osmPath) || eps < 0 || minTraffic < 0)
            {
                ShowHelp(parameters);
                return;
            }

            var osmFile = new OSMDB();

            osmFile.Load(osmPath);
            var roadGraph = new RoadGraph();

            roadGraph.Build(osmFile);

            // Getting all the nodes with traffic signals
            Dictionary <double, OSMNode> tagsNodes = new Dictionary <double, OSMNode>();

            foreach (var node in osmFile.Nodes)
            {
                foreach (var tag in node.Tags)
                {
                    if (tag.Value.Equals("traffic_signals"))
                    {
                        if (!tagsNodes.Keys.Contains(node.Latitude + node.Longitude))
                        {
                            tagsNodes.Add(node.Latitude + node.Longitude, node);
                        }
                    }
                }
            }

            var hotRoutes = new FlowScan().Run(roadGraph, eps, minTraffic);

            // Saving GPX file of the Hot Route
            HashSet <GPXPoint>        listPoints;
            HashSet <GPXTrackSegment> listSegments;
            GPXTrackSegment           segTrack;

            List <GPXTrack> track = new List <GPXTrack>();
            GPXTrack        tr;

            //Console.WriteLine(hotRoutes.Count);
            foreach (var hr in hotRoutes)
            {
                //Console.WriteLine("Number segs: " + hr.Segments.Count);
                listSegments = new HashSet <GPXTrackSegment>();

                foreach (var seg in hr.Segments)
                {
                    listPoints = new HashSet <GPXPoint>();

                    foreach (var segInner in seg.Geometry.Segments)
                    {
                        GPXPoint start;
                        if (tagsNodes.Keys.Contains(segInner.StartPoint.Latitude + segInner.StartPoint.Longitude))
                        {
                            OSMNode osmNode = tagsNodes[segInner.StartPoint.Latitude + segInner.StartPoint.Longitude];
                            start = new GPXPoint()
                            {
                                Id        = osmNode.ID, Latitude = segInner.StartPoint.Latitude,
                                Longitude = segInner.StartPoint.Longitude, TrafficSignal = true
                            };
                        }
                        else
                        {
                            OSMNode osmNode = osmFile.Nodes.ToList().First(x => x.Latitude == segInner.StartPoint.Latitude &&
                                                                           x.Longitude == segInner.StartPoint.Longitude);
                            start = new GPXPoint()
                            {
                                Id        = osmNode.ID, Latitude = segInner.StartPoint.Latitude,
                                Longitude = segInner.StartPoint.Longitude, TrafficSignal = false
                            };
                        }

                        GPXPoint end;
                        if (tagsNodes.Keys.Contains(segInner.EndPoint.Latitude + segInner.EndPoint.Longitude))
                        {
                            OSMNode osmNode = tagsNodes[segInner.EndPoint.Latitude + segInner.EndPoint.Longitude];
                            end = new GPXPoint()
                            {
                                Id        = osmNode.ID, Latitude = segInner.EndPoint.Latitude,
                                Longitude = segInner.EndPoint.Longitude, TrafficSignal = true
                            };
                        }
                        else
                        {
                            OSMNode osmNode = osmFile.Nodes.ToList().First(x => x.Latitude == segInner.EndPoint.Latitude &&
                                                                           x.Longitude == segInner.EndPoint.Longitude);
                            end = new GPXPoint()
                            {
                                Id        = osmNode.ID, Latitude = segInner.EndPoint.Latitude,
                                Longitude = segInner.EndPoint.Longitude, TrafficSignal = false
                            };
                        }

                        listPoints.Add(start);
                        listPoints.Add(end);
                    }

                    segTrack = new GPXTrackSegment(listPoints, seg.AvgSpeed, seg.Speed, seg.Id);
                    // passing the traffic
                    segTrack.Traffic = seg.Traffic;
                    listSegments.Add(segTrack);
                }

                tr = new GPXTrack();
                tr.Segments.AddRange(listSegments);
                track.Add(tr);
            }

            // Bucket Information
            GPXTrack        tBucket = new GPXTrack();
            GPXPoint        pBucket = new GPXPoint(0, 0, 0, false);
            GPXTrackSegment sBucket = new GPXTrackSegment();

            var bucketInfo = osmFile.Nodes.ToList().Find(x => x.ID == 0);

            if (bucketInfo != null)
            {
                pBucket.StartBucket = TimeSpan.Parse(bucketInfo.Tags.First().Value);
                pBucket.EndBucket   = TimeSpan.Parse(bucketInfo.Tags.Last().Value);
            }

            sBucket.Nodes.Add(pBucket);
            tBucket.Segments.Add(sBucket);

            var gpx = new GPXDocument()
            {
                Tracks = track
            };

            gpx.Tracks.Add(tBucket);
            gpx.Save("mapWithHotRoutes.gpx");
        }
Exemplo n.º 3
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");
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            DateTime span = DateTime.Now;

            string osmPath        = "";
            string gpxPath        = "";
            string xmlPath        = "";
            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 },
                { "xml=", "path to the XML file with the time buckets", v => xmlPath = 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("FDI: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `fdi --help' for more information.");
                return;
            }


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


            if (outputPath[outputPath.Length - 1] == '"')
            {
                outputPath = outputPath.Substring(0, outputPath.Length - 1);
            }


            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.");

            TMM processor = new TMM(graph)
            {
                _db = map
            };
            PathReconstructer reconstructor = new PathReconstructer(graph)
            {
                _db = map
            };

            XMLDocument xml = new XMLDocument();

            xml.Load(xmlPath);
            var buckets = xml.Buckets;

            // Process single file
            if (File.Exists(gpxPath))
            {
                List <GPXTrack> result = new List <GPXTrack>();
                result.AddRange(getAllGpxTrackList(gpxPath));

                ProcessGPXFile(gpxPath, processor, reconstructor, outputPath, samplingPeriod, filter, buckets);
                GenerateOsmFiles(buckets, reconstructor, map, result);
                GenerateGpxFiles(buckets, gpxPath, 0);
            }
            // Process all GPX in directory
            else if (Directory.Exists(gpxPath))
            {
                var             files  = Directory.GetFiles(gpxPath, "*.gpx");
                List <GPXTrack> result = new List <GPXTrack>();

                Console.WriteLine("Found {0} GPX file(s).", files.Length);

                for (int i = 0; i < files.Length; i++)
                {
                    ProcessGPXFile(files[i], processor, reconstructor, outputPath, samplingPeriod, filter, buckets);
                    GenerateGpxFiles(buckets, gpxPath, i);
                    result.AddRange(getAllGpxTrackList(files[i]));

                    Console.WriteLine("NEW FILE BEING PROCESSED");
                }

                GenerateOsmFiles(buckets, reconstructor, map, result);
            }
            else
            {
                Console.WriteLine("No GPX files found");
            }

            Console.WriteLine("\tDone.");
            Console.WriteLine("\tSpan=" + (DateTime.Now - span));
        }
Exemplo n.º 5
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();
            }
        }