Exemplo n.º 1
0
        private List <RefPoint> getRefPoints(Trajectory trj)
        {
            if (trj.Count == 0)
            {
                return(null);
            }
            List <RefPoint> refPoints = new List <RefPoint>();

            for (int i = 0; i < trj.Count; ++i)
            {
                MotionVector mv       = trj[i];
                RefPoint     refPoint = null;
                if (mv.e != null)
                {
                    double distance = mv.e.DistOnLine(mv.e.Start.Point, mv.point);
                    refPoint = new RefPoint(mv.t, mv.e, distance);
                }
                else
                {
                    refPoint = new RefPoint(mv.t, mv.point);
                }
                refPoints.Add(refPoint);
            }
            // calcualte the deviation between trj and the ref points
            //String tempFileName = Path.Combine(Constants.TRJ_DIR, "1000099465_short_ref");
            //StreamWriter sw = new StreamWriter(tempFileName);
            //for (int i = 0; i < trj.Count; ++i)
            //{
            //    MotionVector mv = trj[i];
            //    double dev = GeoPoint.GetDistance(mv.point, refPoints[i].Point);
            //    sw.WriteLine("{0},{1},{2},{3},{4}", mv.t, mv.point.Lat, mv.point.Lng, mv.EdgeId, dev);
            //}
            //sw.Close();
            return(refPoints);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Original version of compress
        /// The use of shortest path results in some drawbacks...
        /// </summary>
        /// <param name="trj"></param>
        /// <returns></returns>
        public VCompressedTrj Compress_v1(Trajectory trj)
        {
            if (trj.Count == 0)
            {
                return(null);
            }
            List <RefPoint> refPoints = getRefPoints(trj);
            VCompressedTrj  cTrj      = new VCompressedTrj();

            VCompressedTrj.Item item = new VCompressedTrj.Item();
            double dist = 0, appDist = 0;
            Edge   lastEdge = refPoints[0].e;

            item.RefPoint = refPoints[0];
            for (int i = 1; i < refPoints.Count; ++i)
            {
                RefPoint cur = refPoints[i], prev = refPoints[i - 1];
                double   distance = 0.0, v = 0;
                byte     roundV = 0, si = (byte)(cur.t - prev.t);
                if (cur.e == prev.e)
                {
                    distance = cur.distance - prev.distance;
                }
                else if (cur.e.Start == prev.e.End)
                {
                    distance = prev.e.Length - prev.distance + cur.distance;
                }
                else
                {
                    distance = prev.e.Length - prev.distance;
                    var path = _g.FindPath(prev.e.End, cur.e.Start);
                    foreach (var e in path)
                    {
                        distance += e.Length;
                    }
                    distance += cur.distance;
                }
                v        = distance / si;
                roundV   = (byte)(Math.Round(v) / _binSize);
                dist    += distance;
                appDist += roundV * si * _binSize;
                if (Math.Abs(dist - appDist) >= _maxDev)
                {
                    // insert the reference point
                    cTrj.Items.Add(item);
                    // clear
                    item          = new VCompressedTrj.Item();
                    item.RefPoint = cur;
                    dist          = 0;
                    appDist       = 0;
                }
                else
                {
                    item.Points.Add(new VCompressedMV(si, cur.eid, roundV));
                }
            }
            cTrj.Items.Add(item);
            return(cTrj);
        }