GdopHelper.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. namespace XdCxRhDW.App.Api.GDOP误差椭圆
  7. {
  8. public static class GdopHelper
  9. {
  10. private const string GDOPDll = @"Api\GDOP误差椭圆\GDOP\GDOP_Draw.dll";
  11. static readonly DateTime dtZero = new DateTime(1970, 1, 1, 8, 0, 0, 0);
  12. /// <returns></returns>
  13. [DllImport(GDOPDll, CallingConvention = CallingConvention.Cdecl)]
  14. public static extern int Gdop2Sat1DRef(string mainLines, string adajLines, Int64 captime, double[] cdbPos
  15. , double[] refPos, double dtousErr, double ephLocErr
  16. , double[] level, int levlen, int[] resCount, out IntPtr res, double[] satllh);
  17. [DllImport(GDOPDll, CallingConvention = CallingConvention.Cdecl)]
  18. public static extern void FreeGDOPBuf(IntPtr val);
  19. public static (List<SatInfo>, List<ErrDistanceMapPoints>) Gdop2Sat1DRef(string mainLines, string adajLines, DateTime captime, double[] cdbPos, double[] refPos, double dtousErr, double ephLocErr)
  20. {
  21. int satCount = 2;
  22. //该值和points 一一对应
  23. double[] level = GdopParam.误差配置.误差距离m;
  24. double[] satllh = new double[satCount * 3];
  25. var timeSpan = (long)(captime - dtZero).TotalSeconds;
  26. IntPtr res = IntPtr.Zero;
  27. int[] resCount = new int[level.Length];
  28. Gdop2Sat1DRef(mainLines, adajLines, timeSpan, cdbPos, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  29. IntPtr tmp = res;
  30. //用于绘制的数据
  31. List<double[]> points = new List<double[]>();
  32. for (int idx = 0; idx < level.Length; ++idx)
  33. {
  34. double[] levelval = new double[resCount[idx]];
  35. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  36. tmp += (resCount[idx] * sizeof(double));
  37. points.Add(levelval);
  38. }
  39. FreeGDOPBuf(res);
  40. List<SatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines);
  41. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  42. for (int i = 0; i < points.Count; i++)
  43. {
  44. if (!points[i].Any()) continue;
  45. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  46. errDistanceMap.ErrDistance = level[i];
  47. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  48. errs.Add(errDistanceMap);
  49. }
  50. return (satInfos, errs);
  51. }
  52. private static List<MapDot> ParseResult(double[] ponits)
  53. {
  54. List<MapDot> mapDots = new List<MapDot>();
  55. int count = 2;
  56. for (int i = 0; i < ponits.Length / count; i++)
  57. {
  58. MapDot mapDot = new MapDot();
  59. mapDot.Lat = ponits[count * i + 1];
  60. mapDot.Lon = ponits[count * i];
  61. mapDots.Add(mapDot);
  62. }
  63. return mapDots;
  64. }
  65. private static List<SatInfo> ParseResult(int satCount, double[] satllh, params string[] ephLine)
  66. {
  67. List<SatInfo> list = new List<SatInfo>();
  68. int len = 3;
  69. for (int i = 0; i < satCount; i++)
  70. {
  71. SatInfo satInfo = new SatInfo();
  72. var ephstrs = ephLine[i].Split(new string[] { " ", "U" }, StringSplitOptions.RemoveEmptyEntries);
  73. if (ephstrs.Length == 16)
  74. {
  75. satInfo.SatCode = Convert.ToInt32(ephstrs[1]);
  76. }
  77. satInfo.SatLon = Convert.ToDouble(satllh[len * i]);
  78. satInfo.SatLat = Convert.ToDouble(satllh[len * i + 1]);
  79. list.Add(satInfo);
  80. }
  81. return list;
  82. }
  83. }
  84. }