123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
-
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using XzXdDw.App.Api;
- namespace XdCxRhDW.App.Api.时差线
- {
- public class DrawDtoLineHelper
- {
- #region 未使用
- /*
- static double[] HandleX2D1(X2D1Option opt)
- {
- var target_llh = DLL_LXYDApi.XingDi_DW(
- opt.MsEph
- , opt.NsEph
- , opt.MsAnt
- , opt.NsAnt
- , opt.CDBMsAnt
- , opt.CDBAnt
- , opt.RefGeod
- , opt.Zone
- , opt.SxDto * 1e-6
- , opt.xdDto * 1e-6
- , -opt.SampMsDto * 1e-6
- , -opt.SampNsDto * 1e-6
- , -opt.CDBpMsDto * 1e-6
- );
- double[] result = new double[6];
- Marshal.Copy(target_llh, result, 0, result.Length);
- return result;
- }
-
- static void HandleX1D2(X1D2Option opt)
- {
- var target_llh = DLL_YXLDApi.XingDi_DW_YXLD(
- opt.MsEph
- , opt.Ms1Ant
- , opt.Ms2Ant
- , opt.Nd1Ant
- , opt.Nd2Ant
- , opt.RefGeod1
- , opt.RefGeod2
- , opt.Zone
- , opt.DtXd1 * 1e-6
- , opt.DtXd2 * 1e-6
- , -opt.DtRef1 * 1e-6
- , -opt.DtRef2 * 1e-6
- );
- double[] result = new double[6];
- Marshal.Copy(target_llh, result, 0, result.Length);
- // OutputHelper.WritePos(result);
- }
- */
- #endregion
- private const string exeName = "XingDiSCX.exe";
- public static IEnumerable<(double lon, double lat)> DtoLineXd(DtoLineXdOption opt)
- {
- List<DtoLinePoint> list = new List<DtoLinePoint>();
- string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\时差线\\DtoLine.dat");
- string exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\时差线");
- if (string.IsNullOrWhiteSpace(exePath))
- throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
- if (!Directory.Exists(exePath))
- throw new Exception($"路径[{exePath}]不存在");
- var exeFile = Path.Combine(exePath, exeName);
- if (!File.Exists(exeFile))
- throw new Exception($"文件[{exeFile}]不存在");
- List<string> arguments = new List<string>();
- arguments.Add(file);
- arguments.Add($"{opt.MsEph[0]}");
- arguments.Add($"{opt.MsEph[1]}");
- arguments.Add($"{opt.MsEph[2]}");
- arguments.Add($"{opt.MsAnt[0]}");
- arguments.Add($"{opt.MsAnt[1]}");
- arguments.Add($"{opt.CDBAnt[0]}");
- arguments.Add($"{opt.CDBAnt[1]}");
- arguments.Add($"{opt.RefGeod[0]}");
- arguments.Add($"{opt.RefGeod[1]}");
- arguments.Add($"{opt.xdDto}");
- arguments.Add($"{opt.RefDto}");
- arguments.Add($"{opt.PosLon}");
- arguments.Add($"{opt.PosLat}");
- Process p = new Process();
- p.StartInfo.WorkingDirectory = exePath;
- p.StartInfo.FileName = exeFile;
- p.StartInfo.Arguments = string.Join(" ", arguments);
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- p.Start();
- var succeed = p.WaitForExit(10000);
- if (!succeed)
- {
- throw new Exception($"进程[{exeName}]超时未完成!");
- }
- string result = p.StandardOutput.ReadToEnd();
- if (string.IsNullOrWhiteSpace(result))
- {
- throw new Exception("计算时差线出现未知错误!");
- }
- var array = result.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- if (array[0] == "1")
- {
- throw new Exception(array[1]);
- }
- if (File.Exists(file))
- {
- var dtostr = File.ReadAllText(file);
- list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DtoLinePoint>>(dtostr);
- }
- var Lines = list.Select(s => (s.Lon, s.Lat));
- return Lines;
- }
- public static IEnumerable<(double lon, double lat)> DtoLineXDTwoStart(DtoLineTwoStartOption opt)
- {
- List<DtoLinePoint> list = new List<DtoLinePoint>();
- IntPtr LOP_ValuePtr;
- int LOP_Len = 0;
- double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
- PosApi.CurveByTwoTDOA(
- opt.MsEph,
- opt.NsEph,
- opt.MsAnt,
- opt.NsAnt,
- opt.RefGeod,
- zone,
- opt.TargetDto * 1e-6,
- opt.RefDto * 1e-6, out LOP_ValuePtr, ref LOP_Len);
- double[] LOP_Value = new double[LOP_Len * 3];
- if (LOP_Len > 0)
- {
- Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
- list = OutputHelper.WriteDtoLine(LOP_Value, LOP_Len);
- }
- var Lines = list.Select(p => (p.Lon, p.Lat));
- return Lines;
- }
- public static IEnumerable<(double lon, double lat)> DtoLineXZTwoStart(DtoLineTwoStartOption opt)
- {
- List<DtoLinePoint> list = new List<DtoLinePoint>();
- IntPtr LOP_ValuePtr;
- int LOP_Len = 0;
- double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
- PosApi.TwoStar_SCX(
- opt.MsEph,
- opt.NsEph,
- opt.RefGeod,
- zone,
- opt.TargetDto * 1e-6,
- opt.RefDto * 1e-6, out LOP_ValuePtr, ref LOP_Len);
- double[] LOP_Value = new double[LOP_Len * 3];
- if (LOP_Len > 0)
- {
- Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
- list = OutputHelper.WriteDtoLine(LOP_Value, LOP_Len);
- }
- var Lines = list.Select(p => (p.Lon, p.Lat));
- return Lines;
- }
- public static IEnumerable<(double lon, double lat)> DfoLineXZTwoStart(DfoLineTwoStartOption opt)
- {
- List<DtoLinePoint> list = new List<DtoLinePoint>();
- IntPtr LOP_ValuePtr;
- int LOP_Len = 0;
- double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
- PosApi.TwoStar_PCX(
- opt.MsEph,
- opt.NsEph,
- opt.RefGeod,
- zone,
- opt.TargetDfo,
- opt.RefDfo,
- opt.fu1,
- opt.fu2, out LOP_ValuePtr, ref LOP_Len);
- return ParseResult(LOP_ValuePtr, LOP_Len);
- }
- private static IEnumerable<(double lon, double lat)> ParseResult(IntPtr LOP_ValuePtr, int LOP_Len)
- {
- List<DtoLinePoint> list = new List<DtoLinePoint>();
- double[] LOP_Value = new double[LOP_Len * 3];
- if (LOP_Len > 0)
- {
- Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
- for (int idx = 0; idx < LOP_Len; ++idx)
- {
- if (LOP_Value[3 * idx + 1] != -1)
- {
- list.Add(new DtoLinePoint()
- {
- Lon = LOP_Value[3 * idx + 1],
- Lat = LOP_Value[3 * idx]
- });
- }
- }
- for (int idx = 0; idx < LOP_Len; ++idx)
- {
- if (LOP_Value[3 * idx + 2] != -1)
- {
- list.Add(new DtoLinePoint()
- {
- Lon = LOP_Value[3 * idx + 2],
- Lat = LOP_Value[3 * idx]
- });
- }
- }
- }
- var Lines = list.Select(p => (p.Lon, p.Lat));
- return Lines;
- }
- }
- }
|