EphResult.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Globalization;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. namespace Ips.Library.Entity
  8. {
  9. public class EphResult
  10. {
  11. /// <summary>
  12. /// 卫星编号
  13. /// </summary>
  14. [DisplayName("卫星编号")]
  15. public int SatNum { get; set; }
  16. /// <summary>
  17. /// 星历时间
  18. /// </summary>
  19. [DisplayName("星历时间")]
  20. public DateTime Time { get; set; }
  21. /// <summary>
  22. /// 星历类型
  23. /// </summary>
  24. [DisplayName("星历类型")]
  25. public EphType EphType { get; set; }
  26. /// <summary>
  27. /// 位置X
  28. /// </summary>
  29. [DisplayName("位置X")]
  30. public double X { get; set; }
  31. /// <summary>
  32. /// 位置Y
  33. /// </summary>
  34. [DisplayName("位置Y")]
  35. public double Y { get; set; }
  36. /// <summary>
  37. /// 位置Z
  38. /// </summary>
  39. [DisplayName("位置Z")]
  40. public double Z { get; set; }
  41. /// <summary>
  42. /// 速度X
  43. /// </summary>
  44. [DisplayName("速度X")]
  45. public double Vx { get; set; }
  46. /// <summary>
  47. /// 速度Y
  48. /// </summary>
  49. [DisplayName("速度Y")]
  50. public double Vy { get; set; }
  51. /// <summary>
  52. /// 速度Z
  53. /// </summary>
  54. [DisplayName("速度Z")]
  55. public double Vz { get; set; }
  56. public EphResult() { }
  57. public EphResult(int satNum, DateTime time, double x, double y, double z, double vx = 0, double vy = 0, double vz = 0)
  58. {
  59. this.SatNum = satNum;
  60. this.Time = time;
  61. this.X = x;
  62. this.Y = y;
  63. this.Z = z;
  64. this.Vx = vx;
  65. this.Vy = vy;
  66. this.Vz = vz;
  67. }
  68. public EphResult(int satNum, EphType ephType, DateTime time, double x, double y, double z, double vx = 0, double vy = 0, double vz = 0)
  69. {
  70. this.SatNum = satNum;
  71. this.EphType = ephType;
  72. this.Time = time;
  73. this.X = x;
  74. this.Y = y;
  75. this.Z = z;
  76. this.Vx = vx;
  77. this.Vy = vy;
  78. this.Vz = vz;
  79. }
  80. public static EphResult FromString(string source)
  81. {
  82. EphResult result = new EphResult();
  83. var items = source.TrimEnd().Split('\t');
  84. int i = 0;
  85. if (items.Length >= 1 && DateTime.TryParseExact(items[i++], "yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentUICulture, DateTimeStyles.None, out DateTime timeRes))
  86. {
  87. result.Time = timeRes;
  88. }
  89. if (items.Length >= 3)
  90. {
  91. result.X = double.Parse(items[i++]);
  92. result.Y = double.Parse(items[i++]);
  93. result.Z = double.Parse(items[i++]);
  94. }
  95. if (items.Length >= 6)
  96. {
  97. result.Vx = double.Parse(items[i++]);
  98. result.Vy = double.Parse(items[i++]);
  99. result.Vz = double.Parse(items[i++]);
  100. }
  101. return result;
  102. }
  103. public static EphResult[] FromListString(string result, string itemsep = "")
  104. {
  105. if (string.IsNullOrWhiteSpace(result))
  106. return Array.Empty<EphResult>();
  107. if (string.IsNullOrWhiteSpace(itemsep))
  108. {
  109. itemsep = Environment.NewLine;
  110. }
  111. var items = result.Split(itemsep.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  112. EphResult[] results = new EphResult[items.Length];
  113. for (int i = 0; i < items.Length; i++)
  114. {
  115. results[i] = EphResult.FromString(items[i]);
  116. }
  117. return results;
  118. }
  119. public double[] GetEphXyz()
  120. {
  121. return new double[] { this.X, this.Y, this.Z, this.Vx, this.Vy, this.Vz };
  122. }
  123. public override string ToString()
  124. {
  125. return $"{SatNum},{Time:yyyy-MM-dd HH:mm:ss},{X},{Y},{Z},{Vx},{Vy},{Vz}";
  126. }
  127. }
  128. }