コード例 #1
0
ファイル: Astar.cs プロジェクト: wsgan001/TPM
        /// <summary>
        /// Creates a new instance of the pathfinder
        /// </summary>
        /// <param name="graph">RoadGraph object that represents roads network</param>
        public AstarPathfinder(RoadGraph graph)
        {
            _graph = graph;

            _open  = new PartialPathList();
            _close = new Dictionary <Node, PartialPath>();
            _temporaryConnections = new List <Connection>();
        }
コード例 #2
0
ファイル: Astar.cs プロジェクト: guifa/traveltimeanalysis
        /// <summary>
        /// Creates a new instance of the pathfinder 
        /// </summary>
        /// <param name="graph">RoadGraph object that represents roads network</param>
        public AstarPathfinder(RoadGraph graph)
        {
            _graph = graph;

            _open = new PartialPathList();
            _close = new Dictionary<Node, PartialPath>();
            _temporaryConnections = new List<Connection>();
        }
コード例 #3
0
        public void RoadGraphBuildCreatesNodesAccordingToMap()
        {
            OSMDB map = new OSMDB();
            map.Nodes.Add(new OSMNode(1, 1, 2));
            map.Nodes.Add(new OSMNode(2, 2, 3));

            OSMWay way = new OSMWay(3, new List<int>(new int[] { 1, 2 }));
            way.Tags.Add(new OSMTag("accessible", "no"));
            way.Tags.Add(new OSMTag("accessible-reverse", "yes"));
            way.Tags.Add(new OSMTag("speed", "50"));
            way.Tags.Add(new OSMTag("way-id", "123"));
            map.Ways.Add(way);

            RoadGraph target = new RoadGraph();
            target.Build(map);

            Assert.Equal(2, target.Nodes.Count());
            Assert.Equal(1, target.Nodes.Where(n => n.MapPoint == map.Nodes[1]).Count());
            Assert.Equal(1, target.Nodes.Where(n => n.MapPoint == map.Nodes[2]).Count());
        }
コード例 #4
0
        public void RoadGraphBuildCreatesCorrectConnectionGeometry()
        {
            OSMDB map = new OSMDB();
            map.Nodes.Add(new OSMNode(1, 1, 2));
            map.Nodes.Add(new OSMNode(2, 2, 3));
            map.Nodes.Add(new OSMNode(3, 3, 4));

            OSMWay way = new OSMWay(4, new int[] { 1, 2, 3 });
            way.Tags.Add(new OSMTag("accessible", "yes"));
            way.Tags.Add(new OSMTag("accessible-reverse", "yes"));
            way.Tags.Add(new OSMTag("speed", "50"));
            way.Tags.Add(new OSMTag("way-id", "123"));
            map.Ways.Add(way);

            RoadGraph target = new RoadGraph();
            target.Build(map);

            Assert.Equal(1, target.ConnectionGeometries.Count());
            Assert.Equal(3, target.ConnectionGeometries.Single().Nodes.Count);
        }
コード例 #5
0
 /// <summary>
 /// Create a new instance of the STMatching class
 /// </summary>
 /// <param name="graph">The RoadGraph object that represents road network</param>
 public STMatching(RoadGraph graph)
 {
     _graph = graph;
     _pathfinder = new AstarPathfinder(_graph);
     _trackCutout = new List<ConnectionGeometry>();
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: guifa/traveltimeanalysis
        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");
            }
        }
コード例 #7
0
 /// <summary>
 /// Creates a new instance of the PathReconstructer
 /// </summary>
 /// <param name="graph">The RoadGraph object with the road network that will be used in the reconstruction process</param>
 public PathReconstructer(RoadGraph graph)
 {
     _pathfinder = new AstarPathfinder(graph);
 }
コード例 #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
 /// <summary>
 /// Create a new instance of the STMatching class
 /// </summary>
 /// <param name="graph">The RoadGraph object that represents road network</param>
 public STMatching(RoadGraph graph)
 {
     _graph       = graph;
     _pathfinder  = new AstarPathfinder(_graph);
     _trackCutout = new List <ConnectionGeometry>();
 }
コード例 #10
0
        public void RoadGraphBuildCreatesOneWayConnectionForOnewayRoads1()
        {
            OSMDB map = new OSMDB();
            map.Nodes.Add(new OSMNode(1, 1, 1));
            map.Nodes.Add(new OSMNode(2, 2, 2));

            OSMWay way = new OSMWay(3, new List<int>(new int[] { 1, 2 }));
            way.Tags.Add(new OSMTag("accessible", "yes"));
            way.Tags.Add(new OSMTag("accessible-reverse", "no"));
            way.Tags.Add(new OSMTag("speed", "50"));
            way.Tags.Add(new OSMTag("way-id", "123"));
            map.Ways.Add(way);

            RoadGraph target = new RoadGraph();
            target.Build(map);

            Assert.Equal(1, target.Connections.Count());
            Assert.Equal(1, target.Connections.Where(c => c.From.MapPoint == map.Nodes[1] && c.To.MapPoint == map.Nodes[2]).Count());

            Assert.Equal(1, target.Nodes.Where(n => n.MapPoint == map.Nodes[1]).Single().Connections.Count());
            Assert.Equal(1, target.Nodes.Where(n => n.MapPoint == map.Nodes[2]).Single().Connections.Count());
        }
コード例 #11
0
        public void RoadGraphConstructorInitializesProperties()
        {
            RoadGraph target = new RoadGraph();

            Assert.NotNull(target.Nodes);
            Assert.NotNull(target.Connections);
        }