File indexing completed on 2025-01-18 09:35:41
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_EQDC_HPP
0041 #define BOOST_GEOMETRY_PROJECTIONS_EQDC_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_mlfn.hpp>
0047 #include <boost/geometry/srs/projections/impl/pj_msfn.hpp>
0048 #include <boost/geometry/srs/projections/impl/pj_param.hpp>
0049 #include <boost/geometry/srs/projections/impl/projects.hpp>
0050
0051 #include <boost/geometry/util/math.hpp>
0052
0053 #include <boost/math/special_functions/hypot.hpp>
0054
0055 namespace boost { namespace geometry
0056 {
0057
0058 namespace projections
0059 {
0060 #ifndef DOXYGEN_NO_DETAIL
0061 namespace detail { namespace eqdc
0062 {
0063
0064 static const double epsilon10 = 1.e-10;
0065
0066 template <typename T>
0067 struct par_eqdc
0068 {
0069 T phi1;
0070 T phi2;
0071 T n;
0072 T rho0;
0073 T c;
0074 detail::en<T> en;
0075 bool ellips;
0076 };
0077
0078 template <typename T, typename Parameters>
0079 struct base_eqdc_ellipsoid
0080 {
0081 par_eqdc<T> m_proj_parm;
0082
0083
0084
0085 inline void fwd(Parameters const& , T lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
0086 {
0087 T rho = 0.0;
0088
0089 rho = this->m_proj_parm.c - (this->m_proj_parm.ellips ? pj_mlfn(lp_lat, sin(lp_lat),
0090 cos(lp_lat), this->m_proj_parm.en) : lp_lat);
0091 xy_x = rho * sin( lp_lon *= this->m_proj_parm.n );
0092 xy_y = this->m_proj_parm.rho0 - rho * cos(lp_lon);
0093 }
0094
0095
0096
0097 inline void inv(Parameters const& par, T xy_x, T xy_y, T& lp_lon, T& lp_lat) const
0098 {
0099 static T const half_pi = detail::half_pi<T>();
0100
0101 T rho = 0.0;
0102
0103 if ((rho = boost::math::hypot(xy_x, xy_y = this->m_proj_parm.rho0 - xy_y)) != 0.0 ) {
0104 if (this->m_proj_parm.n < 0.) {
0105 rho = -rho;
0106 xy_x = -xy_x;
0107 xy_y = -xy_y;
0108 }
0109 lp_lat = this->m_proj_parm.c - rho;
0110 if (this->m_proj_parm.ellips)
0111 lp_lat = pj_inv_mlfn(lp_lat, par.es, this->m_proj_parm.en);
0112 lp_lon = atan2(xy_x, xy_y) / this->m_proj_parm.n;
0113 } else {
0114 lp_lon = 0.;
0115 lp_lat = this->m_proj_parm.n > 0. ? half_pi : -half_pi;
0116 }
0117 }
0118
0119 static inline std::string get_name()
0120 {
0121 return "eqdc_ellipsoid";
0122 }
0123
0124 };
0125
0126
0127 template <typename Params, typename Parameters, typename T>
0128 inline void setup_eqdc(Params const& params, Parameters& par, par_eqdc<T>& proj_parm)
0129 {
0130 T cosphi, sinphi;
0131 int secant;
0132
0133 proj_parm.phi1 = pj_get_param_r<T, srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1);
0134 proj_parm.phi2 = pj_get_param_r<T, srs::spar::lat_2>(params, "lat_2", srs::dpar::lat_2);
0135
0136 if (fabs(proj_parm.phi1 + proj_parm.phi2) < epsilon10)
0137 BOOST_THROW_EXCEPTION( projection_exception(error_conic_lat_equal) );
0138
0139 proj_parm.en = pj_enfn<T>(par.es);
0140
0141 proj_parm.n = sinphi = sin(proj_parm.phi1);
0142 cosphi = cos(proj_parm.phi1);
0143 secant = fabs(proj_parm.phi1 - proj_parm.phi2) >= epsilon10;
0144 if( (proj_parm.ellips = (par.es > 0.)) ) {
0145 double ml1, m1;
0146
0147 m1 = pj_msfn(sinphi, cosphi, par.es);
0148 ml1 = pj_mlfn(proj_parm.phi1, sinphi, cosphi, proj_parm.en);
0149 if (secant) {
0150 sinphi = sin(proj_parm.phi2);
0151 cosphi = cos(proj_parm.phi2);
0152 proj_parm.n = (m1 - pj_msfn(sinphi, cosphi, par.es)) /
0153 (pj_mlfn(proj_parm.phi2, sinphi, cosphi, proj_parm.en) - ml1);
0154 }
0155 proj_parm.c = ml1 + m1 / proj_parm.n;
0156 proj_parm.rho0 = proj_parm.c - pj_mlfn(par.phi0, sin(par.phi0),
0157 cos(par.phi0), proj_parm.en);
0158 } else {
0159 if (secant)
0160 proj_parm.n = (cosphi - cos(proj_parm.phi2)) / (proj_parm.phi2 - proj_parm.phi1);
0161 proj_parm.c = proj_parm.phi1 + cos(proj_parm.phi1) / proj_parm.n;
0162 proj_parm.rho0 = proj_parm.c - par.phi0;
0163 }
0164 }
0165
0166 }}
0167 #endif
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185 template <typename T, typename Parameters>
0186 struct eqdc_ellipsoid : public detail::eqdc::base_eqdc_ellipsoid<T, Parameters>
0187 {
0188 template <typename Params>
0189 inline eqdc_ellipsoid(Params const& params, Parameters const& par)
0190 {
0191 detail::eqdc::setup_eqdc(params, par, this->m_proj_parm);
0192 }
0193 };
0194
0195 #ifndef DOXYGEN_NO_DETAIL
0196 namespace detail
0197 {
0198
0199
0200 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_eqdc, eqdc_ellipsoid)
0201
0202
0203 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(eqdc_entry, eqdc_ellipsoid)
0204
0205 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(eqdc_init)
0206 {
0207 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(eqdc, eqdc_entry);
0208 }
0209
0210 }
0211 #endif
0212
0213 }
0214
0215 }}
0216
0217 #endif
0218