/// <summary> /// Convert the path to sensor data. /// </summary> /// <returns></returns> private Task ConvertPathToSensorData() { return Task.Run(() => { // Initialize poi sensors if (PoI.Sensors == null) PoI.Sensors = new SensorSet(); csEvents.Sensors.DataSet dataSet; PoI.Sensors.TryRemove(KeyLongitude, out dataSet); PoI.Sensors.TryRemove(KeyLatitude, out dataSet); PoI.Sensors.TryRemove(KeyAnimateMove, out dataSet); PoI.Sensors.TryRemove(KeyOrientationSensor, out dataSet); foreach (var link in Links) { DateTime startTime, endTime; if (!DateTime.TryParse(link.Labels[KeyLabelStartTime], CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out startTime)) return; if (!DateTime.TryParse(link.Labels[KeyLabelEndTime ], CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out endTime)) return; var totalLength = 0d; var numberOfPoints = link.Points.Count - 1; if (numberOfPoints < 1) continue; var segmentLengths = new double[numberOfPoints]; for (var i = 0; i < numberOfPoints; i++) { var p1 = link.Points[i]; var p2 = link.Points[i + 1]; segmentLengths[i] = ComputeLengthOfSegment(p1, p2); totalLength += segmentLengths[i]; } link.Labels[KeyLabelDistance] = totalLength.ToString(CultureInfo.InvariantCulture); var curTime = startTime; // Interpolate linearly along the path between p1 and p2 if (totalLength>0) for (var i = 0; i < numberOfPoints; i++) { var p1 = link.Points[i]; var p2 = link.Points[i + 1]; var lengthOfCurrentSegment = segmentLengths[i]; var durationOfCurrentSegment = TimeSpan.FromTicks((long)((endTime - startTime).Ticks * lengthOfCurrentSegment / totalLength)); var endTimeOfCurrentSegment = curTime + durationOfCurrentSegment; var heading = new Vector(p2.X - p1.X, p2.Y - p1.Y) / durationOfCurrentSegment.TotalSeconds; var currentPoint = p1; PoI.SetSensorValue(curTime, KeyOrientationSensor, heading.ToAngleInDegrees()); PoI.SetSensorValue(curTime, KeyAnimateMove, link.Labels.ContainsKey(KeyAnimateMove) ? animations.IndexOf(link.Labels[KeyAnimateMove]) : 0); for (var t = curTime; t < endTimeOfCurrentSegment; t += TimeSpan.FromSeconds(1)) { PoI.SetSensorValue(t, KeyLongitude, currentPoint.X); PoI.SetSensorValue(t, KeyLatitude, currentPoint.Y); currentPoint += heading; // NOTE: Assumes a stepsize of 1 second } // Reset counters curTime = endTimeOfCurrentSegment; } } //Model.Service.HasSensorData = PoI.Sensors.ContainsKey(KeyLongitude); }); }