File indexing completed on 2025-01-18 09:35:44
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
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 #ifndef BOOST_GEOMETRY_PROJECTIONS_NATEARTH_HPP
0054 #define BOOST_GEOMETRY_PROJECTIONS_NATEARTH_HPP
0055
0056 #include <boost/geometry/srs/projections/impl/base_static.hpp>
0057 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
0058 #include <boost/geometry/srs/projections/impl/projects.hpp>
0059 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
0060
0061 namespace boost { namespace geometry
0062 {
0063
0064 namespace projections
0065 {
0066 #ifndef DOXYGEN_NO_DETAIL
0067 namespace detail { namespace natearth
0068 {
0069
0070 static const double A0 = 0.8707;
0071 static const double A1 = -0.131979;
0072 static const double A2 = -0.013791;
0073 static const double A3 = 0.003971;
0074 static const double A4 = -0.001529;
0075 static const double B0 = 1.007226;
0076 static const double B1 = 0.015085;
0077 static const double B2 = -0.044475;
0078 static const double B3 = 0.028874;
0079 static const double B4 = -0.005916;
0080 static const double C0 = B0;
0081 static const double C1 = (3 * B1);
0082 static const double C2 = (7 * B2);
0083 static const double C3 = (9 * B3);
0084 static const double C4 = (11 * B4);
0085 static const double epsilon = 1e-11;
0086
0087 template <typename T>
0088 inline T max_y() { return (0.8707 * 0.52 * detail::pi<T>()); }
0089
0090
0091 static const int max_iter = 100;
0092
0093 template <typename T, typename Parameters>
0094 struct base_natearth_spheroid
0095 {
0096
0097
0098 inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
0099 {
0100 T phi2, phi4;
0101
0102 phi2 = lp_lat * lp_lat;
0103 phi4 = phi2 * phi2;
0104 xy_x = lp_lon * (A0 + phi2 * (A1 + phi2 * (A2 + phi4 * phi2 * (A3 + phi2 * A4))));
0105 xy_y = lp_lat * (B0 + phi2 * (B1 + phi4 * (B2 + B3 * phi2 + B4 * phi4)));
0106 }
0107
0108
0109
0110 inline void inv(Parameters const& , T const& xy_x, T xy_y, T& lp_lon, T& lp_lat) const
0111 {
0112 static const T max_y = natearth::max_y<T>();
0113
0114 T yc, tol, y2, y4, f, fder;
0115 int i;
0116
0117
0118 if (xy_y > max_y) {
0119 xy_y = max_y;
0120 } else if (xy_y < -max_y) {
0121 xy_y = -max_y;
0122 }
0123
0124
0125 yc = xy_y;
0126 for (i = max_iter; i ; --i) {
0127 y2 = yc * yc;
0128 y4 = y2 * y2;
0129 f = (yc * (B0 + y2 * (B1 + y4 * (B2 + B3 * y2 + B4 * y4)))) - xy_y;
0130 fder = C0 + y2 * (C1 + y4 * (C2 + C3 * y2 + C4 * y4));
0131 yc -= tol = f / fder;
0132 if (fabs(tol) < epsilon) {
0133 break;
0134 }
0135 }
0136 if( i == 0 )
0137 BOOST_THROW_EXCEPTION( projection_exception(error_non_convergent) );
0138 lp_lat = yc;
0139
0140
0141 y2 = yc * yc;
0142 lp_lon = xy_x / (A0 + y2 * (A1 + y2 * (A2 + y2 * y2 * y2 * (A3 + y2 * A4))));
0143 }
0144
0145 static inline std::string get_name()
0146 {
0147 return "natearth_spheroid";
0148 }
0149
0150 };
0151
0152
0153 template <typename Parameters>
0154 inline void setup_natearth(Parameters& par)
0155 {
0156 par.es = 0;
0157 }
0158
0159 }}
0160 #endif
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174 template <typename T, typename Parameters>
0175 struct natearth_spheroid : public detail::natearth::base_natearth_spheroid<T, Parameters>
0176 {
0177 template <typename Params>
0178 inline natearth_spheroid(Params const& , Parameters & par)
0179 {
0180 detail::natearth::setup_natearth(par);
0181 }
0182 };
0183
0184 #ifndef DOXYGEN_NO_DETAIL
0185 namespace detail
0186 {
0187
0188
0189 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_natearth, natearth_spheroid)
0190
0191
0192 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(natearth_entry, natearth_spheroid)
0193
0194 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(natearth_init)
0195 {
0196 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(natearth, natearth_entry)
0197 }
0198
0199 }
0200 #endif
0201
0202 }
0203
0204 }}
0205
0206 #endif
0207