base_dynamic.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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& lp_lon, CT& lp_lat, CT& xy_x, CT& xy_y) const = 0;
  64. /// Inverse projection using x / y and lon / lat
  65. virtual void inv(CT& xy_x, CT& 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. base_v_f(P const& params)
  80. : m_proj(params)
  81. {}
  82. template <typename ProjP>
  83. base_v_f(P const& params, ProjP const& proj_params)
  84. : m_proj(params, proj_params)
  85. {}
  86. virtual void fwd(CT& lp_lon, CT& lp_lat, CT& xy_x, CT& xy_y) const
  87. {
  88. m_proj.fwd(lp_lon, lp_lat, xy_x, xy_y);
  89. }
  90. virtual void inv(CT& , CT& , CT& , CT& ) const
  91. {
  92. BOOST_THROW_EXCEPTION(projection_not_invertible_exception(params().name));
  93. }
  94. virtual std::string name() const { return m_proj.name(); }
  95. virtual P const& params() const { return m_proj.params(); }
  96. virtual P& mutable_params() { return m_proj.mutable_params(); }
  97. protected:
  98. Prj m_proj;
  99. };
  100. // Base-virtual-forward/inverse
  101. template <typename Prj, typename CT, typename P>
  102. class base_v_fi : public base_v_f<Prj, CT, P>
  103. {
  104. typedef base_v_f<Prj, CT, P> base_t;
  105. public:
  106. base_v_fi(P const& params)
  107. : base_t(params)
  108. {}
  109. template <typename ProjP>
  110. base_v_fi(P const& params, ProjP const& proj_params)
  111. : base_t(params, proj_params)
  112. {}
  113. virtual void inv(CT& xy_x, CT& xy_y, CT& lp_lon, CT& lp_lat) const
  114. {
  115. this->m_proj.inv(xy_x, xy_y, lp_lon, lp_lat);
  116. }
  117. };
  118. } // namespace detail
  119. #endif // DOXYGEN_NO_DETAIL
  120. }}} // namespace boost::geometry::projections
  121. #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP