/// <summary> /// Create a Trajectory object with the data found in the given file /// </summary> /// <param name="filepath">the file of which the data should be read</param> /// <returns>a Trajectory object</returns> public Trajectory CreateTrajectoryFromFile(string filepath) { readFromFile(filepath); double t = 0; double previousV = 0; Point3D previousPoint = null; foreach (double[] row in _trackData) { if (row.Length == 0) { continue; } var currentPoint = new Point3D(row[0], row[1], row[2], CoordinateUnits); var metricPoint = currentPoint.ConvertTo(CoordinateUnit.metric); var currentV = row[3]; if (previousPoint != null) { t += previousPoint.DistanceTo(metricPoint) / ((currentV + previousV) / 2); } _trajectoryGenerator.AddDatapoint(metricPoint.X, metricPoint.Y, metricPoint.Z, row[3], row[4], t); previousPoint = currentPoint; previousV = currentV; } Trajectory trajectory = _trajectoryGenerator.GenerateTrajectory(); return(trajectory); }
public List <Trajectory> CreateFromFile(string filePath, ReferencePoint referencePoint) { // Parse the file containing multiple trajectories string rawTrackData = File.ReadAllText(filePath); var _trackData = rawTrackData .Split('\n') .Select(q => q.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(Convert.ToString) .ToArray() ) .ToArray(); // Define variables DateTime t0 = DateTime.Parse(_trackData[0][14]); string flight_id = ""; var trajectories = new List <Trajectory>(); TrajectoryGenerator trajectoryGenerator = new TrajectoryGenerator(new Aircraft("GP7270", "wing"), referencePoint); // Loop through the positions of all trajectories for (int i = 0; i < _trackData.Length; i++) { // Switch to the next trajectory if (i == _trackData.Length - 1 || (_trackData[i][0] != flight_id && i > 0)) { Trajectory trajectory = trajectoryGenerator.GenerateTrajectory(); _minX = (int)Math.Min(trajectory.LowerLeftPoint.X, _minX); _minY = (int)Math.Min(trajectory.LowerLeftPoint.Y, _minY); _maxX = (int)Math.Max(trajectory.UpperRightPoint.X, _maxX); _maxY = (int)Math.Max(trajectory.UpperRightPoint.X, _maxY); trajectories.Add(trajectory); // Prepare next trajectory t0 = DateTime.Parse(_trackData[i][14]); var aircraft = new Aircraft("GP7270", "wing"); trajectoryGenerator = new TrajectoryGenerator(aircraft, referencePoint); } // Prevent failing on empty lines if (_trackData[i].Count() == 0) { continue; } flight_id = _trackData[i][0]; // Parse the next position of the current trajectory double x = 0; double.TryParse(_trackData[i][4], out x); x = x * 14.46875; double y = 0; double.TryParse(_trackData[i][5], out y); y = y * 14.46875; double z = 0; double.TryParse(_trackData[i][6], out z); z = z * 0.3040 * 100; DateTime t = DateTime.Parse(_trackData[i][14]); double time = t.Subtract(t0).TotalSeconds; trajectoryGenerator.AddDatapoint(x, y, z, 200, 60000, time); } return(trajectories); }