You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ct_convert.cpp 1.7 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "geo/private/coord/ct_convert.h"
  2. namespace ns
  3. {
  4. namespace geo
  5. {
  6. Eigen::Vector2d convert_pt(const PointD& pt, const GaussConverter& gc)
  7. {
  8. PointD gauss = gc.wgs842Gauss(pt);
  9. return {gauss.x, gauss.y};
  10. }
  11. Eigen::Vector2d convert_pt(const PointDST& pt, const GaussConverter& gc)
  12. {
  13. PointD gauss = gc.wgs842Gauss(pt.p);
  14. return {gauss.x, gauss.y};
  15. }
  16. Eigen::Matrix2Xd convert_pl(const std::vector<PointD>& pl, const GaussConverter& gc)
  17. {
  18. Eigen::Matrix2Xd mat = Eigen::Matrix2Xd::Zero(2, pl.size());
  19. for (size_t i = 0; i < pl.size(); i++)
  20. {
  21. mat.col(i) = convert_pt(pl[i], gc);
  22. }
  23. return mat;
  24. }
  25. Eigen::Matrix2Xd convert_pl(const std::vector<PointDST>& pl, const GaussConverter& gc)
  26. {
  27. Eigen::Matrix2Xd mat = Eigen::Matrix2Xd::Zero(2, pl.size());
  28. for (size_t i = 0; i < pl.size(); i++)
  29. {
  30. mat.col(i) = convert_pt(pl[i], gc);
  31. }
  32. return mat;
  33. }
  34. RectD convert_bb(const RectD& bb, const GaussConverter& gc)
  35. {
  36. double wgs_min_x = bb.minX, wgs_min_y = bb.minY, wgs_max_x = bb.maxX, wgs_max_y = bb.maxY;
  37. PointD min_pt = gc.wgs842Gauss({wgs_min_x, wgs_min_y});
  38. PointD max_pt = gc.wgs842Gauss({wgs_max_x, wgs_max_y});
  39. return RectD(min_pt.x, max_pt.x, min_pt.y, max_pt.y);
  40. }
  41. PointD convert_pt_reverse(const Eigen::Vector2d& pt, const GaussConverter& gc)
  42. {
  43. return gc.gauss2Wgs84({pt(0), pt(1)});
  44. }
  45. std::vector<PointD> convert_pl_reverse(const Eigen::Matrix2Xd& pl, const GaussConverter& gc)
  46. {
  47. std::vector<PointD> pts;
  48. Eigen::Index n = pl.cols();
  49. for (Eigen::Index i = 0; i < n; ++i)
  50. {
  51. pts.emplace_back(convert_pt_reverse(pl.col(i), gc));
  52. }
  53. return pts;
  54. }
  55. } // namespace geo
  56. } // namespace ns