123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- #ifndef BOOST_GEOMETRY_PROJECTIONS_NATEARTH_HPP
- #define BOOST_GEOMETRY_PROJECTIONS_NATEARTH_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>
- namespace boost { namespace geometry
- {
- namespace projections
- {
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail { namespace natearth
- {
- static const double A0 = 0.8707;
- static const double A1 = -0.131979;
- static const double A2 = -0.013791;
- static const double A3 = 0.003971;
- static const double A4 = -0.001529;
- static const double B0 = 1.007226;
- static const double B1 = 0.015085;
- static const double B2 = -0.044475;
- static const double B3 = 0.028874;
- static const double B4 = -0.005916;
- static const double C0 = B0;
- static const double C1 = (3 * B1);
- static const double C2 = (7 * B2);
- static const double C3 = (9 * B3);
- static const double C4 = (11 * B4);
- static const double epsilon = 1e-11;
- template <typename T>
- inline T max_y() { return (0.8707 * 0.52 * detail::pi<T>()); }
-
- static const int max_iter = 100;
- template <typename T, typename Parameters>
- struct base_natearth_spheroid
- {
-
-
- inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
- T phi2, phi4;
- phi2 = lp_lat * lp_lat;
- phi4 = phi2 * phi2;
- xy_x = lp_lon * (A0 + phi2 * (A1 + phi2 * (A2 + phi4 * phi2 * (A3 + phi2 * A4))));
- xy_y = lp_lat * (B0 + phi2 * (B1 + phi4 * (B2 + B3 * phi2 + B4 * phi4)));
- }
-
-
- inline void inv(Parameters const& , T const& xy_x, T xy_y, T& lp_lon, T& lp_lat) const
- {
- static const T max_y = natearth::max_y<T>();
- T yc, tol, y2, y4, f, fder;
- int i;
-
- if (xy_y > max_y) {
- xy_y = max_y;
- } else if (xy_y < -max_y) {
- xy_y = -max_y;
- }
-
- yc = xy_y;
- for (i = max_iter; i ; --i) {
- y2 = yc * yc;
- y4 = y2 * y2;
- f = (yc * (B0 + y2 * (B1 + y4 * (B2 + B3 * y2 + B4 * y4)))) - xy_y;
- fder = C0 + y2 * (C1 + y4 * (C2 + C3 * y2 + C4 * y4));
- yc -= tol = f / fder;
- if (fabs(tol) < epsilon) {
- break;
- }
- }
- if( i == 0 )
- BOOST_THROW_EXCEPTION( projection_exception(error_non_convergent) );
- lp_lat = yc;
-
- y2 = yc * yc;
- lp_lon = xy_x / (A0 + y2 * (A1 + y2 * (A2 + y2 * y2 * y2 * (A3 + y2 * A4))));
- }
- static inline std::string get_name()
- {
- return "natearth_spheroid";
- }
- };
-
- template <typename Parameters>
- inline void setup_natearth(Parameters& par)
- {
- par.es = 0;
- }
- }}
- #endif
-
- template <typename T, typename Parameters>
- struct natearth_spheroid : public detail::natearth::base_natearth_spheroid<T, Parameters>
- {
- template <typename Params>
- inline natearth_spheroid(Params const& , Parameters & par)
- {
- detail::natearth::setup_natearth(par);
- }
- };
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_natearth, natearth_spheroid)
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(natearth_entry, natearth_spheroid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(natearth_init)
- {
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(natearth, natearth_entry)
- }
- }
- #endif
- }
- }}
- #endif
|