Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:43

0001 // Boost.Geometry - gis-projections (based on PROJ4)
0002 
0003 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // This file was modified by Oracle on 2017, 2018, 2019.
0006 // Modifications copyright (c) 2017-2019, Oracle and/or its affiliates.
0007 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
0008 
0009 // Use, modification and distribution is subject to the Boost Software License,
0010 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
0012 
0013 // This file is converted from PROJ4, http://trac.osgeo.org/proj
0014 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
0015 // PROJ4 is maintained by Frank Warmerdam
0016 // PROJ4 is converted to Boost.Geometry by Barend Gehrels
0017 
0018 // Last updated version of proj: 5.0.0
0019 
0020 // Original copyright notice:
0021 
0022 // Permission is hereby granted, free of charge, to any person obtaining a
0023 // copy of this software and associated documentation files (the "Software"),
0024 // to deal in the Software without restriction, including without limitation
0025 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
0026 // and/or sell copies of the Software, and to permit persons to whom the
0027 // Software is furnished to do so, subject to the following conditions:
0028 
0029 // The above copyright notice and this permission notice shall be included
0030 // in all copies or substantial portions of the Software.
0031 
0032 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0033 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0034 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0035 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0036 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0037 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0038 // DEALINGS IN THE SOFTWARE.
0039 
0040 #ifndef BOOST_GEOMETRY_PROJECTIONS_LAGRNG_HPP
0041 #define BOOST_GEOMETRY_PROJECTIONS_LAGRNG_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 #include <boost/geometry/util/math.hpp>
0050 
0051 namespace boost { namespace geometry
0052 {
0053 
0054 namespace projections
0055 {
0056     #ifndef DOXYGEN_NO_DETAIL
0057     namespace detail { namespace lagrng
0058     {
0059 
0060             static const double tolerance = 1e-10;
0061 
0062             template <typename T>
0063             struct par_lagrng
0064             {
0065                 T    a1;
0066                 T    rw;
0067                 T    hrw;
0068             };
0069 
0070             template <typename T, typename Parameters>
0071             struct base_lagrng_spheroid
0072             {
0073                 par_lagrng<T> m_proj_parm;
0074 
0075                 // FORWARD(s_forward)  spheroid
0076                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
0077                 inline void fwd(Parameters const& , T lp_lon, T lp_lat, T& xy_x, T& xy_y) const
0078                 {
0079                     static const T half_pi = detail::half_pi<T>();
0080 
0081                     T v, c;
0082 
0083                     if (fabs(fabs(lp_lat) - half_pi) < tolerance) {
0084                         xy_x = 0;
0085                         xy_y = lp_lat < 0 ? -2. : 2.;
0086                     } else {
0087                         lp_lat = sin(lp_lat);
0088                         v = this->m_proj_parm.a1 * math::pow((T(1) + lp_lat)/(T(1) - lp_lat), this->m_proj_parm.hrw);
0089                         if ((c = 0.5 * (v + 1./v) + cos(lp_lon *= this->m_proj_parm.rw)) < tolerance) {
0090                             BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
0091                         }
0092                         xy_x = 2. * sin(lp_lon) / c;
0093                         xy_y = (v - 1./v) / c;
0094                     }
0095                 }
0096 
0097                 static inline std::string get_name()
0098                 {
0099                     return "lagrng_spheroid";
0100                 }
0101 
0102             };
0103 
0104             // Lagrange
0105             template <typename Params, typename Parameters, typename T>
0106             inline void setup_lagrng(Params const& params, Parameters& par, par_lagrng<T>& proj_parm)
0107             {
0108                 T phi1;
0109 
0110                 proj_parm.rw = 0.0;
0111                 bool is_w_set = pj_param_f<srs::spar::w>(params, "W", srs::dpar::w, proj_parm.rw);
0112 
0113                 // Boost.Geometry specific, set default parameters manually
0114                 if (! is_w_set) {
0115                     bool const use_defaults = ! pj_get_param_b<srs::spar::no_defs>(params, "no_defs", srs::dpar::no_defs);
0116                     if (use_defaults) {
0117                         proj_parm.rw = 2;
0118                     }
0119                 }
0120 
0121                 if (proj_parm.rw <= 0)
0122                     BOOST_THROW_EXCEPTION( projection_exception(error_w_or_m_zero_or_less) );
0123 
0124                 proj_parm.rw = 1. / proj_parm.rw;
0125                 proj_parm.hrw = 0.5 * proj_parm.rw;
0126                 phi1 = pj_get_param_r<T, srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1);
0127                 if (fabs(fabs(phi1 = sin(phi1)) - 1.) < tolerance)
0128                     BOOST_THROW_EXCEPTION( projection_exception(error_lat_larger_than_90) );
0129 
0130                 proj_parm.a1 = math::pow((T(1) - phi1)/(T(1) + phi1), proj_parm.hrw);
0131 
0132                 par.es = 0.;
0133             }
0134 
0135     }} // namespace detail::lagrng
0136     #endif // doxygen
0137 
0138     /*!
0139         \brief Lagrange projection
0140         \ingroup projections
0141         \tparam Geographic latlong point type
0142         \tparam Cartesian xy point type
0143         \tparam Parameters parameter type
0144         \par Projection characteristics
0145          - Miscellaneous
0146          - Spheroid
0147          - no inverse
0148         \par Projection parameters
0149          - W (real)
0150          - lat_1: Latitude of first standard parallel (degrees)
0151         \par Example
0152         \image html ex_lagrng.gif
0153     */
0154     template <typename T, typename Parameters>
0155     struct lagrng_spheroid : public detail::lagrng::base_lagrng_spheroid<T, Parameters>
0156     {
0157         template <typename Params>
0158         inline lagrng_spheroid(Params const& params, Parameters & par)
0159         {
0160             detail::lagrng::setup_lagrng(params, par, this->m_proj_parm);
0161         }
0162     };
0163 
0164     #ifndef DOXYGEN_NO_DETAIL
0165     namespace detail
0166     {
0167 
0168         // Static projection
0169         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_lagrng, lagrng_spheroid)
0170 
0171         // Factory entry(s)
0172         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(lagrng_entry, lagrng_spheroid)
0173 
0174         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(lagrng_init)
0175         {
0176             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(lagrng, lagrng_entry);
0177         }
0178 
0179     } // namespace detail
0180     #endif // doxygen
0181 
0182 } // namespace projections
0183 
0184 }} // namespace boost::geometry
0185 
0186 #endif // BOOST_GEOMETRY_PROJECTIONS_LAGRNG_HPP
0187