diff options
Diffstat (limited to 'boost/geometry/srs/projections/proj/natearth.hpp')
-rw-r--r-- | boost/geometry/srs/projections/proj/natearth.hpp | 111 |
1 files changed, 55 insertions, 56 deletions
diff --git a/boost/geometry/srs/projections/proj/natearth.hpp b/boost/geometry/srs/projections/proj/natearth.hpp index dcd259d9d1..47da25b9e2 100644 --- a/boost/geometry/srs/projections/proj/natearth.hpp +++ b/boost/geometry/srs/projections/proj/natearth.hpp @@ -1,13 +1,9 @@ -#ifndef BOOST_GEOMETRY_PROJECTIONS_NATEARTH_HPP -#define BOOST_GEOMETRY_PROJECTIONS_NATEARTH_HPP - -// Boost.Geometry - extensions-gis-projections (based on PROJ4) -// This file is automatically generated. DO NOT EDIT. +// Boost.Geometry - gis-projections (based on PROJ4) // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands. -// This file was modified by Oracle on 2017. -// Modifications copyright (c) 2017, Oracle and/or its affiliates. +// This file was modified by Oracle on 2017, 2018. +// Modifications copyright (c) 2017-2018, Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle. // Use, modification and distribution is subject to the Boost Software License, @@ -19,23 +15,10 @@ // PROJ4 is maintained by Frank Warmerdam // PROJ4 is converted to Boost.Geometry by Barend Gehrels -// Last updated version of proj: 4.9.1 +// Last updated version of proj: 5.0.0 // Original copyright notice: -// The Natural Earth projection was designed by Tom Patterson, US National Park -// Service, in 2007, using Flex Projector. The shape of the original projection -// was defined at every 5 degrees and piece-wise cubic spline interpolation was -// used to compute the complete graticule. -// The code here uses polynomial functions instead of cubic splines and -// is therefore much simpler to program. The polynomial approximation was -// developed by Bojan Savric, in collaboration with Tom Patterson and Bernhard -// Jenny, Institute of Cartography, ETH Zurich. It slightly deviates from -// Patterson's original projection by adding additional curvature to meridians -// where they meet the horizontal pole line. This improvement is by intention -// and designed in collaboration with Tom Patterson. -// Port to PROJ.4 by Bernhard Jenny, 6 June 2011 - // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation @@ -54,6 +37,22 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +// The Natural Earth projection was designed by Tom Patterson, US National Park +// Service, in 2007, using Flex Projector. The shape of the original projection +// was defined at every 5 degrees and piece-wise cubic spline interpolation was +// used to compute the complete graticule. +// The code here uses polynomial functions instead of cubic splines and +// is therefore much simpler to program. The polynomial approximation was +// developed by Bojan Savric, in collaboration with Tom Patterson and Bernhard +// Jenny, Institute of Cartography, ETH Zurich. It slightly deviates from +// Patterson's original projection by adding additional curvature to meridians +// where they meet the horizontal pole line. This improvement is by intention +// and designed in collaboration with Tom Patterson. +// Port to PROJ.4 by Bernhard Jenny, 6 June 2011 + +#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> @@ -64,7 +63,7 @@ namespace boost { namespace geometry namespace srs { namespace par4 { - struct natearth {}; + struct natearth {}; // Natural Earth }} //namespace srs::par4 @@ -89,31 +88,28 @@ namespace projections static const double C2 = (7 * B2); static const double C3 = (9 * B3); static const double C4 = (11 * B4); - static const double EPS = 1e-11; - //static const double MAX_Y = (0.8707 * 0.52 * geometry::math::pi<double>()); + static const double epsilon = 1e-11; template <typename T> - inline T MAX_Y() { return (0.8707 * 0.52 * detail::ONEPI<T>()); } + inline T max_y() { return (0.8707 * 0.52 * detail::pi<T>()); } + + /* Not sure at all of the appropriate number for max_iter... */ + static const int max_iter = 100; // template class, using CRTP to implement forward/inverse - template <typename CalculationType, typename Parameters> - struct base_natearth_spheroid : public base_t_fi<base_natearth_spheroid<CalculationType, Parameters>, - CalculationType, Parameters> + template <typename T, typename Parameters> + struct base_natearth_spheroid + : public base_t_fi<base_natearth_spheroid<T, Parameters>, T, Parameters> { - - typedef CalculationType geographic_type; - typedef CalculationType cartesian_type; - - inline base_natearth_spheroid(const Parameters& par) - : base_t_fi<base_natearth_spheroid<CalculationType, Parameters>, - CalculationType, Parameters>(*this, par) {} + : base_t_fi<base_natearth_spheroid<T, Parameters>, T, Parameters>(*this, par) + {} // FORWARD(s_forward) spheroid // Project coordinates from geographic (lon, lat) to cartesian (x, y) - inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const + inline void fwd(T& lp_lon, T& lp_lat, T& xy_x, T& xy_y) const { - CalculationType phi2, phi4; + T phi2, phi4; phi2 = lp_lat * lp_lat; phi4 = phi2 * phi2; @@ -123,31 +119,34 @@ namespace projections // INVERSE(s_inverse) spheroid // Project coordinates from cartesian (x, y) to geographic (lon, lat) - inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const + inline void inv(T& xy_x, T& xy_y, T& lp_lon, T& lp_lat) const { - static const CalculationType MAX_Y = natearth::MAX_Y<CalculationType>(); + static const T max_y = natearth::max_y<T>(); - CalculationType yc, tol, y2, y4, f, fder; + T yc, tol, y2, y4, f, fder; + int i; /* make sure y is inside valid range */ - if (xy_y > MAX_Y) { - xy_y = MAX_Y; - } else if (xy_y < -MAX_Y) { - xy_y = -MAX_Y; + if (xy_y > max_y) { + xy_y = max_y; + } else if (xy_y < -max_y) { + xy_y = -max_y; } /* latitude */ yc = xy_y; - for (;;) { /* Newton-Raphson */ + for (i = max_iter; i ; --i) { /* Newton-Raphson */ 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) < EPS) { + if (fabs(tol) < epsilon) { break; } } + if( i == 0 ) + BOOST_THROW_EXCEPTION( projection_exception(error_non_convergent) ); lp_lat = yc; /* longitude */ @@ -184,10 +183,10 @@ namespace projections \par Example \image html ex_natearth.gif */ - template <typename CalculationType, typename Parameters> - struct natearth_spheroid : public detail::natearth::base_natearth_spheroid<CalculationType, Parameters> + template <typename T, typename Parameters> + struct natearth_spheroid : public detail::natearth::base_natearth_spheroid<T, Parameters> { - inline natearth_spheroid(const Parameters& par) : detail::natearth::base_natearth_spheroid<CalculationType, Parameters>(par) + inline natearth_spheroid(const Parameters& par) : detail::natearth::base_natearth_spheroid<T, Parameters>(par) { detail::natearth::setup_natearth(this->m_par); } @@ -201,20 +200,20 @@ namespace projections BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::natearth, natearth_spheroid, natearth_spheroid) // Factory entry(s) - template <typename CalculationType, typename Parameters> - class natearth_entry : public detail::factory_entry<CalculationType, Parameters> + template <typename T, typename Parameters> + class natearth_entry : public detail::factory_entry<T, Parameters> { public : - virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const + virtual base_v<T, Parameters>* create_new(const Parameters& par) const { - return new base_v_fi<natearth_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par); + return new base_v_fi<natearth_spheroid<T, Parameters>, T, Parameters>(par); } }; - template <typename CalculationType, typename Parameters> - inline void natearth_init(detail::base_factory<CalculationType, Parameters>& factory) + template <typename T, typename Parameters> + inline void natearth_init(detail::base_factory<T, Parameters>& factory) { - factory.add_to_factory("natearth", new natearth_entry<CalculationType, Parameters>); + factory.add_to_factory("natearth", new natearth_entry<T, Parameters>); } } // namespace detail |