base_dynamic.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2017, 2018.
  4. // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP
  10. #define BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP
  11. #include <string>
  12. #include <boost/geometry/srs/projections/exception.hpp>
  13. #include <boost/geometry/srs/projections/impl/projects.hpp>
  14. namespace boost { namespace geometry { namespace projections
  15. {
  16. #ifndef DOXYGEN_NO_DETAIL
  17. namespace detail
  18. {
  19. /*!
  20. \brief projection virtual base class
  21. \details class containing virtual methods
  22. \ingroup projection
  23. \tparam CT calculation type
  24. \tparam P parameters type
  25. */
  26. template <typename CT, typename P>
  27. class base_v
  28. {
  29. public :
  30. /// Forward projection, from Latitude-Longitude to Cartesian
  31. template <typename LL, typename XY>
  32. inline bool forward(LL const& lp, XY& xy) const
  33. {
  34. try
  35. {
  36. pj_fwd(*this, this->params(), lp, xy);
  37. return true;
  38. }
  39. catch (...)
  40. {
  41. return false;
  42. }
  43. }
  44. /// Inverse projection, from Cartesian to Latitude-Longitude
  45. template <typename LL, typename XY>
  46. inline bool inverse(XY const& xy, LL& lp) const
  47. {
  48. try
  49. {
  50. pj_inv(*this, this->params(), xy, lp);
  51. return true;
  52. }
  53. catch (projection_not_invertible_exception &)
  54. {
  55. BOOST_RETHROW
  56. }
  57. catch (...)
  58. {
  59. return false;
  60. }
  61. }
  62. /// Forward projection using lon / lat and x / y separately
  63. virtual void fwd(CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const = 0;
  64. /// Inverse projection using x / y and lon / lat
  65. virtual void inv(CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const = 0;
  66. /// Returns name of projection
  67. virtual std::string name() const = 0;
  68. /// Returns parameters of projection
  69. virtual P const& params() const = 0;
  70. /// Returns mutable parameters of projection
  71. virtual P& mutable_params() = 0;
  72. virtual ~base_v() {}
  73. };
  74. // Base-virtual-forward
  75. template <typename Prj, typename CT, typename P>
  76. class base_v_f : public base_v<CT, P>
  77. {
  78. public:
  79. explicit base_v_f(P const& p)
  80. : m_proj(p)
  81. {}
  82. template <typename P1, typename P2>
  83. base_v_f(P1 const& p1, P2 const& p2)
  84. : m_proj(p1, p2)
  85. {}
  86. template <typename P1, typename P2, typename P3>
  87. base_v_f(P1 const& p1, P2 const& p2, P3 const& p3)
  88. : m_proj(p1, p2, p3)
  89. {}
  90. virtual void fwd(CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const
  91. {
  92. m_proj.fwd(lp_lon, lp_lat, xy_x, xy_y);
  93. }
  94. virtual void inv(CT const& , CT const& , CT& , CT& ) const
  95. {
  96. BOOST_THROW_EXCEPTION(projection_not_invertible_exception(params().id.name));
  97. }
  98. virtual std::string name() const { return m_proj.name(); }
  99. virtual P const& params() const { return m_proj.params(); }
  100. virtual P& mutable_params() { return m_proj.mutable_params(); }
  101. protected:
  102. Prj m_proj;
  103. };
  104. // Base-virtual-forward/inverse
  105. template <typename Prj, typename CT, typename P>
  106. class base_v_fi : public base_v_f<Prj, CT, P>
  107. {
  108. typedef base_v_f<Prj, CT, P> base_t;
  109. public:
  110. explicit base_v_fi(P const& p)
  111. : base_t(p)
  112. {}
  113. template <typename P1, typename P2>
  114. base_v_fi(P1 const& p1, P2 const& p2)
  115. : base_t(p1, p2)
  116. {}
  117. template <typename P1, typename P2, typename P3>
  118. base_v_fi(P1 const& p1, P2 const& p2, P3 const& p3)
  119. : base_t(p1, p2, p3)
  120. {}
  121. virtual void inv(CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const
  122. {
  123. this->m_proj.inv(xy_x, xy_y, lp_lon, lp_lat);
  124. }
  125. };
  126. } // namespace detail
  127. #endif // DOXYGEN_NO_DETAIL
  128. }}} // namespace boost::geometry::projections
  129. #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP