File indexing completed on 2025-01-18 09:35:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #ifndef BOOST_GEOMETRY_PROJECTIONS_LAGRNG_HPP
0041 #define BOOST_GEOMETRY_PROJECTIONS_LAGRNG_HPP
0042
0043 #include <boost/geometry/srs/projections/impl/base_static.hpp>
0044 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
0045 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
0046 #include <boost/geometry/srs/projections/impl/pj_param.hpp>
0047 #include <boost/geometry/srs/projections/impl/projects.hpp>
0048
0049 #include <boost/geometry/util/math.hpp>
0050
0051 namespace boost { namespace geometry
0052 {
0053
0054 namespace projections
0055 {
0056 #ifndef DOXYGEN_NO_DETAIL
0057 namespace detail { namespace lagrng
0058 {
0059
0060 static const double tolerance = 1e-10;
0061
0062 template <typename T>
0063 struct par_lagrng
0064 {
0065 T a1;
0066 T rw;
0067 T hrw;
0068 };
0069
0070 template <typename T, typename Parameters>
0071 struct base_lagrng_spheroid
0072 {
0073 par_lagrng<T> m_proj_parm;
0074
0075
0076
0077 inline void fwd(Parameters const& , T lp_lon, T lp_lat, T& xy_x, T& xy_y) const
0078 {
0079 static const T half_pi = detail::half_pi<T>();
0080
0081 T v, c;
0082
0083 if (fabs(fabs(lp_lat) - half_pi) < tolerance) {
0084 xy_x = 0;
0085 xy_y = lp_lat < 0 ? -2. : 2.;
0086 } else {
0087 lp_lat = sin(lp_lat);
0088 v = this->m_proj_parm.a1 * math::pow((T(1) + lp_lat)/(T(1) - lp_lat), this->m_proj_parm.hrw);
0089 if ((c = 0.5 * (v + 1./v) + cos(lp_lon *= this->m_proj_parm.rw)) < tolerance) {
0090 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
0091 }
0092 xy_x = 2. * sin(lp_lon) / c;
0093 xy_y = (v - 1./v) / c;
0094 }
0095 }
0096
0097 static inline std::string get_name()
0098 {
0099 return "lagrng_spheroid";
0100 }
0101
0102 };
0103
0104
0105 template <typename Params, typename Parameters, typename T>
0106 inline void setup_lagrng(Params const& params, Parameters& par, par_lagrng<T>& proj_parm)
0107 {
0108 T phi1;
0109
0110 proj_parm.rw = 0.0;
0111 bool is_w_set = pj_param_f<srs::spar::w>(params, "W", srs::dpar::w, proj_parm.rw);
0112
0113
0114 if (! is_w_set) {
0115 bool const use_defaults = ! pj_get_param_b<srs::spar::no_defs>(params, "no_defs", srs::dpar::no_defs);
0116 if (use_defaults) {
0117 proj_parm.rw = 2;
0118 }
0119 }
0120
0121 if (proj_parm.rw <= 0)
0122 BOOST_THROW_EXCEPTION( projection_exception(error_w_or_m_zero_or_less) );
0123
0124 proj_parm.rw = 1. / proj_parm.rw;
0125 proj_parm.hrw = 0.5 * proj_parm.rw;
0126 phi1 = pj_get_param_r<T, srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1);
0127 if (fabs(fabs(phi1 = sin(phi1)) - 1.) < tolerance)
0128 BOOST_THROW_EXCEPTION( projection_exception(error_lat_larger_than_90) );
0129
0130 proj_parm.a1 = math::pow((T(1) - phi1)/(T(1) + phi1), proj_parm.hrw);
0131
0132 par.es = 0.;
0133 }
0134
0135 }}
0136 #endif
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154 template <typename T, typename Parameters>
0155 struct lagrng_spheroid : public detail::lagrng::base_lagrng_spheroid<T, Parameters>
0156 {
0157 template <typename Params>
0158 inline lagrng_spheroid(Params const& params, Parameters & par)
0159 {
0160 detail::lagrng::setup_lagrng(params, par, this->m_proj_parm);
0161 }
0162 };
0163
0164 #ifndef DOXYGEN_NO_DETAIL
0165 namespace detail
0166 {
0167
0168
0169 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_lagrng, lagrng_spheroid)
0170
0171
0172 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(lagrng_entry, lagrng_spheroid)
0173
0174 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(lagrng_init)
0175 {
0176 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(lagrng, lagrng_entry);
0177 }
0178
0179 }
0180 #endif
0181
0182 }
0183
0184 }}
0185
0186 #endif
0187