public static TrackingReplay.TrackPoints GetHistoryTrackingData(string carNumber, DateTime startTime, DateTime endTime) { if (startTime - endTime > new TimeSpan() || string.IsNullOrEmpty(carNumber)) { return(new TrackPoints()); } System.Data.OleDb.OleDbConnection oConn = BaseHandler.DatabaseManager.GetOleDbConnection(GlobeVariables.ConfigureInfos.TrackingReplayConfigureInfos.LocalDatabaseLocation); string sDataTableName = GlobeVariables.ConfigureInfos.TrackingReplayConfigureInfos.TrackingTableName; string sQueryString = string.Format("select distinct * from {0} where carnumber='{1}'", sDataTableName, carNumber); DataTable dtTrackings = BaseHandler.DatabaseManager.GetData(oConn, sQueryString); //string sFilterString = string.Format("currentTime >= #{0}# and currentTime <= #{1}#", startTime.ToString() + "." + startTime.Millisecond.ToString(), endTime.ToString() + "." + endTime.Millisecond.ToString()); //dtTrackings.Columns["currenttime"].Expression = "convert(currenttime,'System.DateTime')"; //dtTrackings.Columns["currenttime"].DataType = typeof(DateTime); //DataRow[] drResults = dtTrackings.Select(sFilterString, "currenttime desc"); TrackPoints oInputData = ConvertDataTableToTrackingPoints(dtTrackings, startTime, endTime); oInputData.Sort((new BaseHandler.MyComparison <TrackingReplay.TrackPoint>()).GetComparison(GPSTrackingMonitor.BaseHandler.ComparisonType.ASC)); return(oInputData); }
/// <summary> /// 对轨迹点集合进行插值处理的核心代码 /// </summary> /// <param name="allPoints">轨迹点集合</param> /// <param name="smoothFactor">平滑系数</param> /// <param name="speedScaleFactor">速度比例系数</param> /// <returns>轨迹点集合</returns> public TrackPoints InterpolateProcess(TrackPoints allPoints, int smoothFactor) { if (smoothFactor == 0) { return(allPoints); } TrackPoints oPointsResult = new TrackPoints(); TrackSegments oSegmentsInfos = new TrackSegments(); TrackSegments oSegmentsResult = new TrackSegments(); int iPointCount = 0; iPointCount = allPoints.Count; double dUsedTime = 0; double dInterval = this.GetIntervalTime(allPoints, smoothFactor); for (int i = 0; i < iPointCount - 1; i++) { dUsedTime = ComputeTotalTime(allPoints[i], allPoints[i + 1]); this.DividSegmentByTime(ref oPointsResult, dUsedTime, smoothFactor, dInterval, allPoints[i], allPoints[i + 1]); } return(oPointsResult); }
private static TrackingReplay.TrackPoints ConvertDataTableToTrackingPoints(DataTable trackingTable, DateTime startTime, DateTime endTime) { TrackingReplay.TrackPoints oTrackingPoints = new TrackPoints(); TrackingReplay.TrackPoint oTrackingPoint; DateTime tCurTime; foreach (DataRow dr in trackingTable.Rows) { tCurTime = DateTime.Parse(dr["currenttime"].ToString()); if (!(tCurTime >= startTime && tCurTime <= endTime)) { continue; } oTrackingPoint = new TrackPoint(); oTrackingPoint.ID = Int32.Parse(dr["geoid"].ToString()); oTrackingPoint.X = double.Parse(dr["x"].ToString()); oTrackingPoint.Y = double.Parse(dr["y"].ToString()); oTrackingPoint.TimeStamp = tCurTime; oTrackingPoints.Add(oTrackingPoint); } return(oTrackingPoints); }
/// <summary> /// 查找所有轨迹段中最短的轨迹段 /// </summary> /// <param name="AllPoints">所有的轨迹点</param> /// <returns>最短的轨迹段</returns> private TrackSegment FindShortestSegment(TrackPoints AllPoints) { int iPointsCount = 0; double dCurDistance = 0; TrackSegment oSegResult = new TrackSegment(); TrackPoint oPrePoint = new TrackPoint(); TrackPoint oNextPoint = new TrackPoint(); iPointsCount = AllPoints.Count; oSegResult.SegmentLenth = this.ComputeDirectDistance(AllPoints[0], AllPoints[1]); oSegResult.StartTrackPoint = AllPoints[0]; oSegResult.EndTrackPoint = AllPoints[1]; for (int i = 0; i < iPointsCount - 1; i++) { dCurDistance = this.ComputeDirectDistance(AllPoints[i], AllPoints[i + 1]); if (oSegResult.SegmentLenth > dCurDistance) { oSegResult.SegmentLenth = dCurDistance; oSegResult.StartTrackPoint = AllPoints[i]; oSegResult.EndTrackPoint = AllPoints[i + 1]; } } TimeSpan oTime = oSegResult.EndTrackPoint.TimeStamp.Subtract(oSegResult.StartTrackPoint.TimeStamp); oSegResult.CourseTime = oTime.TotalMilliseconds; oSegResult.Speed = oSegResult.SegmentLenth / oSegResult.CourseTime; return(oSegResult); }
public virtual void CalculateDistance() { if (TrackPoints.Count == 0) { Distance = null; return; } var points = TrackPoints.Select(p => new PointLatLng(p.Latitude, p.Longitude)); Distance = new MapRoute(points, "").Distance; }
/// <summary> /// 根据平滑系数和速度比例参数来计算时间间隔 /// </summary> /// <param name="allPoints"></param> /// <param name="smoothFactor"></param> /// <param name="speedScaleFactor"></param> /// <returns></returns> public double GetIntervalTime(TrackPoints allPoints, double smoothFactor) { if (allPoints == null || allPoints.Count == 0) { return(0); } double dBaseInterval = this.FindLestTimeInSegments(allPoints).CourseTime; double iInterval = 0; smoothFactor = smoothFactor == 0 ? 1 : smoothFactor; iInterval = dBaseInterval / smoothFactor; return(iInterval); }
public override void MouseMove(object sender, MouseEventArgs e) { if (UseErasePart && SelectLine != null && e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { Topology editor = new Topology(Graph); Point pos = e.GetPosition(GraphContainer); Point np = editor.LinNearestPoint(SelectLine, pos); TrackPoints.Add(np); np = GraphContainer.TranslatePoint(np, this.AssociatedObject); TrackAdorner.Track.Points.Add(np); } else { base.MouseMove(sender, e); } }
private void btnReplay_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.cbbCarNumber.Text)) { MessageBox.Show("未指定车辆,无法进行轨迹回放!"); return; } if (dtpEndTime.Value == dtpStartTime.Value) { MessageBox.Show("请设置正确的时间段。"); return; } this._replayOperation.ClearTrackings(false); //计算插值 TrackInterpolate oTrackInter = new TrackInterpolate(); this._inputData = TrackingReplay.TrackingData.GetHistoryTrackingData(this.cbbCarNumber.Text, dtpStartTime.Value, dtpEndTime.Value); if (this._inputData == null || this._inputData.Count == 0) { MessageBox.Show("在指定的时间段内该车辆没有出行记录。"); return; } this._outputData = oTrackInter.InterpolateProcess(this._inputData, this.trbSmoothScale.Value); if (this._outputData == null || this._outputData.Count == 0) { // MessageBox.Show("插值分析失败!"); return; } //显示轨迹线 this._replayOperation.AddTrackingPath(this._inputData); //开始回放 this._curIndex = 0; this._trackReplayTimer.Interval = 1000 / this.trbReplaySpeed.Value; this._trackReplayTimer.Start(); this.btnReplay.Enabled = false; this.btnStop.Enabled = true; }
private void btnReplay_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.cbbCarNumber.Text)) { MessageBox.Show("δָ�������������й켣�طţ�"); return; } if (dtpEndTime.Value == dtpStartTime.Value) { MessageBox.Show("��������ȷ��ʱ��Ρ�"); return; } this._replayOperation.ClearTrackings(false); //�����ֵ TrackInterpolate oTrackInter = new TrackInterpolate(); this._inputData = TrackingReplay.TrackingData.GetHistoryTrackingData(this.cbbCarNumber.Text,dtpStartTime.Value,dtpEndTime.Value); if (this._inputData == null || this._inputData.Count == 0) { MessageBox.Show("��ָ����ʱ����ڸó���û�г��м�¼��"); return; } this._outputData = oTrackInter.InterpolateProcess(this._inputData, this.trbSmoothScale.Value); if (this._outputData == null || this._outputData.Count == 0) { // MessageBox.Show("��ֵ����ʧ�ܣ�"); return; } //��ʾ�켣�� this._replayOperation.AddTrackingPath(this._inputData); //��ʼ�ط� this._curIndex = 0; this._trackReplayTimer.Interval = 1000 / this.trbReplaySpeed.Value; this._trackReplayTimer.Start(); this.btnReplay.Enabled = false; this.btnStop.Enabled = true; }
/// <summary> /// ��ȡ������ /// </summary> /// <param name="inputPoints">����켣�㼯��</param> /// <param name="baseIntervalTime">����ֵ�켣��֮���ʱ����</param> /// <returns>��ֵ��Ĺ켣�㼯��</returns> public TrackPoints GetResultByInterpolateTime(TrackPoints inputPoints, double baseIntervalTime) { TrackPoints oResultPoint = null; try { TrackInterpolate oTrackInter = new TrackInterpolate(); oTrackInter.BaseIntervalTime = baseIntervalTime; oResultPoint = oTrackInter.InterpolateProcess(inputPoints,); } catch (Exception ex) { throw new Exception(ex.StackTrace); } return oResultPoint; }
/// <summary> /// 获取计算结果 /// </summary> /// <param name="inputPoints">输入轨迹点集合</param> /// <param name="baseIntervalTime">各差值轨迹点之间的时间间隔</param> /// <returns>差值后的轨迹点集合</returns> public TrackPoints GetResultByInterpolateTime(TrackPoints inputPoints, double baseIntervalTime) { TrackPoints oResultPoint = null; try { TrackInterpolate oTrackInter = new TrackInterpolate(); oTrackInter.BaseIntervalTime = baseIntervalTime; oResultPoint = oTrackInter.InterpolateProcess(inputPoints, ); } catch (Exception ex) { throw new Exception(ex.StackTrace); } return(oResultPoint); }
private static TrackingReplay.TrackPoints ConvertDataTableToTrackingPoints(DataTable trackingTable) { TrackingReplay.TrackPoints oTrackingPoints = new TrackPoints(); TrackingReplay.TrackPoint oTrackingPoint; foreach (DataRow dr in trackingTable.Rows) { oTrackingPoint = new TrackPoint(); oTrackingPoint.ID = Int32.Parse(dr["geoid"].ToString()); oTrackingPoint.X = double.Parse(dr["x"].ToString()); oTrackingPoint.Y = double.Parse(dr["y"].ToString()); oTrackingPoint.TimeStamp = DateTime.Parse(dr["currenttime"].ToString()); oTrackingPoints.Add(oTrackingPoint); } return oTrackingPoints; }
private static TrackingReplay.TrackPoints ConvertDataTableToTrackingPoints(DataTable trackingTable) { TrackingReplay.TrackPoints oTrackingPoints = new TrackPoints(); TrackingReplay.TrackPoint oTrackingPoint; foreach (DataRow dr in trackingTable.Rows) { oTrackingPoint = new TrackPoint(); oTrackingPoint.ID = Int32.Parse(dr["geoid"].ToString()); oTrackingPoint.X = double.Parse(dr["x"].ToString()); oTrackingPoint.Y = double.Parse(dr["y"].ToString()); oTrackingPoint.TimeStamp = DateTime.Parse(dr["currenttime"].ToString()); oTrackingPoints.Add(oTrackingPoint); } return(oTrackingPoints); }
public void AddTrackingPath(TrackPoints pointsInTrackingPath) { MapObjects2.Line oTrackingPath = new MapObjects2.LineClass(); MapObjects2.Points oPoints = new MapObjects2.PointsClass(); foreach (TrackPoint item in pointsInTrackingPath) { MapObjects2.Point oPoint = new MapObjects2.PointClass(); oPoint.X = item.X; oPoint.Y = item.Y; oPoints.Add(oPoint); } oTrackingPath.Parts.Add(oPoints); this.AddTrackingPath(oTrackingPath); }
/// <summary> /// 获取计算结果 /// </summary> /// <returns>差值后的轨迹点集合</returns> public TrackPoints GetResultByInterpolateTime() { if (this._inputData == null) { throw new Exception("please check that you had initilized the property 'InputValue'."); } TrackPoints oResultPoints = null; try { oResultPoints = this.GetResultByInterpolateTime(this._inputData, this._baseIntervalTime); } catch (Exception ex) { throw new Exception(ex.StackTrace); } return(oResultPoints); }
/// <summary> /// 根据轨迹点集合来生成相对应的轨迹段集合 /// </summary> /// <param name="allPoints">轨迹点集合</param> /// <param name="segmentsInfos">轨迹段集合</param> private void GetSegmentInfos(TrackPoints allPoints, ref TrackSegments segmentsInfos) { int iPointsCount = allPoints.Count; double dCurDistance = 0; if (iPointsCount < 2) { throw new Exception("the count of points can not be less than 2"); } for (int i = 0; i < iPointsCount - 1; i++) { TrackPoint oPrePoint = new TrackPoint(); TrackPoint oNextPoint = new TrackPoint(); TrackSegment oSegInfos = new TrackSegment(); TimeSpan oTimeSpan = new TimeSpan(); oPrePoint = allPoints[i]; oNextPoint = allPoints[i + 1]; dCurDistance = this.ComputeDirectDistance(oPrePoint, oNextPoint); oTimeSpan = oNextPoint.TimeStamp.Subtract(oPrePoint.TimeStamp); oSegInfos.StartTrackPoint = oPrePoint; oSegInfos.EndTrackPoint = oNextPoint; oSegInfos.SegmentLenth = dCurDistance; oSegInfos.CourseTime = oTimeSpan.TotalMilliseconds; if (oSegInfos.CourseTime == 0) { oSegInfos.Speed = 0; } else { oSegInfos.Speed = oSegInfos.SegmentLenth / oSegInfos.CourseTime; } segmentsInfos.Add(oSegInfos); } }
public override void MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (UseErasePart) { gTopology.Graph graph = Graph; if (graph == null) { return; } Topology editor = new Topology(graph); Point pos = e.GetPosition(GraphContainer); gTopology.Line line = editor.LinHit(pos, Tolerance); if (line != null) { SelectLine = line; this.TrackAdorner.ClearPoint(); Point np = editor.LinNearestPoint(line, pos); TrackPoints.Add(np); np = GraphContainer.TranslatePoint(np, this.AssociatedObject); TrackAdorner.Track.Points.Add(np); OldTrackStyle = TrackAdorner.Track.Style; Style newstyle = new Style(); newstyle.Setters.Add(new Setter() { Property = Polyline.StrokeProperty, Value = new SolidColorBrush() { Color = Colors.LightBlue } }); newstyle.Setters.Add(new Setter() { Property = Polyline.StrokeThicknessProperty, Value = 3.0 }); TrackAdorner.Track.Style = newstyle; return; } } base.MouseLeftButtonDown(sender, e); }
private static TrackingReplay.TrackPoints ConvertDataTableToTrackingPoints(DataTable trackingTable, DateTime startTime, DateTime endTime) { TrackingReplay.TrackPoints oTrackingPoints = new TrackPoints(); TrackingReplay.TrackPoint oTrackingPoint; DateTime tCurTime; foreach (DataRow dr in trackingTable.Rows) { tCurTime = DateTime.Parse(dr["currenttime"].ToString()); if (!(tCurTime >= startTime && tCurTime <= endTime)) continue; oTrackingPoint = new TrackPoint(); oTrackingPoint.ID = Int32.Parse(dr["geoid"].ToString()); oTrackingPoint.X = double.Parse(dr["x"].ToString()); oTrackingPoint.Y = double.Parse(dr["y"].ToString()); oTrackingPoint.TimeStamp = tCurTime; oTrackingPoints.Add(oTrackingPoint); } return oTrackingPoints; }
/// <summary> /// 查找所有轨迹段中最短的轨迹段 /// </summary> /// <param name="AllPoints">所有的轨迹点</param> /// <returns>最短的轨迹段</returns> private TrackSegment FindLestTimeInSegments(TrackPoints AllPoints) { if (AllPoints == null || AllPoints.Count < 2) { return(null); } int iPointsCount = 0; double dTotalTime = 0; TrackSegment oSegResult = new TrackSegment(); TrackPoint oPrePoint = new TrackPoint(); TrackPoint oNextPoint = new TrackPoint(); iPointsCount = AllPoints.Count; oSegResult.CourseTime = this.ComputeTotalTime(AllPoints[0], AllPoints[1]); oSegResult.StartTrackPoint = AllPoints[0]; oSegResult.EndTrackPoint = AllPoints[1]; for (int i = 1; i < iPointsCount - 1; i++) { dTotalTime = this.ComputeTotalTime(AllPoints[i], AllPoints[i + 1]); if (dTotalTime > 0 && oSegResult.CourseTime > dTotalTime) { oSegResult.CourseTime = dTotalTime; oSegResult.StartTrackPoint = AllPoints[i]; oSegResult.EndTrackPoint = AllPoints[i + 1]; } } oSegResult.SegmentLenth = ComputeDirectDistance(oSegResult.StartTrackPoint, oSegResult.EndTrackPoint); oSegResult.Speed = oSegResult.SegmentLenth / oSegResult.CourseTime; return(oSegResult); }
/// <summary> /// Convert the list of points to a list of common coordinates /// </summary> /// <returns></returns> public List <GeoCoordinateExtended> ToCoords() => TrackPoints.Select(pt => pt.ToCoord()).ToList();
void Start() { instance = this; }
public GPSTrackReplay(TrackPoints inputPoints) { this._inputData = inputPoints; }
/////// <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); }