DrawDtoLineHelper.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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.Api
  10. {
  11. public class DrawDtoLineHelper
  12. {
  13. private const string XdtsDll = @"AddIns\时差线\Positioning.dll";
  14. //三星双时差带参、三星双时差无参、三星双频差带参、双星时频差带参、两星一地无参定位及时差线
  15. private const string xddtodll = @"AddIns\时差线\Position-New.dll";
  16. [DllImport(xddtodll, EntryPoint = "XingDi_SCX_NoRef", CallingConvention = CallingConvention.Cdecl)]//高轨双星有参时差线
  17. public extern static void XingDi_SCX_NoRef(double[] main_sat_pos, double[] mbwx_rec_pos, double[] cdb_rec_pos,
  18. double[] Zone, double target_dto, out IntPtr LOP_Value, ref int LOP_Len);
  19. [DllImport(XdtsDll, EntryPoint = "CurveByTwoTDOA", CallingConvention = CallingConvention.Cdecl)]//高轨双星有参时差线
  20. public extern static void CurveByTwoTDOA(double[] main_sat_pos, double[] neigh_sat_pos, double[] rec1_pos, double[] rec2_pos, double[] ref_pos, double[] Zone,
  21. double target_dto, double ref_dto, out IntPtr LOP_Value, ref int LOP_Len);
  22. /*
  23. 双星时差线-无参
  24. LOP_Value 返回值 结构参考DTO_Plot
  25. LOP_Len*3为LOP_Value的长度
  26. */
  27. [DllImport(XdtsDll, EntryPoint = "CurveByTwoTDOAWithNoRef", CallingConvention = CallingConvention.Cdecl)]//高轨双星无参时差线
  28. public extern static void CurveByTwoTDOAWithNoRef(double[] main_sat_pos, double[] neigh_sat_pos, double[] rec1_pos, double[] rec2_pos,
  29. double[] Zone, double target_dto, out IntPtr LOP_Value, ref int LOP_Len);
  30. [DllImport(XdtsDll, CallingConvention = CallingConvention.Cdecl)]
  31. public static extern void Destory(IntPtr val);
  32. private const string exeName = "XingDiSCX.exe";//星地时差线
  33. // private static double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  34. /// <summary>
  35. /// 星地有参时差线
  36. /// </summary>
  37. /// <param name="opt"></param>
  38. /// <returns></returns>
  39. /// <exception cref="Exception"></exception>
  40. public static IEnumerable<(double lon, double lat)> DtoLineXd(DtoLineXdOption opt)
  41. {
  42. List<DtoLinePoint> list = new List<DtoLinePoint>();
  43. string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AddIns\\时差线\\DtoLine.dat");
  44. string exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AddIns\\时差线");
  45. if (string.IsNullOrWhiteSpace(exePath))
  46. throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
  47. if (!Directory.Exists(exePath))
  48. throw new Exception($"路径[{exePath}]不存在");
  49. var exeFile = Path.Combine(exePath, exeName);
  50. if (!File.Exists(exeFile))
  51. throw new Exception($"文件[{exeFile}]不存在");
  52. List<string> arguments = new List<string>
  53. {
  54. file,
  55. $"{opt.MsEph[0]}",
  56. $"{opt.MsEph[1]}",
  57. $"{opt.MsEph[2]}",
  58. $"{opt.MsAnt[0]}",
  59. $"{opt.MsAnt[1]}",
  60. $"{opt.CDBAnt[0]}",
  61. $"{opt.CDBAnt[1]}",
  62. $"{opt.RefGeod[0]}",
  63. $"{opt.RefGeod[1]}",
  64. $"{opt.xdDto}",
  65. $"{opt.RefDto}",
  66. $"{opt.PosLon}",
  67. $"{opt.PosLat}"
  68. };
  69. Process p = new Process();
  70. p.StartInfo.WorkingDirectory = exePath;
  71. p.StartInfo.FileName = exeFile;
  72. p.StartInfo.Arguments = string.Join(" ", arguments);
  73. p.StartInfo.CreateNoWindow = true;
  74. p.StartInfo.RedirectStandardError = true;
  75. p.StartInfo.RedirectStandardOutput = true;
  76. p.StartInfo.UseShellExecute = false;
  77. p.Start();
  78. var succeed = p.WaitForExit(10000);
  79. if (!succeed)
  80. {
  81. throw new Exception($"进程[{exeName}]超时未完成!");
  82. }
  83. string result = p.StandardOutput.ReadToEnd();
  84. if (string.IsNullOrWhiteSpace(result))
  85. {
  86. throw new Exception("计算时差线出现未知错误!");
  87. }
  88. var array = result.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  89. if (array[0] == "1")
  90. {
  91. throw new Exception(array[1]);
  92. }
  93. if (File.Exists(file))
  94. {
  95. var dtostr = File.ReadAllText(file);
  96. list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DtoLinePoint>>(dtostr);
  97. }
  98. var Lines = list.Select(s => (s.Lon, s.Lat));
  99. return Lines;
  100. }
  101. /// <summary>
  102. /// 星地无参时差线
  103. /// </summary>
  104. /// <param name="opt"></param>
  105. /// <returns></returns>
  106. /// <exception cref="Exception"></exception>
  107. public static IEnumerable<(double lon, double lat)> DtoLineXdNoRef(DtoLineXdOption opt)
  108. {
  109. List<DtoLinePoint> list = new List<DtoLinePoint>();
  110. IntPtr LOP_ValuePtr;
  111. int LOP_Len = 0;
  112. XingDi_SCX_NoRef(opt.MsEph, opt.MsAnt, opt.CDBAnt,
  113. new double[] { -85, 85, -180, 180 }, opt.xdDto * 1e-6, out LOP_ValuePtr, ref LOP_Len);
  114. double[] LOP_Value = new double[LOP_Len * 3];
  115. if (LOP_Len > 0)
  116. {
  117. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  118. list = OutputHelper.WriteDtoLine(LOP_Value, LOP_Len);
  119. }
  120. var Lines = list.Select(p => (p.Lon, p.Lat));
  121. return Lines;
  122. }
  123. /// <summary>
  124. /// 星地有参时差线
  125. /// </summary>
  126. /// <param name="opt"></param>
  127. /// <returns></returns>
  128. /// <exception cref="Exception"></exception>
  129. public static IEnumerable<(double lon, double lat)> DtoLineXdEx(DtoLineXdOption opt)
  130. {
  131. List<DtoLinePoint> list = new List<DtoLinePoint>();
  132. IntPtr LOP_ValuePtr;
  133. int LOP_Len = 0;
  134. GDOPApi.SCX_XD(opt.MsEph, opt.MsAnt, opt.MsAnt, opt.CDBAnt, opt.RefGeod, opt.xdDto * 1e-6, opt.RefDto * 1e-6, ref LOP_Len, out LOP_ValuePtr);
  135. double[] LOP_Value = new double[LOP_Len];
  136. if (LOP_Len > 0)
  137. {
  138. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  139. }
  140. GDOPApi.FreeGDOPBuf(LOP_ValuePtr);
  141. var points = ParseResult(LOP_Value);
  142. var mapDots = points.Select(p => p).Select(p => (p.Lon, p.Lat));
  143. return mapDots;
  144. }
  145. private static List<MapDot> ParseResult(double[] ponits)
  146. {
  147. List<MapDot> mapDots = new List<MapDot>();
  148. int count = 2;
  149. for (int i = 0; i < ponits.Length / count; i++)
  150. {
  151. MapDot mapDot = new MapDot();
  152. mapDot.Lon = ponits[count * i];
  153. mapDot.Lat = ponits[count * i + 1];//0 1 2 3 4 5 6 7
  154. mapDots.Add(mapDot);
  155. }
  156. return mapDots;
  157. }
  158. /// <summary>
  159. /// 星地无参时差线
  160. /// </summary>
  161. /// <param name="opt"></param>
  162. /// <returns></returns>
  163. /// <exception cref="Exception"></exception>
  164. public static IEnumerable<(double lon, double lat)> DtoLineXdNoRefEx(DtoLineXdOption opt)
  165. {
  166. List<DtoLinePoint> list = new List<DtoLinePoint>();
  167. IntPtr LOP_ValuePtr;
  168. int LOP_Len = 0;
  169. GDOPApi.SCX_XD_NoRef(opt.MsEph, opt.MsAnt, opt.CDBAnt, opt.xdDto * 1e-6, ref LOP_Len, out LOP_ValuePtr);
  170. double[] LOP_Value = new double[LOP_Len];
  171. if (LOP_Len > 0)
  172. {
  173. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  174. }
  175. GDOPApi.FreeGDOPBuf(LOP_ValuePtr);
  176. var points = ParseResult(LOP_Value);
  177. var mapDots = points.Select(p => p).Select(p => (p.Lon, p.Lat));
  178. return mapDots;
  179. }
  180. /// <summary>
  181. /// 高轨双星时差线
  182. /// </summary>
  183. /// <param name="opt"></param>
  184. /// <returns></returns>
  185. public static IEnumerable<(double lon, double lat)> DtoLine2XStart(DtoLineTwoStartOption opt)
  186. {
  187. List<DtoLinePoint> list = new List<DtoLinePoint>();
  188. IntPtr LOP_ValuePtr;
  189. int LOP_Len = 0;
  190. CurveByTwoTDOA(
  191. opt.MsEph,
  192. opt.NsEph,
  193. opt.MsAnt,
  194. opt.NsAnt,
  195. opt.RefGeod,
  196. new double[] { -85, 85, -180, 180 },
  197. opt.TargetDto * 1e-6,
  198. opt.RefDto * 1e-6, out LOP_ValuePtr, ref LOP_Len);
  199. double[] LOP_Value = new double[LOP_Len * 3];
  200. if (LOP_Len > 0)
  201. {
  202. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  203. list = OutputHelper.WriteDtoLine(LOP_Value, LOP_Len);
  204. }
  205. Destory(LOP_ValuePtr);
  206. var Lines = list.Select(p => (p.Lon, p.Lat));
  207. return Lines;
  208. }
  209. public static IEnumerable<(double lon, double lat)> DtoLine2XNoRefStart(DtoLineTwoStartOption opt)
  210. {
  211. List<DtoLinePoint> list = new List<DtoLinePoint>();
  212. IntPtr LOP_ValuePtr;
  213. int LOP_Len = 0;
  214. CurveByTwoTDOAWithNoRef(
  215. opt.MsEph,
  216. opt.NsEph,
  217. opt.MsAnt,
  218. opt.NsAnt,
  219. new double[] { -85, 85, -180, 180 },
  220. opt.TargetDto * 1e-6, out LOP_ValuePtr, ref LOP_Len);
  221. double[] LOP_Value = new double[LOP_Len * 3];
  222. if (LOP_Len > 0)
  223. {
  224. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  225. list = OutputHelper.WriteDtoLine(LOP_Value, LOP_Len);
  226. }
  227. Destory(LOP_ValuePtr);
  228. var Lines = list.Select(p => (p.Lon, p.Lat));
  229. return Lines;
  230. }
  231. }
  232. }