DrawDfoLineHelper.cs 3.5 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. namespace XdCxRhDW.App.Api
  9. {
  10. public class DrawDfoLineHelper
  11. {
  12. private const string exeName = "locow.exe";
  13. private static double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  14. /// <summary>
  15. /// 高轨双星频差线
  16. /// </summary>
  17. /// <param name="opt"></param>
  18. /// <returns></returns>
  19. /// <exception cref="Exception"></exception>
  20. public static IEnumerable<(double lon, double lat)> DfoLineTwoStart(DfoLineTwoStartOption opt)
  21. {
  22. List<DfoLinePoint> list = new List<DfoLinePoint>();
  23. string exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\频差线");
  24. if (string.IsNullOrWhiteSpace(exePath))
  25. throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
  26. if (!Directory.Exists(exePath))
  27. throw new Exception($"路径[{exePath}]不存在");
  28. var exeFile = Path.Combine(exePath, exeName);
  29. if (!File.Exists(exeFile))
  30. throw new Exception($"文件[{exeFile}]不存在");
  31. List<string> arguments = new List<string>();
  32. arguments.Add("dfoline");
  33. arguments.Add($"{opt.TargetDfo}");
  34. arguments.Add($"{opt.Freq * 1e6}");
  35. arguments.Add($"{opt.Turn1 * 1e6}");
  36. arguments.Add($"{opt.Turn2 * 1e6}");
  37. arguments.Add($"--rec1 {opt.MsAnt[0]} {opt.MsAnt[1]} 0");
  38. arguments.Add($"--rec1 {opt.NsAnt[0]} {opt.NsAnt[1]} 0");
  39. arguments.Add($"--eph1 {opt.MsEph[0]} {opt.MsEph[1]} {opt.MsEph[2]} {opt.MsEph[3]} {opt.MsEph[4]} {opt.MsEph[5]}");
  40. arguments.Add($"--eph1 {opt.NsEph[0]} {opt.NsEph[1]} {opt.NsEph[2]} {opt.NsEph[3]} {opt.NsEph[4]} {opt.NsEph[5]}");
  41. arguments.Add($"--refdf {opt.RefDfo}");
  42. arguments.Add($"--reffreq {opt.RefFreq * 1e6}");
  43. arguments.Add($"--reflla {opt.RefGeod[0]} {opt.RefGeod[0]} 0");
  44. Process p = new Process();
  45. p.StartInfo.WorkingDirectory = exePath;
  46. p.StartInfo.FileName = exeFile;
  47. p.StartInfo.Arguments = string.Join(" ", arguments);
  48. p.StartInfo.CreateNoWindow = true;
  49. p.StartInfo.RedirectStandardError = true;
  50. p.StartInfo.RedirectStandardOutput = true;
  51. p.StartInfo.UseShellExecute = false;
  52. p.Start();
  53. var succeed = p.WaitForExit(10000);
  54. if (!succeed)
  55. {
  56. throw new Exception($"进程[{exeName}]超时未完成!");
  57. }
  58. string result = p.StandardOutput.ReadToEnd();
  59. if (string.IsNullOrWhiteSpace(result))
  60. {
  61. throw new Exception("计算频差线出现未知错误!");
  62. }
  63. var array = result.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  64. if (array[0] == "1")
  65. {
  66. throw new Exception(array[1]);
  67. }
  68. //if (File.Exists(file))
  69. //{
  70. // var dtostr = File.ReadAllText(file);
  71. // list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DfoLinePoint>>(dtostr);
  72. //}
  73. var Lines = list.Select(s => (s.Lon, s.Lat));
  74. return Lines;
  75. }
  76. }
  77. }