DrawDtoLineHelper.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. #region 未使用
  13. /*
  14. static double[] HandleX2D1(X2D1Option opt)
  15. {
  16. var target_llh = DLL_LXYDApi.XingDi_DW(
  17. opt.MsEph
  18. , opt.NsEph
  19. , opt.MsAnt
  20. , opt.NsAnt
  21. , opt.CDBMsAnt
  22. , opt.CDBAnt
  23. , opt.RefGeod
  24. , opt.Zone
  25. , opt.SxDto * 1e-6
  26. , opt.xdDto * 1e-6
  27. , -opt.SampMsDto * 1e-6
  28. , -opt.SampNsDto * 1e-6
  29. , -opt.CDBpMsDto * 1e-6
  30. );
  31. double[] result = new double[6];
  32. Marshal.Copy(target_llh, result, 0, result.Length);
  33. return result;
  34. }
  35. static void HandleX1D2(X1D2Option opt)
  36. {
  37. var target_llh = DLL_YXLDApi.XingDi_DW_YXLD(
  38. opt.MsEph
  39. , opt.Ms1Ant
  40. , opt.Ms2Ant
  41. , opt.Nd1Ant
  42. , opt.Nd2Ant
  43. , opt.RefGeod1
  44. , opt.RefGeod2
  45. , opt.Zone
  46. , opt.DtXd1 * 1e-6
  47. , opt.DtXd2 * 1e-6
  48. , -opt.DtRef1 * 1e-6
  49. , -opt.DtRef2 * 1e-6
  50. );
  51. double[] result = new double[6];
  52. Marshal.Copy(target_llh, result, 0, result.Length);
  53. // OutputHelper.WritePos(result);
  54. }
  55. */
  56. #endregion
  57. private const string exeName = "XingDiSCX.exe";
  58. private static double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  59. /// <summary>
  60. /// 星地时差线
  61. /// </summary>
  62. /// <param name="opt"></param>
  63. /// <returns></returns>
  64. /// <exception cref="Exception"></exception>
  65. public static IEnumerable<(double lon, double lat)> DtoLineXd(DtoLineXdOption opt)
  66. {
  67. List<DtoLinePoint> list = new List<DtoLinePoint>();
  68. string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\时差线\\DtoLine.dat");
  69. string exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\时差线");
  70. if (string.IsNullOrWhiteSpace(exePath))
  71. throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
  72. if (!Directory.Exists(exePath))
  73. throw new Exception($"路径[{exePath}]不存在");
  74. var exeFile = Path.Combine(exePath, exeName);
  75. if (!File.Exists(exeFile))
  76. throw new Exception($"文件[{exeFile}]不存在");
  77. List<string> arguments = new List<string>();
  78. arguments.Add(file);
  79. arguments.Add($"{opt.MsEph[0]}");
  80. arguments.Add($"{opt.MsEph[1]}");
  81. arguments.Add($"{opt.MsEph[2]}");
  82. arguments.Add($"{opt.MsAnt[0]}");
  83. arguments.Add($"{opt.MsAnt[1]}");
  84. arguments.Add($"{opt.CDBAnt[0]}");
  85. arguments.Add($"{opt.CDBAnt[1]}");
  86. arguments.Add($"{opt.RefGeod[0]}");
  87. arguments.Add($"{opt.RefGeod[1]}");
  88. arguments.Add($"{opt.xdDto}");
  89. arguments.Add($"{opt.RefDto}");
  90. arguments.Add($"{opt.PosLon}");
  91. arguments.Add($"{opt.PosLat}");
  92. Process p = new Process();
  93. p.StartInfo.WorkingDirectory = exePath;
  94. p.StartInfo.FileName = exeFile;
  95. p.StartInfo.Arguments = string.Join(" ", arguments);
  96. p.StartInfo.CreateNoWindow = true;
  97. p.StartInfo.RedirectStandardError = true;
  98. p.StartInfo.RedirectStandardOutput = true;
  99. p.StartInfo.UseShellExecute = false;
  100. p.Start();
  101. var succeed = p.WaitForExit(10000);
  102. if (!succeed)
  103. {
  104. throw new Exception($"进程[{exeName}]超时未完成!");
  105. }
  106. string result = p.StandardOutput.ReadToEnd();
  107. if (string.IsNullOrWhiteSpace(result))
  108. {
  109. throw new Exception("计算时差线出现未知错误!");
  110. }
  111. var array = result.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  112. if (array[0] == "1")
  113. {
  114. throw new Exception(array[1]);
  115. }
  116. if (File.Exists(file))
  117. {
  118. var dtostr = File.ReadAllText(file);
  119. list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DtoLinePoint>>(dtostr);
  120. }
  121. var Lines = list.Select(s => (s.Lon, s.Lat));
  122. return Lines;
  123. }
  124. /// <summary>
  125. /// 星地双星时差线
  126. /// </summary>
  127. /// <param name="opt"></param>
  128. /// <returns></returns>
  129. public static IEnumerable<(double lon, double lat)> DtoLineXDTwoStart(DtoLineTwoStartOption opt)
  130. {
  131. List<DtoLinePoint> list = new List<DtoLinePoint>();
  132. IntPtr LOP_ValuePtr;
  133. int LOP_Len = 0;
  134. PosApi.CurveByTwoTDOA(
  135. opt.MsEph,
  136. opt.NsEph,
  137. opt.MsAnt,
  138. opt.NsAnt,
  139. opt.RefGeod,
  140. zone,
  141. opt.TargetDto * 1e-6,
  142. opt.RefDto * 1e-6, out LOP_ValuePtr, ref LOP_Len);
  143. double[] LOP_Value = new double[LOP_Len * 3];
  144. if (LOP_Len > 0)
  145. {
  146. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  147. list = OutputHelper.WriteDtoLine(LOP_Value, LOP_Len);
  148. }
  149. var Lines = list.Select(p => (p.Lon, p.Lat));
  150. return Lines;
  151. }
  152. private static IEnumerable<(double lon, double lat)> ParseResult(IntPtr LOP_ValuePtr, int LOP_Len)
  153. {
  154. List<DtoLinePoint> list = new List<DtoLinePoint>();
  155. double[] LOP_Value = new double[LOP_Len * 3];
  156. if (LOP_Len > 0)
  157. {
  158. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  159. for (int idx = 0; idx < LOP_Len; ++idx)
  160. {
  161. if (LOP_Value[3 * idx + 1] != -1)
  162. {
  163. list.Add(new DtoLinePoint()
  164. {
  165. Lon = LOP_Value[3 * idx + 1],
  166. Lat = LOP_Value[3 * idx]
  167. });
  168. }
  169. }
  170. for (int idx = 0; idx < LOP_Len; ++idx)
  171. {
  172. if (LOP_Value[3 * idx + 2] != -1)
  173. {
  174. list.Add(new DtoLinePoint()
  175. {
  176. Lon = LOP_Value[3 * idx + 2],
  177. Lat = LOP_Value[3 * idx]
  178. });
  179. }
  180. }
  181. }
  182. var Lines = list.Select(p => (p.Lon, p.Lat));
  183. return Lines;
  184. }
  185. }
  186. }