DrawDtoLineHelper.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 DrawDtoLineHelper
  11. {
  12. private const string exeName = "XingDiSCX.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)> DtoLineXd(DtoLineXdOption opt)
  21. {
  22. List<DtoLinePoint> list = new List<DtoLinePoint>();
  23. string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\时差线\\DtoLine.dat");
  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(file);
  34. arguments.Add($"{opt.MsEph[0]}");
  35. arguments.Add($"{opt.MsEph[1]}");
  36. arguments.Add($"{opt.MsEph[2]}");
  37. arguments.Add($"{opt.MsAnt[0]}");
  38. arguments.Add($"{opt.MsAnt[1]}");
  39. arguments.Add($"{opt.CDBAnt[0]}");
  40. arguments.Add($"{opt.CDBAnt[1]}");
  41. arguments.Add($"{opt.RefGeod[0]}");
  42. arguments.Add($"{opt.RefGeod[1]}");
  43. arguments.Add($"{opt.xdDto}");
  44. arguments.Add($"{opt.RefDto}");
  45. arguments.Add($"{opt.PosLon}");
  46. arguments.Add($"{opt.PosLat}");
  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. p.Start();
  56. var succeed = p.WaitForExit(10000);
  57. if (!succeed)
  58. {
  59. throw new Exception($"进程[{exeName}]超时未完成!");
  60. }
  61. string result = p.StandardOutput.ReadToEnd();
  62. if (string.IsNullOrWhiteSpace(result))
  63. {
  64. throw new Exception("计算时差线出现未知错误!");
  65. }
  66. var array = result.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  67. if (array[0] == "1")
  68. {
  69. throw new Exception(array[1]);
  70. }
  71. if (File.Exists(file))
  72. {
  73. var dtostr = File.ReadAllText(file);
  74. list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DtoLinePoint>>(dtostr);
  75. }
  76. var Lines = list.Select(s => (s.Lon, s.Lat));
  77. return Lines;
  78. }
  79. /// <summary>
  80. /// 星地双星时差线
  81. /// </summary>
  82. /// <param name="opt"></param>
  83. /// <returns></returns>
  84. public static IEnumerable<(double lon, double lat)> DtoLineXDTwoStart(DtoLineTwoStartOption opt)
  85. {
  86. List<DtoLinePoint> list = new List<DtoLinePoint>();
  87. IntPtr LOP_ValuePtr;
  88. int LOP_Len = 0;
  89. PosApi.CurveByTwoTDOA(
  90. opt.MsEph,
  91. opt.NsEph,
  92. opt.MsAnt,
  93. opt.NsAnt,
  94. opt.RefGeod,
  95. zone,
  96. opt.TargetDto * 1e-6,
  97. opt.RefDto * 1e-6, out LOP_ValuePtr, ref LOP_Len);
  98. double[] LOP_Value = new double[LOP_Len * 3];
  99. if (LOP_Len > 0)
  100. {
  101. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  102. list = OutputHelper.WriteDtoLine(LOP_Value, LOP_Len);
  103. }
  104. var Lines = list.Select(p => (p.Lon, p.Lat));
  105. return Lines;
  106. }
  107. private static IEnumerable<(double lon, double lat)> ParseResult(IntPtr LOP_ValuePtr, int LOP_Len)
  108. {
  109. List<DtoLinePoint> list = new List<DtoLinePoint>();
  110. double[] LOP_Value = new double[LOP_Len * 3];
  111. if (LOP_Len > 0)
  112. {
  113. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  114. for (int idx = 0; idx < LOP_Len; ++idx)
  115. {
  116. if (LOP_Value[3 * idx + 1] != -1)
  117. {
  118. list.Add(new DtoLinePoint()
  119. {
  120. Lon = LOP_Value[3 * idx + 1],
  121. Lat = LOP_Value[3 * idx]
  122. });
  123. }
  124. }
  125. for (int idx = 0; idx < LOP_Len; ++idx)
  126. {
  127. if (LOP_Value[3 * idx + 2] != -1)
  128. {
  129. list.Add(new DtoLinePoint()
  130. {
  131. Lon = LOP_Value[3 * idx + 2],
  132. Lat = LOP_Value[3 * idx]
  133. });
  134. }
  135. }
  136. }
  137. var Lines = list.Select(p => (p.Lon, p.Lat));
  138. return Lines;
  139. }
  140. }
  141. }