File indexing completed on 2025-01-18 09:35:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP
0014 #define BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP
0015
0016 #include <string>
0017
0018 #include <boost/geometry/srs/projections/exception.hpp>
0019 #include <boost/geometry/srs/projections/impl/projects.hpp>
0020
0021 namespace boost { namespace geometry { namespace projections
0022 {
0023
0024 #ifndef DOXYGEN_NO_DETAIL
0025 namespace detail
0026 {
0027
0028
0029
0030
0031
0032
0033
0034
0035 template <typename CT, typename P>
0036 class dynamic_wrapper_b
0037 {
0038 public :
0039 dynamic_wrapper_b(P const& par)
0040 : m_par(par)
0041 {}
0042
0043 virtual ~dynamic_wrapper_b() {}
0044
0045
0046 virtual void fwd(P const& par, CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const = 0;
0047
0048
0049 virtual void inv(P const& par, CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const = 0;
0050
0051
0052 template <typename LL, typename XY>
0053 inline bool forward(LL const& lp, XY& xy) const
0054 {
0055 try
0056 {
0057 pj_fwd(*this, m_par, lp, xy);
0058 return true;
0059 }
0060 catch (...)
0061 {
0062 return false;
0063 }
0064 }
0065
0066
0067 template <typename LL, typename XY>
0068 inline bool inverse(XY const& xy, LL& lp) const
0069 {
0070 try
0071 {
0072 pj_inv(*this, m_par, xy, lp);
0073 return true;
0074 }
0075 catch (projection_not_invertible_exception &)
0076 {
0077 BOOST_RETHROW
0078 }
0079 catch (...)
0080 {
0081 return false;
0082 }
0083 }
0084
0085
0086 std::string name() const { return m_par.id.name; }
0087
0088
0089 P const& params() const { return m_par; }
0090
0091
0092 P& mutable_params() { return m_par; }
0093
0094 protected:
0095 P m_par;
0096 };
0097
0098
0099 template <typename Prj, typename CT, typename P>
0100 class dynamic_wrapper_f
0101 : public dynamic_wrapper_b<CT, P>
0102 , protected Prj
0103 {
0104 typedef dynamic_wrapper_b<CT, P> base_t;
0105
0106 public:
0107 template <typename Params>
0108 dynamic_wrapper_f(Params const& params, P const& par)
0109 : base_t(par)
0110 , Prj(params, this->m_par)
0111 {}
0112
0113 template <typename Params, typename P3>
0114 dynamic_wrapper_f(Params const& params, P const& par, P3 const& p3)
0115 : base_t(par)
0116 , Prj(params, this->m_par, p3)
0117 {}
0118
0119 virtual void fwd(P const& par, CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const
0120 {
0121 prj().fwd(par, lp_lon, lp_lat, xy_x, xy_y);
0122 }
0123
0124 virtual void inv(P const& , CT const& , CT const& , CT& , CT& ) const
0125 {
0126 BOOST_THROW_EXCEPTION(projection_not_invertible_exception(this->name()));
0127 }
0128
0129 protected:
0130 Prj const& prj() const { return *this; }
0131 };
0132
0133
0134 template <typename Prj, typename CT, typename P>
0135 class dynamic_wrapper_fi : public dynamic_wrapper_f<Prj, CT, P>
0136 {
0137 typedef dynamic_wrapper_f<Prj, CT, P> base_t;
0138
0139 public:
0140 template <typename Params>
0141 dynamic_wrapper_fi(Params const& params, P const& par)
0142 : base_t(params, par)
0143 {}
0144
0145 template <typename Params, typename P3>
0146 dynamic_wrapper_fi(Params const& params, P const& par, P3 const& p3)
0147 : base_t(params, par, p3)
0148 {}
0149
0150 virtual void inv(P const& par, CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const
0151 {
0152 this->prj().inv(par, xy_x, xy_y, lp_lon, lp_lat);
0153 }
0154 };
0155
0156 }
0157 #endif
0158
0159 }}}
0160
0161 #endif