]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/srs/projections/proj/nsper.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / geometry / srs / projections / proj / nsper.hpp
1 #ifndef BOOST_GEOMETRY_PROJECTIONS_NSPER_HPP
2 #define BOOST_GEOMETRY_PROJECTIONS_NSPER_HPP
3
4 // Boost.Geometry - extensions-gis-projections (based on PROJ4)
5 // This file is automatically generated. DO NOT EDIT.
6
7 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
8
9 // This file was modified by Oracle on 2017, 2018.
10 // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
12
13 // Use, modification and distribution is subject to the Boost Software License,
14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
16
17 // This file is converted from PROJ4, http://trac.osgeo.org/proj
18 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
19 // PROJ4 is maintained by Frank Warmerdam
20 // PROJ4 is converted to Boost.Geometry by Barend Gehrels
21
22 // Last updated version of proj: 4.9.1
23
24 // Original copyright notice:
25
26 // Permission is hereby granted, free of charge, to any person obtaining a
27 // copy of this software and associated documentation files (the "Software"),
28 // to deal in the Software without restriction, including without limitation
29 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
30 // and/or sell copies of the Software, and to permit persons to whom the
31 // Software is furnished to do so, subject to the following conditions:
32
33 // The above copyright notice and this permission notice shall be included
34 // in all copies or substantial portions of the Software.
35
36 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
37 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
41 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
42 // DEALINGS IN THE SOFTWARE.
43
44 #include <boost/config.hpp>
45 #include <boost/geometry/util/math.hpp>
46 #include <boost/math/special_functions/hypot.hpp>
47
48 #include <boost/geometry/srs/projections/impl/base_static.hpp>
49 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
50 #include <boost/geometry/srs/projections/impl/projects.hpp>
51 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
52
53 namespace boost { namespace geometry
54 {
55
56 namespace srs { namespace par4
57 {
58 struct nsper {};
59 struct tpers {};
60
61 }} //namespace srs::par4
62
63 namespace projections
64 {
65 #ifndef DOXYGEN_NO_DETAIL
66 namespace detail { namespace nsper
67 {
68
69 static const double EPS10 = 1.e-10;
70 static const int N_POLE = 0;
71 static const int S_POLE = 1;
72 static const int EQUIT = 2;
73 static const int OBLIQ = 3;
74
75 template <typename T>
76 struct par_nsper
77 {
78 T height;
79 T sinph0;
80 T cosph0;
81 T p;
82 T rp;
83 T pn1;
84 T pfact;
85 T h;
86 T cg;
87 T sg;
88 T sw;
89 T cw;
90 int mode;
91 int tilt;
92 };
93
94 // template class, using CRTP to implement forward/inverse
95 template <typename CalculationType, typename Parameters>
96 struct base_nsper_spheroid : public base_t_fi<base_nsper_spheroid<CalculationType, Parameters>,
97 CalculationType, Parameters>
98 {
99
100 typedef CalculationType geographic_type;
101 typedef CalculationType cartesian_type;
102
103 par_nsper<CalculationType> m_proj_parm;
104
105 inline base_nsper_spheroid(const Parameters& par)
106 : base_t_fi<base_nsper_spheroid<CalculationType, Parameters>,
107 CalculationType, Parameters>(*this, par) {}
108
109 // FORWARD(s_forward) spheroid
110 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
111 inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
112 {
113 CalculationType coslam, cosphi, sinphi;
114
115 sinphi = sin(lp_lat);
116 cosphi = cos(lp_lat);
117 coslam = cos(lp_lon);
118 switch (this->m_proj_parm.mode) {
119 case OBLIQ:
120 xy_y = this->m_proj_parm.sinph0 * sinphi + this->m_proj_parm.cosph0 * cosphi * coslam;
121 break;
122 case EQUIT:
123 xy_y = cosphi * coslam;
124 break;
125 case S_POLE:
126 xy_y = - sinphi;
127 break;
128 case N_POLE:
129 xy_y = sinphi;
130 break;
131 }
132 if (xy_y < this->m_proj_parm.rp)
133 BOOST_THROW_EXCEPTION( projection_exception(-20) );
134 xy_y = this->m_proj_parm.pn1 / (this->m_proj_parm.p - xy_y);
135 xy_x = xy_y * cosphi * sin(lp_lon);
136 switch (this->m_proj_parm.mode) {
137 case OBLIQ:
138 xy_y *= (this->m_proj_parm.cosph0 * sinphi -
139 this->m_proj_parm.sinph0 * cosphi * coslam);
140 break;
141 case EQUIT:
142 xy_y *= sinphi;
143 break;
144 case N_POLE:
145 coslam = - coslam;
146 BOOST_FALLTHROUGH;
147 case S_POLE:
148 xy_y *= cosphi * coslam;
149 break;
150 }
151 if (this->m_proj_parm.tilt) {
152 CalculationType yt, ba;
153
154 yt = xy_y * this->m_proj_parm.cg + xy_x * this->m_proj_parm.sg;
155 ba = 1. / (yt * this->m_proj_parm.sw * this->m_proj_parm.h + this->m_proj_parm.cw);
156 xy_x = (xy_x * this->m_proj_parm.cg - xy_y * this->m_proj_parm.sg) * this->m_proj_parm.cw * ba;
157 xy_y = yt * ba;
158 }
159 }
160
161 // INVERSE(s_inverse) spheroid
162 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
163 inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
164 {
165 CalculationType rh, cosz, sinz;
166
167 if (this->m_proj_parm.tilt) {
168 CalculationType bm, bq, yt;
169
170 yt = 1./(this->m_proj_parm.pn1 - xy_y * this->m_proj_parm.sw);
171 bm = this->m_proj_parm.pn1 * xy_x * yt;
172 bq = this->m_proj_parm.pn1 * xy_y * this->m_proj_parm.cw * yt;
173 xy_x = bm * this->m_proj_parm.cg + bq * this->m_proj_parm.sg;
174 xy_y = bq * this->m_proj_parm.cg - bm * this->m_proj_parm.sg;
175 }
176 rh = boost::math::hypot(xy_x, xy_y);
177 if ((sinz = 1. - rh * rh * this->m_proj_parm.pfact) < 0.)
178 BOOST_THROW_EXCEPTION( projection_exception(-20) );
179 sinz = (this->m_proj_parm.p - sqrt(sinz)) / (this->m_proj_parm.pn1 / rh + rh / this->m_proj_parm.pn1);
180 cosz = sqrt(1. - sinz * sinz);
181 if (fabs(rh) <= EPS10) {
182 lp_lon = 0.;
183 lp_lat = this->m_par.phi0;
184 } else {
185 switch (this->m_proj_parm.mode) {
186 case OBLIQ:
187 lp_lat = asin(cosz * this->m_proj_parm.sinph0 + xy_y * sinz * this->m_proj_parm.cosph0 / rh);
188 xy_y = (cosz - this->m_proj_parm.sinph0 * sin(lp_lat)) * rh;
189 xy_x *= sinz * this->m_proj_parm.cosph0;
190 break;
191 case EQUIT:
192 lp_lat = asin(xy_y * sinz / rh);
193 xy_y = cosz * rh;
194 xy_x *= sinz;
195 break;
196 case N_POLE:
197 lp_lat = asin(cosz);
198 xy_y = -xy_y;
199 break;
200 case S_POLE:
201 lp_lat = - asin(cosz);
202 break;
203 }
204 lp_lon = atan2(xy_x, xy_y);
205 }
206 }
207
208 static inline std::string get_name()
209 {
210 return "nsper_spheroid";
211 }
212
213 };
214
215 template <typename Parameters, typename T>
216 inline void setup(Parameters& par, par_nsper<T>& proj_parm)
217 {
218 if ((proj_parm.height = pj_param(par.params, "dh").f) <= 0.)
219 BOOST_THROW_EXCEPTION( projection_exception(-30) );
220 if (fabs(fabs(par.phi0) - geometry::math::half_pi<T>()) < EPS10)
221 proj_parm.mode = par.phi0 < 0. ? S_POLE : N_POLE;
222 else if (fabs(par.phi0) < EPS10)
223 proj_parm.mode = EQUIT;
224 else {
225 proj_parm.mode = OBLIQ;
226 proj_parm.sinph0 = sin(par.phi0);
227 proj_parm.cosph0 = cos(par.phi0);
228 }
229 proj_parm.pn1 = proj_parm.height / par.a; /* normalize by radius */
230 proj_parm.p = 1. + proj_parm.pn1;
231 proj_parm.rp = 1. / proj_parm.p;
232 proj_parm.h = 1. / proj_parm.pn1;
233 proj_parm.pfact = (proj_parm.p + 1.) * proj_parm.h;
234 par.es = 0.;
235 }
236
237
238 // Near-sided perspective
239 template <typename Parameters, typename T>
240 inline void setup_nsper(Parameters& par, par_nsper<T>& proj_parm)
241 {
242 proj_parm.tilt = 0;
243 setup(par, proj_parm);
244 }
245
246 // Tilted perspective
247 template <typename Parameters, typename T>
248 inline void setup_tpers(Parameters& par, par_nsper<T>& proj_parm)
249 {
250 T omega, gamma;
251
252 omega = pj_param(par.params, "dtilt").f * geometry::math::d2r<T>();
253 gamma = pj_param(par.params, "dazi").f * geometry::math::d2r<T>();
254 proj_parm.tilt = 1;
255 proj_parm.cg = cos(gamma); proj_parm.sg = sin(gamma);
256 proj_parm.cw = cos(omega); proj_parm.sw = sin(omega);
257 setup(par, proj_parm);
258 }
259
260 }} // namespace detail::nsper
261 #endif // doxygen
262
263 /*!
264 \brief Near-sided perspective projection
265 \ingroup projections
266 \tparam Geographic latlong point type
267 \tparam Cartesian xy point type
268 \tparam Parameters parameter type
269 \par Projection characteristics
270 - Azimuthal
271 - Spheroid
272 \par Projection parameters
273 - h: Height
274 \par Example
275 \image html ex_nsper.gif
276 */
277 template <typename CalculationType, typename Parameters>
278 struct nsper_spheroid : public detail::nsper::base_nsper_spheroid<CalculationType, Parameters>
279 {
280 inline nsper_spheroid(const Parameters& par) : detail::nsper::base_nsper_spheroid<CalculationType, Parameters>(par)
281 {
282 detail::nsper::setup_nsper(this->m_par, this->m_proj_parm);
283 }
284 };
285
286 /*!
287 \brief Tilted perspective projection
288 \ingroup projections
289 \tparam Geographic latlong point type
290 \tparam Cartesian xy point type
291 \tparam Parameters parameter type
292 \par Projection characteristics
293 - Azimuthal
294 - Spheroid
295 \par Projection parameters
296 - tilt: Tilt, or Omega (real)
297 - azi: Azimuth (or Gamma) (real)
298 - h: Height
299 \par Example
300 \image html ex_tpers.gif
301 */
302 template <typename CalculationType, typename Parameters>
303 struct tpers_spheroid : public detail::nsper::base_nsper_spheroid<CalculationType, Parameters>
304 {
305 inline tpers_spheroid(const Parameters& par) : detail::nsper::base_nsper_spheroid<CalculationType, Parameters>(par)
306 {
307 detail::nsper::setup_tpers(this->m_par, this->m_proj_parm);
308 }
309 };
310
311 #ifndef DOXYGEN_NO_DETAIL
312 namespace detail
313 {
314
315 // Static projection
316 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::nsper, nsper_spheroid, nsper_spheroid)
317 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::tpers, tpers_spheroid, tpers_spheroid)
318
319 // Factory entry(s)
320 template <typename CalculationType, typename Parameters>
321 class nsper_entry : public detail::factory_entry<CalculationType, Parameters>
322 {
323 public :
324 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
325 {
326 return new base_v_fi<nsper_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
327 }
328 };
329
330 template <typename CalculationType, typename Parameters>
331 class tpers_entry : public detail::factory_entry<CalculationType, Parameters>
332 {
333 public :
334 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
335 {
336 return new base_v_fi<tpers_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
337 }
338 };
339
340 template <typename CalculationType, typename Parameters>
341 inline void nsper_init(detail::base_factory<CalculationType, Parameters>& factory)
342 {
343 factory.add_to_factory("nsper", new nsper_entry<CalculationType, Parameters>);
344 factory.add_to_factory("tpers", new tpers_entry<CalculationType, Parameters>);
345 }
346
347 } // namespace detail
348 #endif // doxygen
349
350 } // namespace projections
351
352 }} // namespace boost::geometry
353
354 #endif // BOOST_GEOMETRY_PROJECTIONS_NSPER_HPP
355