LocSigUtil.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using DevExpress.Xpo;
  2. using DevExpress.Xpo.Generators;
  3. using Ips.Library.Basic;
  4. using Ips.Library.Entity;
  5. using Ips.LocAlgorithm;
  6. using Ips.Sps.Scheduling.Entities;
  7. using Ips.Sps.TskResults.Peses;
  8. using Ips.Sps.TskResults.Poses;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace Ips.Sps.Scheduling.SigLocs
  15. {
  16. public class LocSigUtil
  17. {
  18. public static Pos CreatePos(PosResult posRes, int tskId, RunSig sig, DateTime sigTime, Session session)
  19. {
  20. Pos pos = new Pos(session);
  21. pos.TskId = tskId;
  22. pos.SigId = sig.SigId;
  23. pos.EmtId = sig.EmtId;
  24. pos.SigTime = sigTime;
  25. pos.SigFreq = sig.SigFreq;
  26. pos.BandWidth = sig.BandWidth;
  27. pos.CreateTime = DateTime.Now;
  28. if (posRes != null)
  29. {
  30. SetPosLoc(pos, posRes, sig);
  31. }
  32. else
  33. {
  34. pos.PosType = PosType.X3;
  35. pos.HasRef = false;
  36. pos.PosLon = LonNan.Value;
  37. pos.PosLat = LatNan.Value;
  38. pos.PosAlt = 0;
  39. pos.MirrLon = LonNan.Value;
  40. pos.MirrLat = LatNan.Value;
  41. pos.IsValid = false;
  42. }
  43. return pos;
  44. }
  45. public static void SavePosRel(Pos pos, Pes tarPes, Pes refPes, List<Pes> refPesList, Session session)
  46. {
  47. List<PosRel> posRelList = new List<PosRel>();
  48. PosRel posRel = new PosRel(session);
  49. posRelList.Add(posRel);
  50. posRel.PosId = pos.Id;
  51. posRel.PesId = tarPes.Id;
  52. posRel.Category = SignalCategory.TarSig;
  53. if (refPes != null)
  54. {
  55. posRel.RefDt = refPes.Dt;
  56. posRel.RefDf = refPes.Df;
  57. posRel.RefSnr = refPes.Snr;
  58. posRel.RefEmtId = refPes.EmtId;
  59. posRel.RefSigLon = refPes.SigLon;
  60. posRel.RefSigLat = refPes.SigLat;
  61. posRel.RefSigAlt = refPes.SigAlt;
  62. if (refPesList.IsNotNullOrEmpty())
  63. {
  64. foreach (var refPesItem in refPesList)
  65. {
  66. PosRel refPosRel = new PosRel();
  67. refPosRel.PosId = posRel.PosId;
  68. refPosRel.PesId = refPesItem.Id;
  69. refPosRel.Category = SignalCategory.RefSig;
  70. refPosRel.RefDt = refPesItem.Dt;
  71. refPosRel.RefDf = refPesItem.Df;
  72. refPosRel.RefSnr = refPesItem.Snr;
  73. refPosRel.RefEmtId = refPesItem.EmtId;
  74. refPosRel.RefSigLon = refPesItem.SigLon;
  75. refPosRel.RefSigLat = refPesItem.SigLat;
  76. refPosRel.RefSigAlt = refPes.SigAlt;
  77. posRelList.Add(refPosRel);
  78. }
  79. }
  80. }
  81. posRel.Save();
  82. }
  83. public static int GetGdopErr(Pos pos, Pes pes1, Pes pes2, double[] refSigLla)
  84. {
  85. int result = -1;
  86. try
  87. {
  88. bool isGeoPoint = GeoUtil.IsValidPoint(pos.PosLon, pos.PosLat);
  89. if (!isGeoPoint) return result;
  90. ExeResult<GdopErrResult> gdopErr = null;
  91. if (refSigLla.IsNotNullOrEmpty())
  92. {
  93. gdopErr = LocRhUtil.GdopErrRef(pos.GetPosLLA(), refSigLla
  94. , pes1.GetMainEphXYZ(), pes1.GetAdjaEphXYZ()
  95. , pes2.GetMainEphXYZ(), pes2.GetAdjaEphXYZ()).Result;
  96. }
  97. else
  98. {
  99. gdopErr = LocRhUtil.GdopErr(pos.GetPosLLA(), pes1.GetAdjaAntLLA()
  100. , pes1.GetMainEphXYZ(), pes1.GetAdjaEphXYZ()
  101. , pes2.GetMainEphXYZ(), pes2.GetAdjaEphXYZ()).Result;
  102. }
  103. if (gdopErr != null && gdopErr.Result != null && gdopErr.ExitCode == 0)
  104. {
  105. result = (int)(gdopErr.Result.ErrorRange);
  106. }
  107. }
  108. catch (Exception ex)
  109. {
  110. IpsLogger.Error($"定位点误差计算错误,信号时间:{pos.SigTime:yyyy-MM-dd HH:mm:ss},信号频点:{pos.SigFreq.E6m()}",ex);
  111. }
  112. return result;
  113. }
  114. public static void SetPosLoc(Pos pos, PosResult posRes, RunSig sig)
  115. {
  116. pos.PosType = posRes.PosType;
  117. pos.HasRef = posRes.HasRef;
  118. pos.PosAlt = sig.SigAlt;
  119. pos.IsValid = posRes.Result1.IsValid() || posRes.Result2.IsValid();
  120. if (pos.IsValid)
  121. {
  122. pos.IsValid = SpsConst.NoRefIsValidPos || pos.HasRef;
  123. }
  124. GeoLLA lla1 = posRes.Result1, lla2 = posRes.Result2;
  125. GeoLLA posLoc = lla1, posMir = lla2;
  126. if (pos.IsValid)
  127. {
  128. bool lla1InZone = GeoUtil.InZone(lla1.Lon, lla1.Lat, sig.LonMin, sig.LonMax, sig.LatMin, sig.LatMax);
  129. bool lla2InZone = GeoUtil.InZone(lla2.Lon, lla2.Lat, sig.LonMin, sig.LonMax, sig.LatMin, sig.LatMax);
  130. if ((lla1InZone == true && lla2InZone == true) || (lla1InZone == false && lla2InZone == false))
  131. {
  132. var dis1 = GeoUtil.DistinceLla(lla1.Lon, lla1.Lat, sig.SigAlt, sig.SigLon, sig.SigLat, sig.SigAlt);
  133. var dis2 = GeoUtil.DistinceLla(lla2.Lon, lla2.Lat, sig.SigAlt, sig.SigLon, sig.SigLat, sig.SigAlt);
  134. if (dis1 > dis2)
  135. {
  136. posLoc = lla2;
  137. posMir = lla1;
  138. }
  139. }
  140. else if (lla2InZone)
  141. {
  142. posLoc = lla2;
  143. posMir = lla1;
  144. }
  145. }
  146. pos.PosLon = posLoc.Lon;
  147. pos.PosLat = posLoc.Lat;
  148. pos.MirrLon = posMir.Lon;
  149. pos.MirrLat = posMir.Lat;
  150. }
  151. private static void SetPosMirr(Pos pos, GeoLLA lla1, GeoLLA lla2)
  152. {
  153. pos.PosLon = lla1.Lon;
  154. pos.PosLat = lla1.Lat;
  155. pos.MirrLon = lla2.Lon;
  156. pos.MirrLat = lla2.Lat;
  157. }
  158. }
  159. }