123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #ifndef BOOST_GEOMETRY_PROJECTIONS_HAMMER_HPP
- #define BOOST_GEOMETRY_PROJECTIONS_HAMMER_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>
- namespace boost { namespace geometry
- {
- namespace projections
- {
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail { namespace hammer
- {
- static const double epsilon = 1.0e-10;
- template <typename T>
- struct par_hammer
- {
- T w;
- T m, rm;
- };
- template <typename T, typename Parameters>
- struct base_hammer_spheroid
- {
- par_hammer<T> m_proj_parm;
-
-
- inline void fwd(Parameters const& , T lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
- T cosphi, d;
- d = sqrt(2./(1. + (cosphi = cos(lp_lat)) * cos(lp_lon *= this->m_proj_parm.w)));
- xy_x = this->m_proj_parm.m * d * cosphi * sin(lp_lon);
- xy_y = this->m_proj_parm.rm * d * sin(lp_lat);
- }
-
-
- inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
- T z;
- z = sqrt(1. - 0.25*this->m_proj_parm.w*this->m_proj_parm.w*xy_x*xy_x - 0.25*xy_y*xy_y);
- if (geometry::math::abs(2.*z*z-1.) < epsilon) {
- lp_lon = HUGE_VAL;
- lp_lat = HUGE_VAL;
- BOOST_THROW_EXCEPTION( projection_exception(error_lat_or_lon_exceed_limit) );
- } else {
- lp_lon = aatan2(this->m_proj_parm.w * xy_x * z,2. * z * z - 1)/this->m_proj_parm.w;
- lp_lat = aasin(z * xy_y);
- }
- }
- static inline std::string get_name()
- {
- return "hammer_spheroid";
- }
- };
-
- template <typename Params, typename Parameters, typename T>
- inline void setup_hammer(Params const& params, Parameters& par, par_hammer<T>& proj_parm)
- {
- T tmp;
- if (pj_param_f<srs::spar::w>(params, "W", srs::dpar::w, tmp)) {
- if ((proj_parm.w = fabs(tmp)) <= 0.)
- BOOST_THROW_EXCEPTION( projection_exception(error_w_or_m_zero_or_less) );
- } else
- proj_parm.w = .5;
- if (pj_param_f<srs::spar::m>(params, "M", srs::dpar::m, tmp)) {
- if ((proj_parm.m = fabs(tmp)) <= 0.)
- BOOST_THROW_EXCEPTION( projection_exception(error_w_or_m_zero_or_less) );
- } else
- proj_parm.m = 1.;
- proj_parm.rm = 1. / proj_parm.m;
- proj_parm.m /= proj_parm.w;
- par.es = 0.;
- }
- }}
- #endif
-
- template <typename T, typename Parameters>
- struct hammer_spheroid : public detail::hammer::base_hammer_spheroid<T, Parameters>
- {
- template <typename Params>
- inline hammer_spheroid(Params const& params, Parameters & par)
- {
- detail::hammer::setup_hammer(params, par, this->m_proj_parm);
- }
- };
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_hammer, hammer_spheroid)
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(hammer_entry, hammer_spheroid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(hammer_init)
- {
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(hammer, hammer_entry)
- }
- }
- #endif
- }
- }}
- #endif
|