예제 #1
0
        public void Setup()
        {
            this.DataDirPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "../../../../../../../../../", "data"));

            var spatial = new GeographySpatialOperation();
            var roads   = this.ReadRoads(spatial);

            var mapBuilder = new RoadMapBuilder(spatial);

            _roadMap = mapBuilder.AddRoads(roads).Build();

            {
                var naiveDijkstraRouter = new DijkstraRouter <Road, RoadPoint>();
                _naiveDijkstraMatcher = new Matcher <MatcherCandidate, MatcherTransition, MatcherSample>(
                    _roadMap, naiveDijkstraRouter, Costs.TimePriorityCost, spatial);
                _naiveDijkstraMatcher.MaxDistance = MaxDistance;  // set maximum searching distance between two GPS points to 1000 meters.
                _naiveDijkstraMatcher.MaxRadius   = MaxGpsRadius; // sets maximum radius for candidate selection to 200 meters
            }

            {
                var precomputedDijkstraRouter = new PrecomputedDijkstraRouter <Road, RoadPoint>(_roadMap, Costs.TimePriorityCost, Costs.DistanceCost, MaxDistance);
                _precomputedDijkstraMatcher = new Matcher <MatcherCandidate, MatcherTransition, MatcherSample>(
                    _roadMap, precomputedDijkstraRouter, Costs.TimePriorityCost, spatial);
                _precomputedDijkstraMatcher.MaxDistance = MaxDistance;  // set maximum searching distance between two GPS points to 1000 meters.
                _precomputedDijkstraMatcher.MaxRadius   = MaxGpsRadius; // sets maximum radius for candidate selection to 200 meters
            }

            _samples = ReadSamples().OrderBy(s => s.Time).ToArray();
        }
예제 #2
0
        static void Main(string[] args)
        {
            var spatial    = new GeographySpatialOperation();
            var mapBuilder = new RoadMapBuilder(spatial);

            Console.WriteLine("Loading road map...");
            var roads = ReadRoads(spatial);
            var map   = mapBuilder.AddRoads(roads).Build();

            Console.WriteLine("The road map has been loaded");

            var matcher = new Matcher(map, new DijkstraRouter <Road, RoadPoint>(), Costs.TimePriorityCost, spatial);

            matcher.MaxDistance = 1000;  // set maximum searching distance between two GPS points to 1000 meters.
            matcher.MaxRadius   = 200.0; // sets maximum radius for candidate selection to 200 meters

            var kstate = new MatcherKState();

            Console.WriteLine("Loading GPS samples...");
            var samples = ReadSamples().OrderBy(s => s.Time).ToArray();

            Console.WriteLine("GPS samples loaded. [count={0}]", samples.Length);

            //Do the offline map-matching
            Console.WriteLine("Doing map-matching...");
            var startedOn = DateTime.Now;

            foreach (var sample in samples)
            {
                var vector = matcher.Execute(kstate.Vector(), kstate.Sample, sample);
                kstate.Update(vector, sample);
            }

            Console.WriteLine("Fetching map-matching results...");
            var candidatesSequence = kstate.Sequence();
            var timeElapsed        = DateTime.Now - startedOn;

            Console.WriteLine("Map-matching elapsed time: {0}, Speed={1} samples/second", timeElapsed, samples.Length / timeElapsed.TotalSeconds);
            Console.WriteLine("Results: [count={0}]", candidatesSequence.Count());
            foreach (var cand in candidatesSequence)
            {
                var roadId  = cand.Point.Edge.RoadInfo.Id; // original road id
                var heading = cand.Point.Edge.Headeing;    // heading
                var coord   = cand.Point.Coordinate;       // GPS position (on the road)
                if (cand.HasTransition)
                {
                    var geom = cand.Transition.Route.ToGeometry(); // path geometry from last matching candidate
                    Console.WriteLine("RoadID={0}\t\tFraction={1}", roadId, cand.Point.Fraction);
                }
            }

            Console.WriteLine("All done!");
            Console.ReadKey();
        }
예제 #3
0
        /// <summary>
        /// 开始纠偏
        /// </summary>
        /// <returns></returns>
        public async Task <List <Trajectory> > LoadDataAndTransfer()
        {
            var spatial    = new GeographySpatialOperation();
            var mapBuilder = new RoadMapBuilder(spatial);

            LoggerHelper.Logger.Info("Loading road map...");
            Debug.WriteLine("Loading road map...");
            var roads = ReadRoads(spatial);
            var map   = mapBuilder.AddRoads(roads).Build();

            LoggerHelper.Logger.Info("The road map has been loaded");
            Debug.WriteLine("The road map has been loaded");


            //var router = new PrecomputedDijkstraRouter<Road, RoadPoint>(map, Costs.TimePriorityCost, Costs.DistanceCost, 1000D);
            var router = new DijkstraRouter <Road, RoadPoint>();

            var matcher = new Matcher <MatcherCandidate, MatcherTransition, MatcherSample>(
                map, router, Costs.TimePriorityCost, spatial);

            matcher.MaxDistance = 20; // set maximum searching distance between two GPS points to 1000 meters.
            matcher.MaxRadius   = 15; // sets maximum radius for candidate selection to 200 meters

            //matcher.MaxDistance = 1000; // set maximum searching distance between two GPS points to 1000 meters.
            //matcher.MaxRadius = 200; // sets maximum radius for candidate selection to 200 meters


            Debug.WriteLine("Loading GPS samples...");
            //var samples = ReadSamples().OrderBy(s => s.Time).ToList();
            var samples = ReadSamples(_trajectories).OrderBy(s => s.Time).ToList();

            LoggerHelper.Logger.Info("GPS samples loaded. [count={0}]", samples.Count);
            Debug.WriteLine("GPS samples loaded. [count={0}]", samples.Count);

            Debug.WriteLine("Starting Offline map-matching...");
            var res = await OfflineMatch(matcher, samples);

            return(res);
        }
예제 #4
0
        static void Main(string[] args)
        {
            var spatial    = new GeographySpatialOperation();
            var mapBuilder = new RoadMapBuilder(spatial);

            Console.WriteLine("Loading road map...");
            var roads = ReadRoads(spatial);
            var map   = mapBuilder.AddRoads(roads).Build();

            Console.WriteLine("The road map has been loaded");


            //var router = new PrecomputedDijkstraRouter<Road, RoadPoint>(map, Costs.TimePriorityCost, Costs.DistanceCost, 1000D);
            var router = new DijkstraRouter <Road, RoadPoint>();

            var matcher = new Matcher <MatcherCandidate, MatcherTransition, MatcherSample>(
                map, router, Costs.TimePriorityCost, spatial);

            matcher.MaxDistance = 1000;  // set maximum searching distance between two GPS points to 1000 meters.
            matcher.MaxRadius   = 200.0; // sets maximum radius for candidate selection to 200 meters


            Console.WriteLine("Loading GPS samples...");
            var samples = ReadSamples().OrderBy(s => s.Time).ToList();

            Console.WriteLine("GPS samples loaded. [count={0}]", samples.Count);

            Console.WriteLine("Starting Offline map-matching...");
            OfflineMatch(matcher, samples);


            Console.WriteLine("Starting Online map-matching...");
            //Uncomment below line to see how online-matching works
            //OnlineMatch(matcher, samples);

            Console.WriteLine("All done!");
            Console.ReadKey();
        }