DrawDfoLineHelper.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.App.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, "API\\频差线");
  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. arguments.Add("dfoline");
  34. arguments.Add($"{opt.TargetDfo}");
  35. arguments.Add($"{opt.Freq * 1e-6}");
  36. arguments.Add($"{opt.Turn1 * 1e-6}");
  37. arguments.Add($"{opt.Turn2 * 1e-6}");
  38. arguments.Add($"--rec1 {opt.MsAnt[0]} {opt.MsAnt[1]} 0");
  39. arguments.Add($"--rec2 {opt.NsAnt[0]} {opt.NsAnt[1]} 0");
  40. arguments.Add($"--eph1 {opt.MsEph[0]} {opt.MsEph[1]} {opt.MsEph[2]} {opt.MsEph[3]} {opt.MsEph[4]} {opt.MsEph[5]}");
  41. arguments.Add($"--eph2 {opt.NsEph[0]} {opt.NsEph[1]} {opt.NsEph[2]} {opt.NsEph[3]} {opt.NsEph[4]} {opt.NsEph[5]}");
  42. arguments.Add($"--refdf {opt.RefDfo}");
  43. arguments.Add($"--reffreq {opt.RefFreq * 1e-6}");
  44. arguments.Add($"--reflla {opt.RefGeod[0]} {opt.RefGeod[1]} 0");
  45. Process p = new Process();
  46. p.StartInfo.WorkingDirectory = exePath;
  47. p.StartInfo.FileName = exeFile;
  48. p.StartInfo.Arguments = string.Join(" ", arguments);
  49. p.StartInfo.CreateNoWindow = true;
  50. p.StartInfo.RedirectStandardError = true;
  51. p.StartInfo.RedirectStandardOutput = true;
  52. p.StartInfo.UseShellExecute = false;
  53. StringBuilder sb = new StringBuilder();
  54. p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
  55. p.Start();
  56. p.BeginOutputReadLine();
  57. p.WaitForExit();
  58. if (string.IsNullOrWhiteSpace(sb.ToString()))
  59. {
  60. throw new Exception("计算频差线出现未知错误!");
  61. }
  62. var array = sb.ToString().Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  63. foreach (var item in array)
  64. {
  65. var strs = item.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  66. DfoLinePoint point = new DfoLinePoint();
  67. point.Lon = Convert.ToDouble(strs[0]);
  68. point.Lat = Convert.ToDouble(strs[1]);
  69. list.Add(point);
  70. }
  71. var Lines = list.Select(s => (s.Lon, s.Lat));
  72. return Lines;
  73. }
  74. }
  75. }