示例#1
0
 /// <summary>
 /// Finds shortest path between two points along routes
 /// </summary>
 /// <param name="from">Start point</param>
 /// <param name="to">Destination point</param>
 /// <returns>length of the path in meters</returns>
 double FindShortestPath(CandidatePoint from, CandidatePoint to)
 {
     if (from.Road == to.Road)
     {
         return(Calculations.GetPathLength(from.MapPoint, to.MapPoint, from.Road));
     }
     else
     {
         double length = double.PositiveInfinity;
         _pathfinder.FindPath(from, to, ref length);
         return(length);
     }
 }
示例#2
0
        /// <summary>
        /// Recostrcucts Path from the list of candidate points
        /// </summary>
        /// <param name="matched">List of the candidate points</param>
        /// <returns>List of Polylines that represents matched path</returns>
        public List <Polyline <IPointGeo> > Reconstruct(IList <CandidatePoint> matched)
        {
            _points = new Dictionary <IPointGeo, PointEx>();
            List <Polyline <IPointGeo> > result = new List <Polyline <IPointGeo> >();

            for (int i = 0; i < matched.Count - 1; i++)
            {
                ConnectionGeometry wayGeometry = null;
                if (Calculations.GetDistance2D(matched[i + 1].MapPoint, matched[i].Road) < Calculations.EpsLength)
                {
                    wayGeometry = matched[i].Road;
                }
                else if (Calculations.GetDistance2D(matched[i].MapPoint, matched[i + 1].Road) < Calculations.EpsLength)
                {
                    wayGeometry = matched[i + 1].Road;
                }

                // both points are on the same road segment
                if (wayGeometry != null)
                {
                    result.Add(CreateLine(matched[i].MapPoint, matched[i + 1].MapPoint, matched[i].Layer.TrackPoint.Time, matched[i + 1].Layer.TrackPoint.Time, wayGeometry));
                }
                else
                {
                    double lenght = double.PositiveInfinity;

                    // find path between matched[i] and matched[i+1]
                    var pathSegments = _pathfinder.FindPath(matched[i], matched[i + 1], ref lenght);
                    if (pathSegments == null)
                    {
                        throw new ArgumentException(string.Format("Can not find path between points {0} and {1}", matched[i].MapPoint, matched[i + 1].MapPoint));
                    }
                    if (pathSegments.Count > 1)
                    {
                        result.Add(CreateLine(pathSegments[0].From.MapPoint, pathSegments[0].To.MapPoint, matched[i].Layer.TrackPoint.Time, DateTime.MinValue, pathSegments[0].Road));

                        for (int j = 1; j < pathSegments.Count - 1; j++)
                        {
                            result.Add(CreateLine(pathSegments[j].From.MapPoint, pathSegments[j].To.MapPoint, pathSegments[j].Road));
                        }

                        result.Add(CreateLine(pathSegments[pathSegments.Count - 1].From.MapPoint, pathSegments[pathSegments.Count - 1].To.MapPoint, DateTime.MinValue, matched[i + 1].Layer.TrackPoint.Time, pathSegments[pathSegments.Count - 1].Road));
                    }
                    else
                    {
                        result.Add(CreateLine(pathSegments[0].From.MapPoint, pathSegments[0].To.MapPoint, matched[i].Layer.TrackPoint.Time, matched[i + 1].Layer.TrackPoint.Time, pathSegments[0].Road));
                    }
                }
            }
            return(result);
        }