1 // Boost.Geometry - gis-projections (based on PROJ4)
3 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2017, 2018, 2019.
6 // Modifications copyright (c) 2017-2019, Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 // This file is converted from PROJ4, http://trac.osgeo.org/proj
14 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
15 // PROJ4 is maintained by Frank Warmerdam
16 // PROJ4 is converted to Boost.Geometry by Barend Gehrels
18 // Last updated version of proj: 5.0.0
20 // Original copyright notice:
22 // Permission is hereby granted, free of charge, to any person obtaining a
23 // copy of this software and associated documentation files (the "Software"),
24 // to deal in the Software without restriction, including without limitation
25 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
26 // and/or sell copies of the Software, and to permit persons to whom the
27 // Software is furnished to do so, subject to the following conditions:
29 // The above copyright notice and this permission notice shall be included
30 // in all copies or substantial portions of the Software.
32 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
33 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
35 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
37 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
38 // DEALINGS IN THE SOFTWARE.
40 #ifndef BOOST_GEOMETRY_PROJECTIONS_LAGRNG_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_LAGRNG_HPP
43 #include <boost/geometry/srs/projections/impl/base_static.hpp>
44 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
45 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
46 #include <boost/geometry/srs/projections/impl/pj_param.hpp>
47 #include <boost/geometry/srs/projections/impl/projects.hpp>
49 #include <boost/geometry/util/math.hpp>
51 namespace boost { namespace geometry
56 #ifndef DOXYGEN_NO_DETAIL
57 namespace detail { namespace lagrng
60 static const double tolerance = 1e-10;
70 template <typename T, typename Parameters>
71 struct base_lagrng_spheroid
73 par_lagrng<T> m_proj_parm;
75 // FORWARD(s_forward) spheroid
76 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
77 inline void fwd(Parameters const& , T lp_lon, T lp_lat, T& xy_x, T& xy_y) const
79 static const T half_pi = detail::half_pi<T>();
83 if (fabs(fabs(lp_lat) - half_pi) < tolerance) {
85 xy_y = lp_lat < 0 ? -2. : 2.;
88 v = this->m_proj_parm.a1 * math::pow((T(1) + lp_lat)/(T(1) - lp_lat), this->m_proj_parm.hrw);
89 if ((c = 0.5 * (v + 1./v) + cos(lp_lon *= this->m_proj_parm.rw)) < tolerance) {
90 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
92 xy_x = 2. * sin(lp_lon) / c;
93 xy_y = (v - 1./v) / c;
97 static inline std::string get_name()
99 return "lagrng_spheroid";
105 template <typename Params, typename Parameters, typename T>
106 inline void setup_lagrng(Params const& params, Parameters& par, par_lagrng<T>& proj_parm)
111 bool is_w_set = pj_param_f<srs::spar::w>(params, "W", srs::dpar::w, proj_parm.rw);
113 // Boost.Geometry specific, set default parameters manually
115 bool const use_defaults = ! pj_get_param_b<srs::spar::no_defs>(params, "no_defs", srs::dpar::no_defs);
121 if (proj_parm.rw <= 0)
122 BOOST_THROW_EXCEPTION( projection_exception(error_w_or_m_zero_or_less) );
124 proj_parm.rw = 1. / proj_parm.rw;
125 proj_parm.hrw = 0.5 * proj_parm.rw;
126 phi1 = pj_get_param_r<T, srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1);
127 if (fabs(fabs(phi1 = sin(phi1)) - 1.) < tolerance)
128 BOOST_THROW_EXCEPTION( projection_exception(error_lat_larger_than_90) );
130 proj_parm.a1 = math::pow((T(1) - phi1)/(T(1) + phi1), proj_parm.hrw);
135 }} // namespace detail::lagrng
139 \brief Lagrange projection
141 \tparam Geographic latlong point type
142 \tparam Cartesian xy point type
143 \tparam Parameters parameter type
144 \par Projection characteristics
148 \par Projection parameters
150 - lat_1: Latitude of first standard parallel (degrees)
152 \image html ex_lagrng.gif
154 template <typename T, typename Parameters>
155 struct lagrng_spheroid : public detail::lagrng::base_lagrng_spheroid<T, Parameters>
157 template <typename Params>
158 inline lagrng_spheroid(Params const& params, Parameters & par)
160 detail::lagrng::setup_lagrng(params, par, this->m_proj_parm);
164 #ifndef DOXYGEN_NO_DETAIL
169 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_lagrng, lagrng_spheroid)
172 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(lagrng_entry, lagrng_spheroid)
174 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(lagrng_init)
176 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(lagrng, lagrng_entry);
179 } // namespace detail
182 } // namespace projections
184 }} // namespace boost::geometry
186 #endif // BOOST_GEOMETRY_PROJECTIONS_LAGRNG_HPP