GdopHelper.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection.Emit;
  6. using System.Runtime.InteropServices;
  7. namespace DW5S.KxcApi
  8. {
  9. public static class GdopHelper
  10. {
  11. static readonly DateTime dtZero = new DateTime(1970, 1, 1, 8, 0, 0, 0);
  12. public static double[] ErrorEllipse2X1D(double posLon, double posLat, double[] mainEph, double[] adajEph, double[] cdbPos, double[] RefGeod, double DtoErrus, double EphErrm)
  13. {
  14. IEnumerable<double> res = new List<double>();
  15. int LOP_Len = 0;
  16. /// <summary>
  17. /// 概率 默认0.5
  18. /// </summary>
  19. double Pe = 0.5;
  20. IntPtr LOP_ValuePtr = GDOPApi.Error_Ellipse_2X1D(
  21. mainEph,
  22. adajEph,
  23. cdbPos,
  24. RefGeod,
  25. new double[3] { posLon, posLat, 0 },
  26. DtoErrus * 1e-6,
  27. EphErrm,//单位m
  28. Pe, ref LOP_Len);
  29. List<DtoLinePoint> list = new List<DtoLinePoint>();
  30. double[] LOP_Value = new double[LOP_Len];
  31. if (LOP_Len > 0)
  32. {
  33. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  34. int lastcount = LOP_Len - 3;
  35. res = LOP_Value.Skip(lastcount).Take(3);
  36. }
  37. return res.ToArray();
  38. }
  39. /// <summary>
  40. /// 两星一地GDOP 无参时参考位置不赋值
  41. /// </summary>
  42. /// <param name="mainEph">主星星历 x y z vx vy vz</param>
  43. /// <param name="adajEph">邻星星历x y z vx vy vz</param>
  44. /// <param name="cdbPos">超短波位置 3</param>
  45. /// <param name="refPos">参考站位置 3</param>
  46. /// <param name="dtousErr">时差误差</param>
  47. /// <param name="ephLocErr">星历误差</param>
  48. /// <param name="refPos"></param>
  49. /// <returns></returns>
  50. public static List<ErrDistanceMapPoints> Gdop2Sat1DByXyz(double[] mainEph, double[] adajEph, double[] cdbPos, double dtousErr, double ephLocErr, double[] refPos = null)
  51. {
  52. int satCount = 2;
  53. //该值和points 一一对应
  54. double[] level = GdopParam.误差配置.误差距离m;
  55. double[] satllh = new double[satCount * 3];
  56. IntPtr res = IntPtr.Zero;
  57. int[] resCount = new int[level.Length];
  58. if (refPos == null || refPos.Length == 0)
  59. {
  60. GDOPApi.Gdop2Sat1DNoRefByXyz(mainEph, adajEph, cdbPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  61. }
  62. else
  63. {
  64. GDOPApi.Gdop2Sat1DRefByXyz(mainEph, adajEph, cdbPos, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  65. }
  66. IntPtr tmp = res;
  67. //用于绘制的数据
  68. List<double[]> points = new List<double[]>();
  69. for (int idx = 0; idx < level.Length; ++idx)
  70. {
  71. double[] levelval = new double[resCount[idx]];
  72. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  73. tmp += (resCount[idx] * sizeof(double));
  74. points.Add(levelval);
  75. }
  76. GDOPApi.FreeGDOPBuf(res);
  77. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  78. for (int i = 0; i < points.Count; i++)
  79. {
  80. if (!points[i].Any()) continue;
  81. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  82. errDistanceMap.ErrDistance = level[i];
  83. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  84. errs.Add(errDistanceMap);
  85. }
  86. return errs;
  87. }
  88. /// <summary>
  89. /// 两星一地GDOP 无参时参考位置不赋值
  90. /// </summary>
  91. /// <param name="mainEph">主星星历 x y z vx vy vz</param>
  92. /// <param name="adajEph">邻星星历x y z vx vy vz</param>
  93. /// <param name="cdbPos">超短波位置 3</param>
  94. /// <param name="refPos">参考站位置 3</param>
  95. /// <param name="dtousErr">时差误差</param>
  96. /// <param name="ephLocErr">星历误差</param>
  97. /// <param name="refPos"></param>
  98. /// <returns></returns>
  99. public static List<ErrDistanceMapPoints> Gdop2Sat1DByXyzNew(double[] mainEph, double[] adajEph, double[] cdbPos, double dtousErr, double ephLocErr, double[] refPos = null)
  100. {
  101. int satCount = 2;
  102. //该值和points 一一对应
  103. double[] level = GdopParam.误差配置.误差距离m;
  104. double[] satllh = new double[satCount * 3];
  105. IntPtr res = IntPtr.Zero;
  106. IntPtr lpoints = IntPtr.Zero;
  107. int[] resCount = new int[level.Length];
  108. if (refPos == null || refPos.Length == 0)
  109. {
  110. GDOPApi.Gdop2Sat1DNoRefByXyz_new(mainEph, adajEph, cdbPos, dtousErr, ephLocErr, level, level.Length, resCount, out lpoints, out res, satllh);
  111. }
  112. else
  113. {
  114. GDOPApi.Gdop2Sat1DRefByXyz_new(mainEph, adajEph, cdbPos, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out lpoints, out res, satllh);
  115. }
  116. var errs = ToErrDistanceMapPoints(level, resCount, lpoints, res);
  117. GDOPApi.FreeGDOPBuf(res);
  118. GDOPApi.FreeGDOPBuf(lpoints);
  119. return errs;
  120. }
  121. private static List<ErrDistanceMapPoints> ToErrDistanceMapPoints(double[] level, int[] resCount, IntPtr lpoints, IntPtr res)
  122. {
  123. int total = resCount.Sum(r => r);
  124. int[] Points_Value = new int[total];
  125. Marshal.Copy(lpoints, Points_Value, 0, Points_Value.Length);
  126. int totalPoint = Points_Value.Sum(p => p);
  127. double[] LOP_Value = new double[totalPoint * 2];
  128. Marshal.Copy(res, LOP_Value, 0, LOP_Value.Length);
  129. var points = ParseResult(LOP_Value);
  130. //用于绘制的数据
  131. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  132. int skippointcount = 0;
  133. int skipcount = 0;
  134. int count = 0;
  135. for (int idx = 0; idx < level.Length; ++idx)
  136. {
  137. int levelcount = resCount[idx];
  138. skipcount = idx == 0 ? 0 : skipcount + resCount[idx - 1];
  139. for (int i = skipcount; i < levelcount + skipcount; i++)
  140. {
  141. int pointcount = Points_Value[i];
  142. skippointcount = count == 0 ? 0 : skippointcount + Points_Value[i - 1];
  143. var mapDots = points.Skip(skippointcount).Take(pointcount);
  144. if (!mapDots.Any()) continue;
  145. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  146. errDistanceMap.ErrDistance = level[idx];
  147. errDistanceMap.MapDots.AddRange(mapDots);
  148. errs.Add(errDistanceMap);
  149. count++;
  150. }
  151. }
  152. return errs;
  153. }
  154. /// <summary>
  155. /// 一星一地GDOP
  156. /// </summary>
  157. /// <param name="mainLines">主星星历</param>
  158. /// <param name="captime">信号时间</param>
  159. /// <param name="cdbPos">超短波位置 3</param>
  160. /// <param name="cxPos">测向站位置 3</param>
  161. /// <param name="dtousErr">时差误差</param>
  162. /// <param name="doaErr">测向误差</param>
  163. /// <param name="ephLocErr">星历误差</param>
  164. /// <param name="refPos">参考站位置 3</param>
  165. /// <returns></returns>
  166. public static List<ErrDistanceMapPoints> Gdop1Sat1DByXyz(double[] mainEph, double[] cdbPos, double[] cxPos, double dtousErr, double doaErr, double ephLocErr, double[] refPos = null)
  167. {
  168. int satCount = 1;
  169. //该值和points 一一对应
  170. double[] level = GdopParam.误差配置.误差距离m;
  171. double[] satllh = new double[satCount * 3];
  172. IntPtr res = IntPtr.Zero;
  173. int[] resCount = new int[level.Length];
  174. if (refPos == null || refPos.Length == 0)
  175. {
  176. GDOPApi.GdopXDCXNoRefByXyz(mainEph, cdbPos, cxPos, dtousErr, doaErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  177. }
  178. else
  179. {
  180. GDOPApi.GdopXDCXRefByXyz(mainEph, cdbPos, cxPos, refPos, dtousErr, doaErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  181. }
  182. IntPtr tmp = res;
  183. //用于绘制的数据
  184. List<double[]> points = new List<double[]>();
  185. for (int idx = 0; idx < level.Length; ++idx)
  186. {
  187. double[] levelval = new double[resCount[idx]];
  188. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  189. tmp += (resCount[idx] * sizeof(double));
  190. points.Add(levelval);
  191. }
  192. GDOPApi.FreeGDOPBuf(res);
  193. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  194. for (int i = 0; i < points.Count; i++)
  195. {
  196. if (!points[i].Any()) continue;
  197. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  198. errDistanceMap.ErrDistance = level[i];
  199. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  200. errs.Add(errDistanceMap);
  201. }
  202. return errs;
  203. }
  204. public static List<ErrDistanceMapPoints> Gdop1Sat1DByXyzNew(double[] mainEph, double[] cdbPos, double[] cxPos, double dtousErr, double doaErr, double ephLocErr, double[] refPos = null)
  205. {
  206. int satCount = 1;
  207. //该值和points 一一对应
  208. double[] level = GdopParam.误差配置.误差距离m;
  209. double[] satllh = new double[satCount * 3];
  210. IntPtr res = IntPtr.Zero;
  211. IntPtr lpoints = IntPtr.Zero;
  212. int[] resCount = new int[level.Length];
  213. if (refPos == null || refPos.Length == 0)
  214. {
  215. GDOPApi.GdopXDCXNoRefByXyz_new(mainEph, cdbPos, cxPos, dtousErr, doaErr, ephLocErr, level, level.Length, resCount, out lpoints, out res, satllh);
  216. }
  217. else
  218. {
  219. GDOPApi.GdopXDCXRefByXyz_new(mainEph, cdbPos, cxPos, refPos, dtousErr, doaErr, ephLocErr, level, level.Length, resCount, out lpoints, out res, satllh);
  220. }
  221. var errs = ToErrDistanceMapPoints(level, resCount, lpoints, res);
  222. GDOPApi.FreeGDOPBuf(res);
  223. GDOPApi.FreeGDOPBuf(lpoints);
  224. return errs;
  225. }
  226. public static List<ErrDistanceMapPoints> Gdop3SatByXyz(double[] mainEph, double[] adaj1Eph, double[] adaj2Eph,
  227. double dtousErr, double ephLocErr, double[] refPos = null)
  228. {
  229. int satCount = 3;
  230. //该值和points 一一对应
  231. double[] level = GdopParam.误差配置.误差距离m;
  232. double[] satllh = new double[satCount * 3];
  233. IntPtr res = IntPtr.Zero;
  234. int[] resCount = new int[level.Length];
  235. if (refPos == null || refPos.Length == 0)
  236. {
  237. GDOPApi.Gdop3SatNoRefByXyz(mainEph, adaj1Eph, adaj2Eph, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  238. }
  239. else
  240. {
  241. GDOPApi.Gdop3SatRefByXyz(mainEph, adaj1Eph, adaj2Eph, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  242. }
  243. IntPtr tmp = res;
  244. //用于绘制的数据
  245. List<double[]> points = new List<double[]>();
  246. for (int idx = 0; idx < level.Length; ++idx)
  247. {
  248. double[] levelval = new double[resCount[idx]];
  249. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  250. tmp += (resCount[idx] * sizeof(double));
  251. points.Add(levelval);
  252. }
  253. GDOPApi.FreeGDOPBuf(res);
  254. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  255. for (int i = 0; i < points.Count; i++)
  256. {
  257. if (!points[i].Any()) continue;
  258. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  259. errDistanceMap.ErrDistance = level[i];
  260. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  261. errs.Add(errDistanceMap);
  262. }
  263. return errs;
  264. }
  265. public static List<ErrDistanceMapPoints> Gdop3SatByXyzNew(double[] mainEph, double[] adaj1Eph, double[] adaj2Eph,
  266. double dtousErr, double ephLocErr, double[] refPos = null)
  267. {
  268. int satCount = 3;
  269. //该值和points 一一对应
  270. double[] level = GdopParam.误差配置.误差距离m;
  271. double[] satllh = new double[satCount * 3];
  272. IntPtr res = IntPtr.Zero;
  273. IntPtr lpoints = IntPtr.Zero;
  274. int[] resCount = new int[level.Length];
  275. if (refPos == null || refPos.Length == 0)
  276. {
  277. GDOPApi.Gdop3SatNoRefByXyz_new(mainEph, adaj1Eph, adaj2Eph, dtousErr, ephLocErr, level, level.Length, resCount, out lpoints, out res, satllh);
  278. }
  279. else
  280. {
  281. GDOPApi.Gdop3SatRefByXyz_new(mainEph, adaj1Eph, adaj2Eph, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out lpoints, out res, satllh);
  282. }
  283. var errs = ToErrDistanceMapPoints(level, resCount, lpoints, res);
  284. GDOPApi.FreeGDOPBuf(res);
  285. GDOPApi.FreeGDOPBuf(lpoints);
  286. return errs;
  287. }
  288. public static List<ErrDistanceMapPoints> Gdop3SatDFByXyz(double[] mainEph, double[] adaj1Eph, double[] adaj2Eph,
  289. double fuHz1, double fuHz2, double dfoErr, double ephLocErr, double ephVErr, double[] refPos)
  290. {
  291. int satCount = 3;
  292. //该值和points 一一对应
  293. double[] level = GdopParam.误差配置.误差距离m;
  294. double[] satllh = new double[satCount * 3];
  295. IntPtr res = IntPtr.Zero;
  296. int[] resCount = new int[level.Length];
  297. GDOPApi.Gdop3SatDFByXyz(mainEph, adaj1Eph, adaj2Eph, refPos, fuHz1, fuHz2, dfoErr, ephLocErr, ephVErr, level, level.Length, resCount, out res, satllh);
  298. IntPtr tmp = res;
  299. //用于绘制的数据
  300. List<double[]> points = new List<double[]>();
  301. for (int idx = 0; idx < level.Length; ++idx)
  302. {
  303. double[] levelval = new double[resCount[idx]];
  304. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  305. tmp += (resCount[idx] * sizeof(double));
  306. points.Add(levelval);
  307. }
  308. GDOPApi.FreeGDOPBuf(res);
  309. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  310. for (int i = 0; i < points.Count; i++)
  311. {
  312. if (!points[i].Any()) continue;
  313. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  314. errDistanceMap.ErrDistance = level[i];
  315. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  316. errs.Add(errDistanceMap);
  317. }
  318. return errs;
  319. }
  320. public static List<ErrDistanceMapPoints> Gdop2SatDRefByXyz(double[] mainEph, double[] adajEph, double fuHz1, double fuHz2, double dtousErr, double dfoErr, double ephLocErr, double ephVErr, double[] refPos)
  321. {
  322. int satCount = 2;
  323. //该值和points 一一对应
  324. double[] level = GdopParam.误差配置.误差距离m;
  325. double[] satllh = new double[satCount * 3];
  326. IntPtr res = IntPtr.Zero;
  327. int[] resCount = new int[level.Length];
  328. GDOPApi.Gdop2SatDRefByXyz(mainEph, adajEph, refPos, fuHz1, fuHz2, dtousErr, dfoErr, ephLocErr, ephVErr, level, level.Length, resCount, out res, satllh);
  329. IntPtr tmp = res;
  330. //用于绘制的数据
  331. List<double[]> points = new List<double[]>();
  332. for (int idx = 0; idx < level.Length; ++idx)
  333. {
  334. double[] levelval = new double[resCount[idx]];
  335. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  336. tmp += (resCount[idx] * sizeof(double));
  337. points.Add(levelval);
  338. }
  339. GDOPApi.FreeGDOPBuf(res);
  340. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  341. for (int i = 0; i < points.Count; i++)
  342. {
  343. if (!points[i].Any()) continue;
  344. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  345. errDistanceMap.ErrDistance = level[i];
  346. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  347. errs.Add(errDistanceMap);
  348. }
  349. return errs;
  350. }
  351. private static List<(double lon, double lat)> ParseResult(double[] ponits)
  352. {
  353. List<(double lon, double lat)> mapDots = new List<(double lon, double lat)>();
  354. int count = 2;
  355. for (int i = 0; i < ponits.Length / count; i++)
  356. {
  357. var Lon = ponits[count * i];
  358. var Lat = ponits[count * i + 1];//0 1 2 3 4 5 6 7
  359. mapDots.Add((Lon, Lat));
  360. }
  361. return mapDots;
  362. }
  363. public static List<ErrDistanceMapPoints> Gdop3SatDFByXyzNew(double[] mainEph, double[] adaj1Eph, double[] adaj2Eph,
  364. double fuHz1, double fuHz2, double dfoErr, double ephLocErr, double ephVErr, double[] refPos)
  365. {
  366. int satCount = 3;
  367. //该值和points 一一对应
  368. double[] level = GdopParam.误差配置.误差距离m;
  369. double[] satllh = new double[satCount * 3];
  370. IntPtr res = IntPtr.Zero;
  371. IntPtr lpoints = IntPtr.Zero;
  372. int[] resCount = new int[level.Length];
  373. GDOPApi.Gdop3SatDFByXyz_new(mainEph, adaj1Eph, adaj2Eph, refPos, fuHz1, fuHz2, dfoErr, ephLocErr, ephVErr, level, level.Length, resCount, out lpoints, out res, satllh);
  374. var errs = ToErrDistanceMapPoints(level, resCount, lpoints, res);
  375. GDOPApi.FreeGDOPBuf(res);
  376. GDOPApi.FreeGDOPBuf(lpoints);
  377. return errs;
  378. }
  379. public static List<ErrDistanceMapPoints> Gdop2SatDRefByXyzNew(double[] mainEph, double[] adajEph, double fuHz1, double fuHz2, double dtousErr, double dfoErr, double ephLocErr, double ephVErr, double[] refPos)
  380. {
  381. int satCount = 2;
  382. //该值和points 一一对应
  383. double[] level = GdopParam.误差配置.误差距离m;
  384. double[] satllh = new double[satCount * 3];
  385. IntPtr res = IntPtr.Zero;
  386. IntPtr lpoints = IntPtr.Zero;
  387. int[] resCount = new int[level.Length];
  388. GDOPApi.Gdop2SatDRefByXyz_new(mainEph, adajEph, refPos, fuHz1, fuHz2, dtousErr, dfoErr, ephLocErr, ephVErr, level, level.Length, resCount, out lpoints, out res, satllh);
  389. var errs = ToErrDistanceMapPoints(level, resCount, lpoints, res);
  390. GDOPApi.FreeGDOPBuf(res);
  391. GDOPApi.FreeGDOPBuf(lpoints);
  392. return errs;
  393. }
  394. }
  395. }