Exemple #1
0
        /// <summary>
        /// 计算两轨迹点之间所花的时间
        /// </summary>
        /// <param name="startPoint">开始点</param>
        /// <param name="endPoint">终止点</param>
        /// <returns></returns>
        private double ComputeTotalTime(TrackPoint startPoint, TrackPoint endPoint)
        {
            TimeSpan oTime = endPoint.TimeStamp.Subtract(startPoint.TimeStamp);

            return(Math.Abs(oTime.TotalMilliseconds));
        }
Exemple #2
0
        /////// <summary>
        /////// 对轨迹点集合进行插值处理的核心代码
        /////// </summary>
        /////// <param name="allPoints">轨迹点集合</param>
        /////// <param name="smoothFactor">平滑系数</param>
        /////// <param name="speedScaleFactor">速度比例系数</param>
        /////// <returns>轨迹段集合</returns>
        ////private TrackSegments InterpolateProcessCore(TrackPoints allPoints,InterpolateType interpolateType, double smoothFactor, double speedScaleFactor)
        ////{
        ////    TrackPoints oPointsResult = new TrackPoints();
        ////    TrackSegments oSegmentsInfos = new TrackSegments();
        ////    TrackSegments oSegmentsResult = new TrackSegments();

        ////    int iPointCount = 0;

        ////    iPointCount = allPoints.Count;

        ////    if (interpolateType == InterpolateType.LengthInterpolate)
        ////    {
        ////        double dSegLength = 0;

        ////        for (int i = 0; i < iPointCount - 1; i++)
        ////        {
        ////            dSegLength = ComputeDirectDistance(allPoints[i], allPoints[i + 1]);
        ////            this.DividSegmentByLength(ref oPointsResult, dSegLength, smoothFactor, speedScaleFactor, allPoints[i], allPoints[i + 1]);
        ////        }
        ////    }
        ////    else if (interpolateType == InterpolateType.TimeInterpolate)
        ////    {
        ////        double dUsedTime = 0;
        ////        for (int i = 0; i < iPointCount - 1; i++)
        ////        {
        ////            dUsedTime = ComputeTotalTime(allPoints[i], allPoints[i + 1]) / speedScaleFactor;
        ////            this.DividSegmentByTime(ref oPointsResult, dUsedTime, this._baseIntervalTime, allPoints[i], allPoints[i + 1]);
        ////        }
        ////    }

        ////    this.GetSegmentInfos(oPointsResult,ref  oSegmentsResult);
        ////    return oSegmentsResult;
        ////}



        ///// <summary>
        ///// 对指点两个点之间的轨迹段进行分割(以长度为分割单元)
        ///// </summary>
        ///// <param name="trackPointsResult">分割后的轨迹点集合</param>
        ///// <param name="distanceBetweenTwoPoints">两点间的距离</param>
        ///// <param name="smoothFactor">平滑系数</param>
        ///// <param name="speedScaleFactor">速度比例系数</param>
        ///// <param name="StartTrackPoint">起始点</param>
        ///// <param name="EndTrackPoint">终止点</param>
        //private void DividSegmentByLength(ref TrackPoints trackPointsResult, double distanceBetweenTwoPoints, double smoothFactor, double speedScaleFactor, TrackPoint StartTrackPoint, TrackPoint EndTrackPoint)
        //{
        //    TrackPoint oStartPoint = new TrackPoint();
        //    TrackPoint oEndPoint = new TrackPoint();
        //    TrackSegment oSeg = new TrackSegment();

        //    oStartPoint.ID = StartTrackPoint.ID;
        //    oStartPoint.TimeStamp = StartTrackPoint.TimeStamp;
        //    oStartPoint.X = StartTrackPoint.X;
        //    oStartPoint.Y = StartTrackPoint.Y;

        //    oEndPoint.ID = EndTrackPoint.ID;
        //    oEndPoint.TimeStamp = EndTrackPoint.TimeStamp;
        //    oEndPoint.X = EndTrackPoint.X;
        //    oEndPoint.Y = EndTrackPoint.Y;

        //    //计算插入点的个数
        //    decimal decPointCount = smoothFactor == 0 ? 0 : Convert.ToDecimal(distanceBetweenTwoPoints / smoothFactor);
        //    int iInsertPointCount = Convert.ToInt32(Math.Round(decPointCount)) - 1;
        //    iInsertPointCount = iInsertPointCount < 0 ? 0 : iInsertPointCount;

        //    /*
        //     * 如果Ps > Pe
        //     * Px = Abs((Ps - Pe) / n ) * x + Ps
        //     *
        //     * 如果Ps < Pe
        //     * Px = Abs((Ps - Pe) / n ) * (n - 1 - x) + Pe
        //     *
        //     * 其中,n为分割段的个数(等于插入点个数加1),Ps起始端点,Pe终止端点
        //     * x为插入点的序号(靠近Ps的序号为1,靠近Pe的序号为n -1),Px为某一插入点
        //     *
        //     * */

        //    double dSegLenthX = Math.Abs(((oStartPoint.X - oEndPoint.X) / (iInsertPointCount + 1)));
        //    double dSegLenthY = Math.Abs(((oStartPoint.Y - oEndPoint.Y) / (iInsertPointCount + 1)));
        //    TimeSpan oTimeInterval = new TimeSpan();

        //    //计算每个分割轨迹段所用的间隔时间
        //    speedScaleFactor = speedScaleFactor == 0 ? 1 : speedScaleFactor;
        //    oTimeInterval = oEndPoint.TimeStamp.Subtract(oStartPoint.TimeStamp);
        //    int iInterval = Convert.ToInt32((oTimeInterval.TotalMilliseconds / (iInsertPointCount + 1)) * speedScaleFactor);

        //    if (trackPointsResult.Count == 0)
        //    {
        //        oStartPoint.ID = trackPointsResult.Count + 1;
        //        trackPointsResult.Add(oStartPoint);
        //    }

        //    //将分割后的轨迹点添加到集合中去
        //    for (int i = 0; i < iInsertPointCount; i++)
        //    {
        //        TrackPoint oTempPoint = new TrackPoint();

        //        oTempPoint.ID = trackPointsResult.Count + 1;
        //        oTempPoint.TimeStamp = trackPointsResult[trackPointsResult.Count -1].TimeStamp.AddMilliseconds(iInterval);

        //        if (oStartPoint.X >= oEndPoint.X)
        //        {
        //            oTempPoint.X = dSegLenthX * (iInsertPointCount - i) + oEndPoint.X;
        //        }
        //        else
        //        {
        //            oTempPoint.X = dSegLenthX * (i + 1) + oStartPoint.X;
        //        }

        //        if (oStartPoint.Y >= oEndPoint.Y)
        //        {
        //            oTempPoint.Y = dSegLenthY * (iInsertPointCount - i) + oEndPoint.Y;
        //        }
        //        else
        //        {
        //            oTempPoint.Y = dSegLenthY * (i + 1) + oStartPoint.Y;
        //        }

        //        trackPointsResult.Add(oTempPoint);
        //    }

        //    oEndPoint.ID = trackPointsResult.Count + 1;
        //    oEndPoint.TimeStamp = trackPointsResult[trackPointsResult.Count - 1].TimeStamp.AddMilliseconds(iInterval);
        //    trackPointsResult.Add(oEndPoint);
        //}

        /// <summary>
        /// 对指点两个点之间的轨迹段进行分割(以时间为分割单元)
        /// </summary>
        /// <param name="trackPointsResult">分割后的轨迹点集合</param>
        /// <param name="totalTimeUsedBetweenTwoPoints">两点间的时间差</param>
        /// <param name="smoothFactor">平滑系数</param>
        /// <param name="speedScaleFactor">速度比例系数</param>
        /// <param name="StartTrackPoint">起始点</param>
        /// <param name="EndTrackPoint">终止点</param>
        private void DividSegmentByTime(ref TrackPoints trackPointsResult, double totalTimeUsedBetweenTwoPoints, double smoothFactor, double intervalTime, TrackPoint StartTrackPoint, TrackPoint EndTrackPoint)
        {
            TrackPoint   oStartPoint = new TrackPoint();
            TrackPoint   oEndPoint   = new TrackPoint();
            TrackSegment oSeg        = new TrackSegment();

            oStartPoint.ID        = StartTrackPoint.ID;
            oStartPoint.TimeStamp = StartTrackPoint.TimeStamp;
            oStartPoint.X         = StartTrackPoint.X;
            oStartPoint.Y         = StartTrackPoint.Y;

            oEndPoint.ID        = EndTrackPoint.ID;
            oEndPoint.TimeStamp = EndTrackPoint.TimeStamp;
            oEndPoint.X         = EndTrackPoint.X;
            oEndPoint.Y         = EndTrackPoint.Y;

            //计算插入点的个数
            decimal decPointCount = intervalTime == 0 ? 1 : Convert.ToDecimal((totalTimeUsedBetweenTwoPoints) / intervalTime);

            int iInsertPointCount = Convert.ToInt32(Math.Round(decPointCount)) - 1;

            iInsertPointCount = iInsertPointCount < 0 ? 0 : iInsertPointCount;

            /**************************************************************************************
             * 如果Ps > Pe
             * Px = Abs((Ps - Pe) / n ) * x + Ps
             *
             * 如果Ps < Pe
             * Px = Abs((Ps - Pe) / n ) * (n - 1 - x) + Pe
             *
             * 其中,n为分割段的个数(等于插入点个数加1),Ps起始端点,Pe终止端点
             * x为插入点的序号(靠近Ps的序号为1,靠近Pe的序号为n -1),Px为某一插入点
             *
             ***************************************************************************************/

            double dSegLenthX = Math.Abs(((oStartPoint.X - oEndPoint.X) / (iInsertPointCount + 1)));
            double dSegLenthY = Math.Abs(((oStartPoint.Y - oEndPoint.Y) / (iInsertPointCount + 1)));

            if (trackPointsResult.Count == 0)
            {
                oStartPoint.ID = trackPointsResult.Count + 1;
                trackPointsResult.Add(oStartPoint);
            }

            //将分割后的轨迹点添加到集合中去
            for (int i = 0; i < iInsertPointCount; i++)
            {
                TrackPoint oTempPoint = new TrackPoint();

                oTempPoint.ID        = trackPointsResult.Count + 1;
                oTempPoint.TimeStamp = trackPointsResult[trackPointsResult.Count - 1].TimeStamp.AddMilliseconds(intervalTime);

                if (oStartPoint.X >= oEndPoint.X)
                {
                    oTempPoint.X = dSegLenthX * (iInsertPointCount - i) + oEndPoint.X;
                }
                else
                {
                    oTempPoint.X = dSegLenthX * (i + 1) + oStartPoint.X;
                }

                if (oStartPoint.Y >= oEndPoint.Y)
                {
                    oTempPoint.Y = dSegLenthY * (iInsertPointCount - i) + oEndPoint.Y;
                }
                else
                {
                    oTempPoint.Y = dSegLenthY * (i + 1) + oStartPoint.Y;
                }

                trackPointsResult.Add(oTempPoint);
            }

            oEndPoint.ID = trackPointsResult.Count + 1;
            trackPointsResult.Add(oEndPoint);
        }