1 #ifndef BOOST_GEOMETRY_PROJECTIONS_NSPER_HPP
2 #define BOOST_GEOMETRY_PROJECTIONS_NSPER_HPP
4 // Boost.Geometry - extensions-gis-projections (based on PROJ4)
5 // This file is automatically generated. DO NOT EDIT.
7 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
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.
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)
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
22 // Last updated version of proj: 4.9.1
24 // Original copyright notice:
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:
33 // The above copyright notice and this permission notice shall be included
34 // in all copies or substantial portions of the Software.
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.
44 #include <boost/config.hpp>
45 #include <boost/geometry/util/math.hpp>
46 #include <boost/math/special_functions/hypot.hpp>
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>
53 namespace boost { namespace geometry
56 namespace srs { namespace par4
61 }} //namespace srs::par4
65 #ifndef DOXYGEN_NO_DETAIL
66 namespace detail { namespace nsper
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;
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>
100 typedef CalculationType geographic_type;
101 typedef CalculationType cartesian_type;
103 par_nsper<CalculationType> m_proj_parm;
105 inline base_nsper_spheroid(const Parameters& par)
106 : base_t_fi<base_nsper_spheroid<CalculationType, Parameters>,
107 CalculationType, Parameters>(*this, par) {}
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
113 CalculationType coslam, cosphi, sinphi;
115 sinphi = sin(lp_lat);
116 cosphi = cos(lp_lat);
117 coslam = cos(lp_lon);
118 switch (this->m_proj_parm.mode) {
120 xy_y = this->m_proj_parm.sinph0 * sinphi + this->m_proj_parm.cosph0 * cosphi * coslam;
123 xy_y = cosphi * coslam;
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) {
138 xy_y *= (this->m_proj_parm.cosph0 * sinphi -
139 this->m_proj_parm.sinph0 * cosphi * coslam);
148 xy_y *= cosphi * coslam;
151 if (this->m_proj_parm.tilt) {
152 CalculationType yt, ba;
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;
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
165 CalculationType rh, cosz, sinz;
167 if (this->m_proj_parm.tilt) {
168 CalculationType bm, bq, yt;
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;
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) {
183 lp_lat = this->m_par.phi0;
185 switch (this->m_proj_parm.mode) {
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;
192 lp_lat = asin(xy_y * sinz / rh);
201 lp_lat = - asin(cosz);
204 lp_lon = atan2(xy_x, xy_y);
208 static inline std::string get_name()
210 return "nsper_spheroid";
215 template <typename Parameters, typename T>
216 inline void setup(Parameters& par, par_nsper<T>& proj_parm)
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;
225 proj_parm.mode = OBLIQ;
226 proj_parm.sinph0 = sin(par.phi0);
227 proj_parm.cosph0 = cos(par.phi0);
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;
238 // Near-sided perspective
239 template <typename Parameters, typename T>
240 inline void setup_nsper(Parameters& par, par_nsper<T>& proj_parm)
243 setup(par, proj_parm);
246 // Tilted perspective
247 template <typename Parameters, typename T>
248 inline void setup_tpers(Parameters& par, par_nsper<T>& proj_parm)
252 omega = pj_param(par.params, "dtilt").f * geometry::math::d2r<T>();
253 gamma = pj_param(par.params, "dazi").f * geometry::math::d2r<T>();
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);
260 }} // namespace detail::nsper
264 \brief Near-sided perspective projection
266 \tparam Geographic latlong point type
267 \tparam Cartesian xy point type
268 \tparam Parameters parameter type
269 \par Projection characteristics
272 \par Projection parameters
275 \image html ex_nsper.gif
277 template <typename CalculationType, typename Parameters>
278 struct nsper_spheroid : public detail::nsper::base_nsper_spheroid<CalculationType, Parameters>
280 inline nsper_spheroid(const Parameters& par) : detail::nsper::base_nsper_spheroid<CalculationType, Parameters>(par)
282 detail::nsper::setup_nsper(this->m_par, this->m_proj_parm);
287 \brief Tilted perspective projection
289 \tparam Geographic latlong point type
290 \tparam Cartesian xy point type
291 \tparam Parameters parameter type
292 \par Projection characteristics
295 \par Projection parameters
296 - tilt: Tilt, or Omega (real)
297 - azi: Azimuth (or Gamma) (real)
300 \image html ex_tpers.gif
302 template <typename CalculationType, typename Parameters>
303 struct tpers_spheroid : public detail::nsper::base_nsper_spheroid<CalculationType, Parameters>
305 inline tpers_spheroid(const Parameters& par) : detail::nsper::base_nsper_spheroid<CalculationType, Parameters>(par)
307 detail::nsper::setup_tpers(this->m_par, this->m_proj_parm);
311 #ifndef DOXYGEN_NO_DETAIL
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)
320 template <typename CalculationType, typename Parameters>
321 class nsper_entry : public detail::factory_entry<CalculationType, Parameters>
324 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
326 return new base_v_fi<nsper_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
330 template <typename CalculationType, typename Parameters>
331 class tpers_entry : public detail::factory_entry<CalculationType, Parameters>
334 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
336 return new base_v_fi<tpers_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
340 template <typename CalculationType, typename Parameters>
341 inline void nsper_init(detail::base_factory<CalculationType, Parameters>& factory)
343 factory.add_to_factory("nsper", new nsper_entry<CalculationType, Parameters>);
344 factory.add_to_factory("tpers", new tpers_entry<CalculationType, Parameters>);
347 } // namespace detail
350 } // namespace projections
352 }} // namespace boost::geometry
354 #endif // BOOST_GEOMETRY_PROJECTIONS_NSPER_HPP