123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- namespace XdCxRhDW.App.Api.GDOP误差椭圆
- {
- public static class GdopHelper
- {
- private const string GDOPDll = @"Api\GDOP误差椭圆\GDOP\GDOP_Draw.dll";
- static readonly DateTime dtZero = new DateTime(1970, 1, 1, 8, 0, 0, 0);
- /// <returns></returns>
-
- [DllImport(GDOPDll, CallingConvention = CallingConvention.Cdecl)]
- public static extern int Gdop2Sat1DRef(string mainLines, string adajLines, Int64 captime, double[] cdbPos
- , double[] refPos, double dtousErr, double ephLocErr
- , double[] level, int levlen, int[] resCount, out IntPtr res, double[] satllh);
- [DllImport(GDOPDll, CallingConvention = CallingConvention.Cdecl)]
- public static extern void FreeGDOPBuf(IntPtr val);
-
- public static (List<SatInfo>, List<ErrDistanceMapPoints>) Gdop2Sat1DRef(string mainLines, string adajLines, DateTime captime, double[] cdbPos, double[] refPos, double dtousErr, double ephLocErr)
- {
- int satCount = 2;
- //该值和points 一一对应
- double[] level = GdopParam.误差配置.误差距离m;
- double[] satllh = new double[satCount * 3];
- var timeSpan = (long)(captime - dtZero).TotalSeconds;
- IntPtr res = IntPtr.Zero;
- int[] resCount = new int[level.Length];
- Gdop2Sat1DRef(mainLines, adajLines, timeSpan, cdbPos, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
- IntPtr tmp = res;
- //用于绘制的数据
- List<double[]> points = new List<double[]>();
- for (int idx = 0; idx < level.Length; ++idx)
- {
- double[] levelval = new double[resCount[idx]];
- Marshal.Copy(tmp, levelval, 0, resCount[idx]);
- tmp += (resCount[idx] * sizeof(double));
- points.Add(levelval);
- }
- FreeGDOPBuf(res);
- List<SatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines);
- List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
- for (int i = 0; i < points.Count; i++)
- {
- if (!points[i].Any()) continue;
- ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
- errDistanceMap.ErrDistance = level[i];
- errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
- errs.Add(errDistanceMap);
- }
- return (satInfos, errs);
- }
- private static List<MapDot> ParseResult(double[] ponits)
- {
- List<MapDot> mapDots = new List<MapDot>();
- int count = 2;
- for (int i = 0; i < ponits.Length / count; i++)
- {
- MapDot mapDot = new MapDot();
- mapDot.Lat = ponits[count * i + 1];
- mapDot.Lon = ponits[count * i];
- mapDots.Add(mapDot);
-
- }
- return mapDots;
- }
- private static List<SatInfo> ParseResult(int satCount, double[] satllh, params string[] ephLine)
- {
- List<SatInfo> list = new List<SatInfo>();
- int len = 3;
- for (int i = 0; i < satCount; i++)
- {
- SatInfo satInfo = new SatInfo();
- var ephstrs = ephLine[i].Split(new string[] { " ", "U" }, StringSplitOptions.RemoveEmptyEntries);
- if (ephstrs.Length == 16)
- {
- satInfo.SatCode = Convert.ToInt32(ephstrs[1]);
- }
- satInfo.SatLon = Convert.ToDouble(satllh[len * i]);
- satInfo.SatLat = Convert.ToDouble(satllh[len * i + 1]);
- list.Add(satInfo);
- }
- return list;
- }
- }
- }
|