Back to home page

EIC code displayed by LXR

 
 

    


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

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_LOXIM_HPP
0041 #define BOOST_GEOMETRY_PROJECTIONS_LOXIM_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 loxim
0058     {
0059             static const double epsilon = 1e-8;
0060 
0061             template <typename T>
0062             struct par_loxim
0063             {
0064                 T phi1;
0065                 T cosphi1;
0066                 T tanphi1;
0067             };
0068 
0069             template <typename T, typename Parameters>
0070             struct base_loxim_spheroid
0071             {
0072                 par_loxim<T> m_proj_parm;
0073 
0074                 // FORWARD(s_forward)  spheroid
0075                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
0076                 inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
0077                 {
0078                     static const T fourth_pi = detail::fourth_pi<T>();
0079                     static const T half_pi = detail::half_pi<T>();
0080 
0081                     xy_y = lp_lat - this->m_proj_parm.phi1;
0082                     if (fabs(xy_y) < epsilon)
0083                         xy_x = lp_lon * this->m_proj_parm.cosphi1;
0084                     else {
0085                         xy_x = fourth_pi + 0.5 * lp_lat;
0086                         if (fabs(xy_x) < epsilon || fabs(fabs(xy_x) - half_pi) < epsilon)
0087                             xy_x = 0.;
0088                         else
0089                             xy_x = lp_lon * xy_y / log( tan(xy_x) / this->m_proj_parm.tanphi1 );
0090                     }
0091                 }
0092 
0093                 // INVERSE(s_inverse)  spheroid
0094                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
0095                 inline void inv(Parameters const&, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
0096                 {
0097                     static const T fourth_pi = detail::fourth_pi<T>();
0098                     static const T half_pi = detail::half_pi<T>();
0099 
0100                     lp_lat = xy_y + this->m_proj_parm.phi1;
0101                     if (fabs(xy_y) < epsilon) {
0102                         lp_lon = xy_x / this->m_proj_parm.cosphi1;
0103                     } else {
0104                         lp_lon = fourth_pi + 0.5 * lp_lat;
0105                         if (fabs(lp_lon) < epsilon || fabs(fabs(lp_lon) - half_pi) < epsilon)
0106                             lp_lon = 0.;
0107                         else
0108                             lp_lon = xy_x * log( tan(lp_lon) / this->m_proj_parm.tanphi1 ) / xy_y ;
0109                     }
0110                 }
0111 
0112                 static inline std::string get_name()
0113                 {
0114                     return "loxim_spheroid";
0115                 }
0116 
0117             };
0118 
0119             // Loximuthal
0120             template <typename Params, typename Parameters, typename T>
0121             inline void setup_loxim(Params const& params, Parameters& par, par_loxim<T>& proj_parm)
0122             {
0123                 static const T fourth_pi = detail::fourth_pi<T>();
0124 
0125                 proj_parm.phi1 = pj_get_param_r<T, srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1);
0126                 proj_parm.cosphi1 = cos(proj_parm.phi1);
0127                 if (proj_parm.cosphi1 < epsilon)
0128                     BOOST_THROW_EXCEPTION( projection_exception(error_lat_larger_than_90) );
0129 
0130                 proj_parm.tanphi1 = tan(fourth_pi + 0.5 * proj_parm.phi1);
0131 
0132                 par.es = 0.;
0133             }
0134 
0135     }} // namespace detail::loxim
0136     #endif // doxygen
0137 
0138     /*!
0139         \brief Loximuthal 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          - Pseudocylindrical
0146          - Spheroid
0147         \par Projection parameters
0148          - lat_1: Latitude of first standard parallel (degrees)
0149         \par Example
0150         \image html ex_loxim.gif
0151     */
0152     template <typename T, typename Parameters>
0153     struct loxim_spheroid : public detail::loxim::base_loxim_spheroid<T, Parameters>
0154     {
0155         template <typename Params>
0156         inline loxim_spheroid(Params const& params, Parameters & par)
0157         {
0158             detail::loxim::setup_loxim(params, par, this->m_proj_parm);
0159         }
0160     };
0161 
0162     #ifndef DOXYGEN_NO_DETAIL
0163     namespace detail
0164     {
0165 
0166         // Static projection
0167         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_loxim, loxim_spheroid)
0168 
0169         // Factory entry(s)
0170         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(loxim_entry, loxim_spheroid)
0171 
0172         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(loxim_init)
0173         {
0174             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(loxim, loxim_entry)
0175         }
0176 
0177     } // namespace detail
0178     #endif // doxygen
0179 
0180 } // namespace projections
0181 
0182 }} // namespace boost::geometry
0183 
0184 #endif // BOOST_GEOMETRY_PROJECTIONS_LOXIM_HPP
0185