DrawDtoLineHelper.cs 8.4 KB

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