DrawDfoLineHelper.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. namespace XdCxRhDW.Api
  10. {
  11. public class DrawDfoLineHelper
  12. {
  13. private const string exeName = "locow.exe";
  14. private static double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  15. /// <summary>
  16. /// 高轨双星频差线
  17. /// </summary>
  18. /// <param name="opt"></param>
  19. /// <returns></returns>
  20. /// <exception cref="Exception"></exception>
  21. public static IEnumerable<(double lon, double lat)> DfoLineTwoStart(DfoLineTwoStartOption opt)
  22. {
  23. List<DfoLinePoint> list = new List<DfoLinePoint>();
  24. string exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AddIns\\频差线");
  25. if (string.IsNullOrWhiteSpace(exePath))
  26. throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
  27. if (!Directory.Exists(exePath))
  28. throw new Exception($"路径[{exePath}]不存在");
  29. var exeFile = Path.Combine(exePath, exeName);
  30. if (!File.Exists(exeFile))
  31. throw new Exception($"文件[{exeFile}]不存在");
  32. List<string> arguments = new List<string>
  33. {
  34. "dfoline",
  35. $"{opt.TargetDfo}",
  36. $"{opt.Freq * 1e-6}",
  37. $"{opt.Turn1 * 1e-6}",
  38. $"{opt.Turn2 * 1e-6}",
  39. $"--rec1 {opt.MsAnt[0]} {opt.MsAnt[1]} 0",
  40. $"--rec2 {opt.NsAnt[0]} {opt.NsAnt[1]} 0",
  41. $"--eph1 {opt.MsEph[0]} {opt.MsEph[1]} {opt.MsEph[2]} {opt.MsEph[3]} {opt.MsEph[4]} {opt.MsEph[5]}",
  42. $"--eph2 {opt.NsEph[0]} {opt.NsEph[1]} {opt.NsEph[2]} {opt.NsEph[3]} {opt.NsEph[4]} {opt.NsEph[5]}",
  43. $"--refdf {opt.RefDfo}",
  44. $"--reffreq {opt.RefFreq * 1e-6}",
  45. $"--reflla {opt.RefGeod[0]} {opt.RefGeod[1]} 0"
  46. };
  47. Process p = new Process();
  48. p.StartInfo.WorkingDirectory = exePath;
  49. p.StartInfo.FileName = exeFile;
  50. p.StartInfo.Arguments = string.Join(" ", arguments);
  51. p.StartInfo.CreateNoWindow = true;
  52. p.StartInfo.RedirectStandardError = true;
  53. p.StartInfo.RedirectStandardOutput = true;
  54. p.StartInfo.UseShellExecute = false;
  55. StringBuilder sb = new StringBuilder();
  56. p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
  57. p.Start();
  58. p.BeginOutputReadLine();
  59. p.WaitForExit();
  60. if (string.IsNullOrWhiteSpace(sb.ToString()))
  61. {
  62. throw new Exception("计算频差线出现未知错误!");
  63. }
  64. var array = sb.ToString().Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  65. foreach (var item in array)
  66. {
  67. var strs = item.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  68. DfoLinePoint point = new DfoLinePoint();
  69. point.Lon = Convert.ToDouble(strs[0]);
  70. point.Lat = Convert.ToDouble(strs[1]);
  71. list.Add(point);
  72. }
  73. var Lines = list.Select(s => (s.Lon, s.Lat));
  74. return Lines;
  75. }
  76. }
  77. }