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_OCEA_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_OCEA_HPP
43 #include <boost/geometry/util/math.hpp>
45 #include <boost/geometry/srs/projections/impl/base_static.hpp>
46 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
47 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
48 #include <boost/geometry/srs/projections/impl/pj_param.hpp>
49 #include <boost/geometry/srs/projections/impl/projects.hpp>
51 namespace boost { namespace geometry
56 #ifndef DOXYGEN_NO_DETAIL
57 namespace detail { namespace ocea
70 template <typename T, typename Parameters>
71 struct base_ocea_spheroid
73 par_ocea<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 const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
79 static const T pi = detail::pi<T>();
85 xy_x = atan((tan(lp_lat) * this->m_proj_parm.cosphi + this->m_proj_parm.sinphi * xy_y) / t);
88 xy_x *= this->m_proj_parm.rtk;
89 xy_y = this->m_proj_parm.rok * (this->m_proj_parm.sinphi * sin(lp_lat) - this->m_proj_parm.cosphi * cos(lp_lat) * xy_y);
92 // INVERSE(s_inverse) spheroid
93 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
94 inline void inv(Parameters const& , T xy_x, T xy_y, T& lp_lon, T& lp_lat) const
98 xy_y /= this->m_proj_parm.rok;
99 xy_x /= this->m_proj_parm.rtk;
100 t = sqrt(1. - xy_y * xy_y);
101 lp_lat = asin(xy_y * this->m_proj_parm.sinphi + t * this->m_proj_parm.cosphi * (s = sin(xy_x)));
102 lp_lon = atan2(t * this->m_proj_parm.sinphi * s - xy_y * this->m_proj_parm.cosphi,
106 static inline std::string get_name()
108 return "ocea_spheroid";
113 // Oblique Cylindrical Equal Area
114 template <typename Params, typename Parameters, typename T>
115 inline void setup_ocea(Params const& params, Parameters& par, par_ocea<T>& proj_parm)
117 static const T half_pi = detail::half_pi<T>();
119 T phi_0=0.0, phi_1, phi_2, lam_1, lam_2, lonz, alpha;
121 proj_parm.rok = 1. / par.k0;
122 proj_parm.rtk = par.k0;
123 /*If the keyword "alpha" is found in the sentence then use 1point+1azimuth*/
124 if ( pj_param_r<srs::spar::alpha>(params, "alpha", srs::dpar::alpha, alpha)) {
125 /*Define Pole of oblique transformation from 1 point & 1 azimuth*/
126 //alpha = pj_get_param_r(par.params, "alpha"); // set above
127 lonz = pj_get_param_r<T, srs::spar::lonc>(params, "lonc", srs::dpar::lonc);
128 /*Equation 9-8 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
129 proj_parm.singam = atan(-cos(alpha)/(-sin(phi_0) * sin(alpha))) + lonz;
130 /*Equation 9-7 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
131 proj_parm.sinphi = asin(cos(phi_0) * sin(alpha));
132 /*If the keyword "alpha" is NOT found in the sentence then use 2points*/
134 /*Define Pole of oblique transformation from 2 points*/
135 phi_1 = pj_get_param_r<T, srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1);
136 phi_2 = pj_get_param_r<T, srs::spar::lat_2>(params, "lat_2", srs::dpar::lat_2);
137 lam_1 = pj_get_param_r<T, srs::spar::lon_1>(params, "lon_1", srs::dpar::lon_1);
138 lam_2 = pj_get_param_r<T, srs::spar::lon_2>(params, "lon_2", srs::dpar::lon_2);
139 /*Equation 9-1 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
140 proj_parm.singam = atan2(cos(phi_1) * sin(phi_2) * cos(lam_1) -
141 sin(phi_1) * cos(phi_2) * cos(lam_2),
142 sin(phi_1) * cos(phi_2) * sin(lam_2) -
143 cos(phi_1) * sin(phi_2) * sin(lam_1) );
145 /* take care of P->lam0 wrap-around when +lam_1=-90*/
146 if (lam_1 == -half_pi)
147 proj_parm.singam = -proj_parm.singam;
149 /*Equation 9-2 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
150 proj_parm.sinphi = atan(-cos(proj_parm.singam - lam_1) / tan(phi_1));
152 par.lam0 = proj_parm.singam + half_pi;
153 proj_parm.cosphi = cos(proj_parm.sinphi);
154 proj_parm.sinphi = sin(proj_parm.sinphi);
155 proj_parm.cosgam = cos(proj_parm.singam);
156 proj_parm.singam = sin(proj_parm.singam);
160 }} // namespace detail::ocea
164 \brief Oblique Cylindrical Equal Area projection
166 \tparam Geographic latlong point type
167 \tparam Cartesian xy point type
168 \tparam Parameters parameter type
169 \par Projection characteristics
172 \par Projection parameters
173 - lonc: Longitude (only used if alpha (or gamma) is specified) (degrees)
174 - alpha: Alpha (degrees)
175 - lat_1: Latitude of first standard parallel (degrees)
176 - lat_2: Latitude of second standard parallel (degrees)
180 \image html ex_ocea.gif
182 template <typename T, typename Parameters>
183 struct ocea_spheroid : public detail::ocea::base_ocea_spheroid<T, Parameters>
185 template <typename Params>
186 inline ocea_spheroid(Params const& params, Parameters & par)
188 detail::ocea::setup_ocea(params, par, this->m_proj_parm);
192 #ifndef DOXYGEN_NO_DETAIL
197 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_ocea, ocea_spheroid)
200 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(ocea_entry, ocea_spheroid)
202 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(ocea_init)
204 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(ocea, ocea_entry)
207 } // namespace detail
210 } // namespace projections
212 }} // namespace boost::geometry
214 #endif // BOOST_GEOMETRY_PROJECTIONS_OCEA_HPP