Tle2XYZ.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace XdCxRhDW.App.Api.星历推算
  9. {
  10. /// <summary>
  11. /// 星历推算
  12. /// </summary>
  13. public static class Tle2XYZ
  14. {
  15. public static double[] GetXyz(String tle, DateTime dt)
  16. {
  17. var lines = tle.Split(';');
  18. var dz = new DateTime(1970, 1, 1, 8, 0, 0);
  19. Process p = new Process();
  20. p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "API\\星历推算\\Tle2XYZ.exe");
  21. //-a "1 23467U 95003A 22364.32362671 -.00000025 00000+0 00000+0 0 9992" -b "2 23467 9.8007 17.1777 0001795 205.8937 164.3833 1.00270390102276"
  22. ////-t 1672718400 -p 1 -c 1
  23. p.StartInfo.Arguments = $"-a \"{lines[0]}\" -b \"{lines[1]}\" -t {(dt-dz).TotalSeconds} -p 1 -c 1";
  24. p.StartInfo.CreateNoWindow = true;
  25. p.StartInfo.RedirectStandardError = true;
  26. p.StartInfo.RedirectStandardOutput = true;
  27. p.StartInfo.UseShellExecute = false;
  28. p.Start();
  29. p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
  30. var str = p.StandardOutput.ReadToEnd();
  31. //解析
  32. //23467,1672357561,1672718400,-41542540.907490,5369494.210104,-4850802.865098,-44.255811,10.624541,386.892634;
  33. str = str.Replace(';', ' ').Trim();
  34. var result = str.Split(',');
  35. double[] res = new double[6];
  36. for (int idx = 0; idx < 6; ++idx)
  37. {
  38. res[idx] = Convert.ToDouble(result[idx + 3]);
  39. }
  40. return res;
  41. }
  42. }
  43. }