PosResult.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Ips.Library.Entity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace Ips.Library.Entity
  6. {
  7. public class PosResult
  8. {
  9. public PosType PosType { get; set; }
  10. public bool HasRef { get; set; }
  11. public GeoLLA Result1 { get; set; }
  12. public GeoLLA Result2 { get; set; }
  13. public PosResult()
  14. : this(LonNan.Value, LatNan.Value, LonNan.Value, LatNan.Value)
  15. { }
  16. public PosResult(double lon, double lat, double alt)
  17. : this(lon, lat, alt, LonNan.Value, LatNan.Value, 0)
  18. { }
  19. public PosResult(double lon, double lat, double mirlon, double mirlat)
  20. : this(lon, lat, 0, mirlon, mirlat, 0)
  21. {
  22. }
  23. public PosResult(double lon, double lat, double alt, double mirlon, double mirlat, double miralt)
  24. {
  25. Result1 = new GeoLLA(lon, lat, alt);
  26. Result2 = new GeoLLA(mirlon, mirlat, miralt);
  27. }
  28. public override string ToString()
  29. {
  30. return $"{Result1.Lon},{Result1.Lat},{Result1.Alt};{Result2.Lon},{Result2.Lat},{Result2.Alt}";
  31. }
  32. public static PosResult FromString(PosType posType, bool hasRef, string source)
  33. {
  34. if (string.IsNullOrWhiteSpace(source))
  35. throw new ArgumentException("定位结果转换出错!", nameof(source));
  36. var items = source.Split(';');
  37. PosResult result = new PosResult();
  38. result.PosType = posType;
  39. result.HasRef = hasRef;
  40. if (items.Length >= 1)
  41. {
  42. result.Result1 = GeoLLA.FromString(items[0]);
  43. }
  44. if (items.Length >= 2)
  45. {
  46. result.Result2 = GeoLLA.FromString(items[1]);
  47. }
  48. return result;
  49. }
  50. }
  51. }