123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- #ifndef BOOST_GEOMETRY_PROJECTIONS_SOMERC_HPP
- #define BOOST_GEOMETRY_PROJECTIONS_SOMERC_HPP
- #include <boost/geometry/util/math.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/projects.hpp>
- #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
- #include <boost/geometry/srs/projections/impl/aasincos.hpp>
- namespace boost { namespace geometry
- {
- namespace projections
- {
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail { namespace somerc
- {
- static const double epsilon = 1.e-10;
- static const int n_iter = 6;
- template <typename T>
- struct par_somerc
- {
- T K, c, hlf_e, kR, cosp0, sinp0;
- };
- template <typename T, typename Parameters>
- struct base_somerc_ellipsoid
- {
- par_somerc<T> m_proj_parm;
-
-
- inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
- static const T fourth_pi = detail::fourth_pi<T>();
- static const T half_pi = detail::half_pi<T>();
- T phip, lamp, phipp, lampp, sp, cp;
- sp = par.e * sin(lp_lat);
- phip = 2.* atan( exp( this->m_proj_parm.c * (
- log(tan(fourth_pi + 0.5 * lp_lat)) - this->m_proj_parm.hlf_e * log((1. + sp)/(1. - sp)))
- + this->m_proj_parm.K)) - half_pi;
- lamp = this->m_proj_parm.c * lp_lon;
- cp = cos(phip);
- phipp = aasin(this->m_proj_parm.cosp0 * sin(phip) - this->m_proj_parm.sinp0 * cp * cos(lamp));
- lampp = aasin(cp * sin(lamp) / cos(phipp));
- xy_x = this->m_proj_parm.kR * lampp;
- xy_y = this->m_proj_parm.kR * log(tan(fourth_pi + 0.5 * phipp));
- }
-
-
- inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
- static const T fourth_pi = detail::fourth_pi<T>();
- T phip, lamp, phipp, lampp, cp, esp, con, delp;
- int i;
- phipp = 2. * (atan(exp(xy_y / this->m_proj_parm.kR)) - fourth_pi);
- lampp = xy_x / this->m_proj_parm.kR;
- cp = cos(phipp);
- phip = aasin(this->m_proj_parm.cosp0 * sin(phipp) + this->m_proj_parm.sinp0 * cp * cos(lampp));
- lamp = aasin(cp * sin(lampp) / cos(phip));
- con = (this->m_proj_parm.K - log(tan(fourth_pi + 0.5 * phip)))/this->m_proj_parm.c;
- for (i = n_iter; i ; --i) {
- esp = par.e * sin(phip);
- delp = (con + log(tan(fourth_pi + 0.5 * phip)) - this->m_proj_parm.hlf_e *
- log((1. + esp)/(1. - esp)) ) *
- (1. - esp * esp) * cos(phip) * par.rone_es;
- phip -= delp;
- if (fabs(delp) < epsilon)
- break;
- }
- if (i) {
- lp_lat = phip;
- lp_lon = lamp / this->m_proj_parm.c;
- } else {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- }
- static inline std::string get_name()
- {
- return "somerc_ellipsoid";
- }
- };
-
- template <typename Parameters, typename T>
- inline void setup_somerc(Parameters const& par, par_somerc<T>& proj_parm)
- {
- static const T fourth_pi = detail::fourth_pi<T>();
- T cp, phip0, sp;
- proj_parm.hlf_e = 0.5 * par.e;
- cp = cos(par.phi0);
- cp *= cp;
- proj_parm.c = sqrt(1 + par.es * cp * cp * par.rone_es);
- sp = sin(par.phi0);
- proj_parm.cosp0 = cos( phip0 = aasin(proj_parm.sinp0 = sp / proj_parm.c) );
- sp *= par.e;
- proj_parm.K = log(tan(fourth_pi + 0.5 * phip0)) - proj_parm.c * (
- log(tan(fourth_pi + 0.5 * par.phi0)) - proj_parm.hlf_e *
- log((1. + sp) / (1. - sp)));
- proj_parm.kR = par.k0 * sqrt(par.one_es) / (1. - sp * sp);
- }
- }}
- #endif
-
- template <typename T, typename Parameters>
- struct somerc_ellipsoid : public detail::somerc::base_somerc_ellipsoid<T, Parameters>
- {
- template <typename Params>
- inline somerc_ellipsoid(Params const& , Parameters const& par)
- {
- detail::somerc::setup_somerc(par, this->m_proj_parm);
- }
- };
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_somerc, somerc_ellipsoid)
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(somerc_entry, somerc_ellipsoid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(somerc_init)
- {
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(somerc, somerc_entry)
- }
- }
- #endif
- }
- }}
- #endif
|