File indexing completed on 2025-01-18 09:35:42
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_HAMMER_HPP
0041 #define BOOST_GEOMETRY_PROJECTIONS_HAMMER_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_param.hpp>
0047 #include <boost/geometry/srs/projections/impl/projects.hpp>
0048
0049 namespace boost { namespace geometry
0050 {
0051
0052 namespace projections
0053 {
0054 #ifndef DOXYGEN_NO_DETAIL
0055 namespace detail { namespace hammer
0056 {
0057 static const double epsilon = 1.0e-10;
0058
0059 template <typename T>
0060 struct par_hammer
0061 {
0062 T w;
0063 T m, rm;
0064 };
0065
0066 template <typename T, typename Parameters>
0067 struct base_hammer_spheroid
0068 {
0069 par_hammer<T> m_proj_parm;
0070
0071
0072
0073 inline void fwd(Parameters const& , T lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
0074 {
0075 T cosphi, d;
0076
0077 d = sqrt(2./(1. + (cosphi = cos(lp_lat)) * cos(lp_lon *= this->m_proj_parm.w)));
0078 xy_x = this->m_proj_parm.m * d * cosphi * sin(lp_lon);
0079 xy_y = this->m_proj_parm.rm * d * sin(lp_lat);
0080 }
0081
0082
0083
0084 inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
0085 {
0086 T z;
0087
0088 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);
0089 if (geometry::math::abs(2.*z*z-1.) < epsilon) {
0090 lp_lon = HUGE_VAL;
0091 lp_lat = HUGE_VAL;
0092 BOOST_THROW_EXCEPTION( projection_exception(error_lat_or_lon_exceed_limit) );
0093 } else {
0094 lp_lon = aatan2(this->m_proj_parm.w * xy_x * z,2. * z * z - 1)/this->m_proj_parm.w;
0095 lp_lat = aasin(z * xy_y);
0096 }
0097 }
0098
0099 static inline std::string get_name()
0100 {
0101 return "hammer_spheroid";
0102 }
0103
0104 };
0105
0106
0107 template <typename Params, typename Parameters, typename T>
0108 inline void setup_hammer(Params const& params, Parameters& par, par_hammer<T>& proj_parm)
0109 {
0110 T tmp;
0111
0112 if (pj_param_f<srs::spar::w>(params, "W", srs::dpar::w, tmp)) {
0113 if ((proj_parm.w = fabs(tmp)) <= 0.)
0114 BOOST_THROW_EXCEPTION( projection_exception(error_w_or_m_zero_or_less) );
0115 } else
0116 proj_parm.w = .5;
0117 if (pj_param_f<srs::spar::m>(params, "M", srs::dpar::m, tmp)) {
0118 if ((proj_parm.m = fabs(tmp)) <= 0.)
0119 BOOST_THROW_EXCEPTION( projection_exception(error_w_or_m_zero_or_less) );
0120 } else
0121 proj_parm.m = 1.;
0122
0123 proj_parm.rm = 1. / proj_parm.m;
0124 proj_parm.m /= proj_parm.w;
0125
0126 par.es = 0.;
0127 }
0128
0129 }}
0130 #endif
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 template <typename T, typename Parameters>
0149 struct hammer_spheroid : public detail::hammer::base_hammer_spheroid<T, Parameters>
0150 {
0151 template <typename Params>
0152 inline hammer_spheroid(Params const& params, Parameters & par)
0153 {
0154 detail::hammer::setup_hammer(params, par, this->m_proj_parm);
0155 }
0156 };
0157
0158 #ifndef DOXYGEN_NO_DETAIL
0159 namespace detail
0160 {
0161
0162
0163 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_hammer, hammer_spheroid)
0164
0165
0166 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(hammer_entry, hammer_spheroid)
0167
0168 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(hammer_init)
0169 {
0170 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(hammer, hammer_entry)
0171 }
0172
0173 }
0174 #endif
0175
0176 }
0177
0178 }}
0179
0180 #endif
0181