123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- #ifndef BOOST_GEOMETRY_PROJECTIONS_CEA_HPP
- #define BOOST_GEOMETRY_PROJECTIONS_CEA_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_auth.hpp>
- #include <boost/geometry/srs/projections/impl/pj_param.hpp>
- #include <boost/geometry/srs/projections/impl/pj_qsfn.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 cea
- {
- static const double epsilon = 1e-10;
- template <typename T>
- struct par_cea
- {
- T qp;
- detail::apa<T> apa;
- };
- template <typename T, typename Parameters>
- struct base_cea_ellipsoid
- {
- par_cea<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
- {
- xy_x = par.k0 * lp_lon;
- xy_y = .5 * pj_qsfn(sin(lp_lat), par.e, par.one_es) / par.k0;
- }
-
-
- inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
- lp_lat = pj_authlat(asin( 2. * xy_y * par.k0 / this->m_proj_parm.qp), this->m_proj_parm.apa);
- lp_lon = xy_x / par.k0;
- }
- static inline std::string get_name()
- {
- return "cea_ellipsoid";
- }
- };
- template <typename T, typename Parameters>
- struct base_cea_spheroid
- {
- par_cea<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
- {
- xy_x = par.k0 * lp_lon;
- xy_y = sin(lp_lat) / par.k0;
- }
-
-
- inline void inv(Parameters const& par, T const& xy_x, T xy_y, T& lp_lon, T& lp_lat) const
- {
- static const T half_pi = detail::half_pi<T>();
- T t;
- if ((t = fabs(xy_y *= par.k0)) - epsilon <= 1.) {
- if (t >= 1.)
- lp_lat = xy_y < 0. ? -half_pi : half_pi;
- else
- lp_lat = asin(xy_y);
- lp_lon = xy_x / par.k0;
- } else
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- static inline std::string get_name()
- {
- return "cea_spheroid";
- }
- };
-
- template <typename Params, typename Parameters, typename T>
- inline void setup_cea(Params const& params, Parameters& par, par_cea<T>& proj_parm)
- {
- T t = 0;
- if (pj_param_r<srs::spar::lat_ts>(params, "lat_ts", srs::dpar::lat_ts, t)) {
- par.k0 = cos(t);
- if (par.k0 < 0.) {
- BOOST_THROW_EXCEPTION( projection_exception(error_lat_ts_larger_than_90) );
- }
- }
- if (par.es != 0.0) {
- t = sin(t);
- par.k0 /= sqrt(1. - par.es * t * t);
- par.e = sqrt(par.es);
- proj_parm.apa = pj_authset<T>(par.es);
- proj_parm.qp = pj_qsfn(T(1), par.e, par.one_es);
- }
- }
- }}
- #endif
-
- template <typename T, typename Parameters>
- struct cea_ellipsoid : public detail::cea::base_cea_ellipsoid<T, Parameters>
- {
- template <typename Params>
- inline cea_ellipsoid(Params const& params, Parameters & par)
- {
- detail::cea::setup_cea(params, par, this->m_proj_parm);
- }
- };
-
- template <typename T, typename Parameters>
- struct cea_spheroid : public detail::cea::base_cea_spheroid<T, Parameters>
- {
- template <typename Params>
- inline cea_spheroid(Params const& params, Parameters & par)
- {
- detail::cea::setup_cea(params, par, this->m_proj_parm);
- }
- };
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI2(srs::spar::proj_cea, cea_spheroid, cea_ellipsoid)
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI2(cea_entry, cea_spheroid, cea_ellipsoid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(cea_init)
- {
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(cea, cea_entry);
- }
- }
- #endif
- }
- }}
- #endif
|