Exemplo n.º 1
0
        private async Task <List <Trajectory> > OfflineMatch(Matcher <MatcherCandidate, MatcherTransition, MatcherSample> matcher, IReadOnlyList <MatcherSample> samples)
        {
            var kstate = new MatcherKState();

            //Do the offline map-matching
            Debug.WriteLine("Doing map-matching...");
            var startedOn = DateTime.Now;
            await Task.Run(() =>
            {
                foreach (var sample in samples)
                {
                    var vector = matcher.Execute(kstate.Vector(), kstate.Sample, sample);
                    kstate.Update(vector, sample);
                }
            });

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

            LoggerHelper.Logger.Info("Map-matching elapsed time: {0}, Speed={1} samples/second", timeElapsed, samples.Count / timeElapsed.TotalSeconds);
            LoggerHelper.Logger.Info("Results: [count={0}]", candidatesSequence.Count());
            Debug.WriteLine("Map-matching elapsed time: {0}, Speed={1} samples/second", timeElapsed, samples.Count / timeElapsed.TotalSeconds);
            Debug.WriteLine("Results: [count={0}]", candidatesSequence.Count());

            List <Trajectory> csvLines = new List <Trajectory>();
            int matchedCandidateCount  = 0;

            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)
                csvLines.Add(new Trajectory()
                {
                    GPSTime        = cand.Sample.Time.DateTime,
                    Location       = "314.2",
                    Velocity       = 30,
                    LongitudeWgs84 = coord.X,
                    LatitudeWgs84  = coord.Y
                });

                if (cand.HasTransition)
                {
                    var geom = cand.Transition.Route.ToGeometry(); // path geometry(LineString) from last matching candidate
                    //var edges = cand.Transition.Route.Edges; // Road segments between two GPS position
                }
                matchedCandidateCount++;
            }

            LoggerHelper.Logger.Info("Matched Candidates: {0}, Rate: {1}%", matchedCandidateCount, matchedCandidateCount * 100 / samples.Count());
            Debug.WriteLine("Matched Candidates: {0}, Rate: {1}%", matchedCandidateCount, matchedCandidateCount * 100 / samples.Count());
            return(csvLines);
        }
Exemplo n.º 2
0
        private int DoMatching(Matcher <MatcherCandidate, MatcherTransition, MatcherSample> matcher)
        {
            var kstate = new MatcherKState();

            foreach (var sample in _samples)
            {
                var vector = matcher.Execute(kstate.Vector(), kstate.Sample, sample);
                kstate.Update(vector, sample);
            }
            return(0);
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        private static void OfflineMatch(
            Matcher <MatcherCandidate, MatcherTransition, MatcherSample> matcher,
            IReadOnlyList <MatcherSample> samples)
        {
            var kstate = new MatcherKState();

            //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.Count / timeElapsed.TotalSeconds);
            Console.WriteLine("Results: [count={0}]", candidatesSequence.Count());
            var csvLines = new List <string>();

            csvLines.Add("time,lng,lat,azimuth");
            int matchedCandidateCount = 0;

            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)
                csvLines.Add(string.Format("{0},{1},{2},{3}", cand.Sample.Time.ToUnixTimeSeconds(), coord.X, coord.Y, cand.Point.Azimuth));
                if (cand.HasTransition)
                {
                    var geom = cand.Transition.Route.ToGeometry(); // path geometry(LineString) from last matching candidate
                    //cand.Transition.Route.Edges // Road segments between two GPS position
                }
                matchedCandidateCount++;
            }
            Console.WriteLine("Matched Candidates: {0}, Rate: {1}%", matchedCandidateCount, matchedCandidateCount * 100 / samples.Count());

            var csvFile = System.IO.Path.Combine(s_dataDir, "samples.output.csv");

            Console.WriteLine("Writing output file: {0}", csvFile);
            File.WriteAllLines(csvFile, csvLines);
        }
Exemplo n.º 5
0
        private static void OnlineMatch(
            Matcher <MatcherCandidate, MatcherTransition, MatcherSample> matcher,
            IReadOnlyList <MatcherSample> samples)
        {
            // Create initial (empty) state memory
            var kstate = new MatcherKState();

            // Iterate over sequence (stream) of samples
            foreach (var sample in samples)
            {
                // Execute matcher with single sample and update state memory
                var vector = kstate.Vector();
                vector = matcher.Execute(vector, kstate.Sample, sample);
                kstate.Update(vector, sample);

                // Access map matching result: estimate for most recent sample
                var estimated = kstate.Estimate();
                Console.WriteLine("RoadID={0}", estimated.Point.Edge.RoadInfo.Id); // The id of the road in your map
            }
        }