123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- #ifndef BOOST_GEOMETRY_PROJECTIONS_AITOFF_HPP
- #define BOOST_GEOMETRY_PROJECTIONS_AITOFF_HPP
- #include <boost/core/ignore_unused.hpp>
- #include <boost/geometry/srs/projections/impl/base_static.hpp>
- #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
- #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
- #include <boost/geometry/srs/projections/impl/pj_param.hpp>
- #include <boost/geometry/srs/projections/impl/projects.hpp>
- #include <boost/geometry/util/math.hpp>
- namespace boost { namespace geometry
- {
- namespace projections
- {
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail { namespace aitoff
- {
- enum mode_type {
- mode_aitoff = 0,
- mode_winkel_tripel = 1
- };
- template <typename T>
- struct par_aitoff
- {
- T cosphi1;
- mode_type mode;
- };
- template <typename T, typename Parameters>
- struct base_aitoff_spheroid
- {
- par_aitoff<T> m_proj_parm;
-
-
- inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
- T c, d;
- if((d = acos(cos(lp_lat) * cos(c = 0.5 * lp_lon)))) {
- xy_x = 2. * d * cos(lp_lat) * sin(c) * (xy_y = 1. / sin(d));
- xy_y *= d * sin(lp_lat);
- } else
- xy_x = xy_y = 0.;
- if (this->m_proj_parm.mode == mode_winkel_tripel) {
- xy_x = (xy_x + lp_lon * this->m_proj_parm.cosphi1) * 0.5;
- xy_y = (xy_y + lp_lat) * 0.5;
- }
- }
-
-
-
- inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
- static const T pi = detail::pi<T>();
- static const T two_pi = detail::two_pi<T>();
- static const T epsilon = 1e-12;
- int iter, max_iter = 10, round = 0, max_round = 20;
- T D, C, f1, f2, f1p, f1l, f2p, f2l, dp, dl, sl, sp, cp, cl, x, y;
- if ((fabs(xy_x) < epsilon) && (fabs(xy_y) < epsilon )) {
- lp_lat = 0.; lp_lon = 0.;
- return;
- }
-
- lp_lat = xy_y; lp_lon = xy_x;
- do {
- iter = 0;
- do {
- sl = sin(lp_lon * 0.5); cl = cos(lp_lon * 0.5);
- sp = sin(lp_lat); cp = cos(lp_lat);
- D = cp * cl;
- C = 1. - D * D;
- D = acos(D) / math::pow(C, T(1.5));
- f1 = 2. * D * C * cp * sl;
- f2 = D * C * sp;
- f1p = 2.* (sl * cl * sp * cp / C - D * sp * sl);
- f1l = cp * cp * sl * sl / C + D * cp * cl * sp * sp;
- f2p = sp * sp * cl / C + D * sl * sl * cp;
- f2l = 0.5 * (sp * cp * sl / C - D * sp * cp * cp * sl * cl);
- if (this->m_proj_parm.mode == mode_winkel_tripel) {
- f1 = 0.5 * (f1 + lp_lon * this->m_proj_parm.cosphi1);
- f2 = 0.5 * (f2 + lp_lat);
- f1p *= 0.5;
- f1l = 0.5 * (f1l + this->m_proj_parm.cosphi1);
- f2p = 0.5 * (f2p + 1.);
- f2l *= 0.5;
- }
- f1 -= xy_x; f2 -= xy_y;
- dl = (f2 * f1p - f1 * f2p) / (dp = f1p * f2l - f2p * f1l);
- dp = (f1 * f2l - f2 * f1l) / dp;
- dl = fmod(dl, pi);
- lp_lat -= dp; lp_lon -= dl;
- } while ((fabs(dp) > epsilon || fabs(dl) > epsilon) && (iter++ < max_iter));
- if (lp_lat > two_pi) lp_lat -= 2.*(lp_lat-two_pi);
- if (lp_lat < -two_pi) lp_lat -= 2.*(lp_lat+two_pi);
- if ((fabs(fabs(lp_lat) - two_pi) < epsilon) && (!this->m_proj_parm.mode)) lp_lon = 0.;
-
- if((D = acos(cos(lp_lat) * cos(C = 0.5 * lp_lon))) != 0.0) {
- x = 2. * D * cos(lp_lat) * sin(C) * (y = 1. / sin(D));
- y *= D * sin(lp_lat);
- } else
- x = y = 0.;
- if (this->m_proj_parm.mode == mode_winkel_tripel) {
- x = (x + lp_lon * this->m_proj_parm.cosphi1) * 0.5;
- y = (y + lp_lat) * 0.5;
- }
-
- } while (((fabs(xy_x-x) > epsilon) || (fabs(xy_y-y) > epsilon)) && (round++ < max_round));
- if (iter == max_iter && round == max_round)
- {
- BOOST_THROW_EXCEPTION( projection_exception(error_non_convergent) );
-
- }
- }
- static inline std::string get_name()
- {
- return "aitoff_spheroid";
- }
- };
- template <typename Parameters>
- inline void setup(Parameters& par)
- {
- par.es = 0.;
- }
-
- template <typename Parameters, typename T>
- inline void setup_aitoff(Parameters& par, par_aitoff<T>& proj_parm)
- {
- proj_parm.mode = mode_aitoff;
- setup(par);
- }
-
- template <typename Params, typename Parameters, typename T>
- inline void setup_wintri(Params& params, Parameters& par, par_aitoff<T>& proj_parm)
- {
- static const T two_div_pi = detail::two_div_pi<T>();
- T phi1;
- proj_parm.mode = mode_winkel_tripel;
- if (pj_param_r<srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1, phi1)) {
- if ((proj_parm.cosphi1 = cos(phi1)) == 0.)
- BOOST_THROW_EXCEPTION( projection_exception(error_lat_larger_than_90) );
- } else
- proj_parm.cosphi1 = two_div_pi;
- setup(par);
- }
- }}
- #endif
-
- template <typename T, typename Parameters>
- struct aitoff_spheroid : public detail::aitoff::base_aitoff_spheroid<T, Parameters>
- {
- template <typename Params>
- inline aitoff_spheroid(Params const& , Parameters & par)
- {
- detail::aitoff::setup_aitoff(par, this->m_proj_parm);
- }
- };
-
- template <typename T, typename Parameters>
- struct wintri_spheroid : public detail::aitoff::base_aitoff_spheroid<T, Parameters>
- {
- template <typename Params>
- inline wintri_spheroid(Params const& params, Parameters & par)
- {
- detail::aitoff::setup_wintri(params, par, this->m_proj_parm);
- }
- };
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_aitoff, aitoff_spheroid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_wintri, wintri_spheroid)
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(aitoff_entry, aitoff_spheroid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(wintri_entry, wintri_spheroid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(aitoff_init)
- {
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(aitoff, aitoff_entry)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(wintri, wintri_entry)
- }
- }
- #endif
- }
- }}
- #endif
|