ErrEllipseHepler.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using DPP_YH_Core.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using XdCxRhDW.Dto;
  10. namespace XdCxRhDW.Api
  11. {
  12. /// <summary>
  13. /// 误差椭圆帮助类
  14. /// </summary>
  15. public static class ErrEllipseHepler
  16. {
  17. private const string ErrellipDll = @"AddIns\GDOP误差椭圆\DLL_GDOP_Analysis0623";
  18. /// <summary>
  19. /// 两星一地带参误差椭圆
  20. /// </summary>
  21. /// <param name="main_eph">主星星历 长度3</param>
  22. /// <param name="neigh_eph">邻星星历 长度3</param>
  23. /// <param name="cdbAnt">超短站位置 长度3</param>
  24. /// <param name="refStation">参考站位置 长度3</param>
  25. /// <param name="Select_Point">定位点经纬高 长度3</param>
  26. /// <param name="dto_err">时差误差(s)</param>
  27. /// <param name="eph_err">星历误差(m)</param>
  28. /// <param name="Pe">概率,范围(0,1),默认0.5</param>
  29. /// <param name="LOP_Len">输出参数</param>
  30. /// <returns></returns>
  31. [DllImport(ErrellipDll, EntryPoint = "Error_Ellipse_2X1D", CallingConvention = CallingConvention.Cdecl)]
  32. private extern static IntPtr Error_Ellipse_2X1D(double[] main_eph, double[] neigh_eph, double[] cdbAnt, double[] refStation, double[] Select_Point, double dto_err,
  33. double eph_err, double Pe, ref int LOP_Len);
  34. /// <summary>
  35. /// 两星一地误差椭圆
  36. /// </summary>
  37. /// <param name="main_eph">主星位置 长度3</param>
  38. /// <param name="neigh_eph">邻星位置 长度3</param>
  39. /// <param name="cdbAnt">超短波 长度3</param>
  40. /// <param name="refStation">参考站 长度3</param>
  41. /// <param name="Select_Point">定位点 长度3</param>
  42. /// <param name="dto_err">时差误差(s)</param>
  43. /// <param name="eph_err">星历误差(m)</param>
  44. /// <param name="Pe">0.5</param>
  45. /// <param name="LOP_Len"></param>
  46. /// <returns></returns>
  47. [DllImport(ErrellipDll, EntryPoint = "Error_Ellipse_2X1D_NoRef", CallingConvention = CallingConvention.Cdecl)]
  48. private extern static IntPtr Error_Ellipse_2X1D_NoRef(double[] main_eph, double[] neigh_eph, double[] cdbAnt, double[] Select_Point, double dto_err,
  49. double eph_err, double Pe, ref int LOP_Len);
  50. /// <summary>
  51. /// 三星带参误差椭圆(高轨和低轨是一样的)
  52. /// </summary>
  53. /// <param name="main_eph">主星位置 长度3</param>
  54. /// <param name="neigh_eph1">邻星1位置 长度3</param>
  55. /// <param name="neigh_eph2">邻星2位置 长度3</param>
  56. /// <param name="RefGeod">参考站 长度3</param>
  57. /// <param name="refStation">参考站 长度3</param>
  58. /// <param name="Select_Point">定位点 长度3</param>
  59. /// <param name="dto_err">时差误差(s)</param>
  60. /// <param name="eph_err">星历误差(m)</param>
  61. /// <param name="Pe">0.5</param>
  62. /// <param name="LOP_Len"></param>
  63. /// <returns></returns>
  64. [DllImport(ErrellipDll, EntryPoint = "Error_Ellipse_3X_2DTO", CallingConvention = CallingConvention.Cdecl)]
  65. private extern static IntPtr Error_Ellipse_3X_2DTO(double[] main_eph, double[] neigh_eph1, double[] neigh_eph2, double[] RefGeod, double[] Select_Point, double dto_err,
  66. double eph_err, double Pe, ref int LOP_Len);
  67. /// <summary>
  68. /// 三星无参误差椭圆(高轨和低轨是一样的)
  69. /// </summary>
  70. /// <param name="main_eph">主星位置 长度3</param>
  71. /// <param name="neigh_eph1">邻星1位置 长度3</param>
  72. /// <param name="neigh_eph2">邻星2位置 长度3</param>
  73. /// <param name="refStation">参考站 长度3</param>
  74. /// <param name="Select_Point">定位点 长度3</param>
  75. /// <param name="dto_err">时差误差(s)</param>
  76. /// <param name="eph_err">星历误差(m)</param>
  77. /// <param name="Pe">0.5</param>
  78. /// <param name="LOP_Len"></param>
  79. /// <returns></returns>
  80. [DllImport(ErrellipDll, EntryPoint = "Error_Ellipse_3X_NoRef", CallingConvention = CallingConvention.Cdecl)]
  81. private extern static IntPtr Error_Ellipse_3X_2DTONoRef(double[] main_eph, double[] neigh_eph1, double[] neigh_eph2, double[] Select_Point, double dto_err,
  82. double eph_err, double Pe, ref int LOP_Len);
  83. /// <summary>
  84. /// 两星一地带参误差椭圆
  85. /// </summary>
  86. /// <param name="posLon">定位点经度</param>
  87. /// <param name="posLat">定位点纬度</param>
  88. /// <param name="mainEph">主星xyz,长度=3</param>
  89. /// <param name="adjaEph">邻星xyz,长度=3</param>
  90. /// <param name="cdbPos">超短波位置(长度=2或3)</param>
  91. /// <param name="RefGeod">参考站位置(长度=2或3)</param>
  92. /// <param name="DtoErrus">时差误差(us)</param>
  93. /// <param name="EphErrm">星历误差(m)</param>
  94. /// <param name="outputErrPoint">是否输出椭圆Geo点</param>
  95. /// <param name="pe">概率(范围0-1,默认0.5)</param>
  96. /// <returns></returns>
  97. public static ErrEllipseResDto ErrorEllipse2X1D(double posLon, double posLat, double[] mainEph, double[] adjaEph, double[] cdbPos, double[] RefGeod, double DtoErrus, double EphErrm, bool outputErrPoint, double pe = 0.5)
  98. {
  99. if (cdbPos.Length == 2)
  100. {
  101. cdbPos = cdbPos.Concat(new double[1] { 0 }).ToArray();
  102. }
  103. if (RefGeod.Length == 2)
  104. {
  105. RefGeod = RefGeod.Concat(new double[1] { 0 }).ToArray();
  106. }
  107. int LOP_Len = 0;
  108. IntPtr LOP_ValuePtr = Error_Ellipse_2X1D(
  109. mainEph,
  110. adjaEph,
  111. cdbPos,
  112. RefGeod,
  113. new double[3] { posLon, posLat, 0 },
  114. DtoErrus * 1e-6,
  115. EphErrm,//单位m
  116. pe, ref LOP_Len);
  117. double[] LOP_Value = new double[LOP_Len];
  118. if (LOP_Len > 0)
  119. {
  120. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  121. }
  122. ErrEllipseResDto res = new ErrEllipseResDto();
  123. res.LongRadius = LOP_Value[LOP_Value.Length - 3];
  124. res.ShortRadius = LOP_Value[LOP_Value.Length - 2];
  125. res.DipAngle = LOP_Value[LOP_Value.Length - 1];
  126. if (outputErrPoint)
  127. {
  128. int count = LOP_Value.Length - 3;
  129. for (int i = 0; i < count; i += 2)
  130. {
  131. res.GeoPoints.Add(new GeoPoint()
  132. {
  133. Lon = LOP_Value[i],
  134. Lat = LOP_Value[i + 1],
  135. });
  136. }
  137. }
  138. return res;
  139. }
  140. /// <summary>
  141. /// 两星一地无参误差椭圆
  142. /// </summary>
  143. /// <param name="posLon">定位点经度</param>
  144. /// <param name="posLat">定位点纬度</param>
  145. /// <param name="mainEph">主星xyz,长度=3</param>
  146. /// <param name="adjaEph">邻星xyz,长度=3</param>
  147. /// <param name="cdbPos">超短波位置(长度=2或3)</param>
  148. /// <param name="DtoErrus">时差误差(us)</param>
  149. /// <param name="EphErrm">星历误差(m)</param>
  150. /// <param name="outputErrPoint">是否输出椭圆Geo点</param>
  151. /// <param name="pe">概率(范围0-1,默认0.5)</param>
  152. /// <returns></returns>
  153. public static ErrEllipseResDto ErrorEllipse2X1DNoRef(double posLon, double posLat, double[] mainEph, double[] adjaEph, double[] cdbPos, double DtoErrus, double EphErrm, bool outputErrPoint, double pe = 0.5)
  154. {
  155. if (cdbPos.Length == 2)
  156. {
  157. cdbPos = cdbPos.Concat(new double[1] { 0 }).ToArray();
  158. }
  159. int LOP_Len = 0;
  160. double Pe = 0.5;
  161. IntPtr LOP_ValuePtr = Error_Ellipse_2X1D_NoRef(
  162. mainEph,
  163. adjaEph,
  164. cdbPos,
  165. new double[3] { posLon, posLat, 0 },
  166. DtoErrus * 1e-6,
  167. EphErrm,//单位m
  168. Pe, ref LOP_Len);
  169. double[] LOP_Value = new double[LOP_Len];
  170. if (LOP_Len > 0)
  171. {
  172. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  173. }
  174. ErrEllipseResDto res = new ErrEllipseResDto();
  175. res.LongRadius = LOP_Value[LOP_Value.Length - 3];
  176. res.ShortRadius = LOP_Value[LOP_Value.Length - 2];
  177. res.DipAngle = LOP_Value[LOP_Value.Length - 1];
  178. if (outputErrPoint)
  179. {
  180. int count = LOP_Value.Length - 3;
  181. for (int i = 0; i < count; i += 2)
  182. {
  183. res.GeoPoints.Add(new GeoPoint()
  184. {
  185. Lon = LOP_Value[i],
  186. Lat = LOP_Value[i + 1],
  187. });
  188. }
  189. }
  190. return res;
  191. }
  192. /// <summary>
  193. /// 三星双时差带参误差椭圆(高轨和低轨是一样的)
  194. /// </summary>
  195. /// <param name="posLon">定位点经度</param>
  196. /// <param name="posLat">定位点纬度</param>
  197. /// <param name="mainEph">主星xyz,长度=3</param>
  198. /// <param name="adja1Eph">邻1星xyz,长度=3</param>
  199. /// <param name="adja2Eph">邻2星xyz,长度=3</param>
  200. /// <param name="RefGeod">参考站位置(长度=2或3)</param>
  201. /// <param name="dtoErrus">时差误差(us)</param>
  202. /// <param name="ephErrm">星历误差(m)</param>
  203. /// <param name="outputErrPoint">是否输出椭圆Geo点</param>
  204. /// <param name="pe">概率(范围0-1,默认0.5)</param>
  205. /// <returns></returns>
  206. public static ErrEllipseResDto ErrorEllipseX3(double posLon, double posLat, double[] mainEph, double[] adja1Eph, double[] adja2Eph,
  207. double[] RefGeod, double dtoErrus, double ephErrm, bool outputErrPoint, double pe = 0.5)
  208. {
  209. if (RefGeod.Length == 2)
  210. {
  211. RefGeod = RefGeod.Concat(new double[1] { 0 }).ToArray();
  212. }
  213. int LOP_Len = 0;
  214. IntPtr LOP_ValuePtr = Error_Ellipse_3X_2DTO(
  215. mainEph,
  216. adja1Eph,
  217. adja2Eph,
  218. RefGeod,
  219. new double[3] { posLon, posLat, 0 },
  220. dtoErrus * 1e-6,
  221. ephErrm,
  222. pe, ref LOP_Len);
  223. double[] LOP_Value = new double[LOP_Len];
  224. if (LOP_Len > 0)
  225. {
  226. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  227. }
  228. ErrEllipseResDto res = new ErrEllipseResDto();
  229. res.LongRadius = LOP_Value[LOP_Value.Length - 3];
  230. res.ShortRadius = LOP_Value[LOP_Value.Length - 2];
  231. res.DipAngle = LOP_Value[LOP_Value.Length - 1];
  232. if (outputErrPoint)
  233. {
  234. int count = LOP_Value.Length - 3;
  235. for (int i = 0; i < count; i += 2)
  236. {
  237. res.GeoPoints.Add(new GeoPoint()
  238. {
  239. Lon = LOP_Value[i],
  240. Lat = LOP_Value[i + 1],
  241. });
  242. }
  243. }
  244. return res;
  245. }
  246. public static ErrEllipseResDto ErrorEllipseX3NoRef(double posLon, double posLat, double[] mainEph, double[] adja1Eph, double[] adja2Eph,
  247. double dtoErrus, double ephErrm, bool outputErrPoint, double pe = 0.5)
  248. {
  249. int LOP_Len = 0;
  250. IntPtr LOP_ValuePtr = Error_Ellipse_3X_2DTONoRef(
  251. mainEph,
  252. adja1Eph,
  253. adja2Eph,
  254. new double[3] { posLon, posLat, 0 },
  255. dtoErrus * 1e-6,
  256. ephErrm,
  257. pe, ref LOP_Len);
  258. double[] LOP_Value = new double[LOP_Len];
  259. if (LOP_Len > 0)
  260. {
  261. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  262. }
  263. ErrEllipseResDto res = new ErrEllipseResDto();
  264. res.LongRadius = LOP_Value[LOP_Value.Length - 3];
  265. res.ShortRadius = LOP_Value[LOP_Value.Length - 2];
  266. res.DipAngle = LOP_Value[LOP_Value.Length - 1];
  267. if (outputErrPoint)
  268. {
  269. int count = LOP_Value.Length - 3;
  270. for (int i = 0; i < count; i += 2)
  271. {
  272. res.GeoPoints.Add(new GeoPoint()
  273. {
  274. Lon = LOP_Value[i],
  275. Lat = LOP_Value[i + 1],
  276. });
  277. }
  278. }
  279. return res;
  280. }
  281. }
  282. }