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 // Purpose: Implementation of the nzmg (New Zealand Map Grid) projection.
23 // Very loosely based upon DMA code by Bradford W. Drew
24 // Author: Gerald Evenden
25 // Copyright (c) 1995, Gerald Evenden
27 // Permission is hereby granted, free of charge, to any person obtaining a
28 // copy of this software and associated documentation files (the "Software"),
29 // to deal in the Software without restriction, including without limitation
30 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
31 // and/or sell copies of the Software, and to permit persons to whom the
32 // Software is furnished to do so, subject to the following conditions:
34 // The above copyright notice and this permission notice shall be included
35 // in all copies or substantial portions of the Software.
37 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
38 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
40 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
43 // DEALINGS IN THE SOFTWARE.
45 #ifndef BOOST_GEOMETRY_PROJECTIONS_NZMG_HPP
46 #define BOOST_GEOMETRY_PROJECTIONS_NZMG_HPP
48 #include <boost/geometry/util/math.hpp>
50 #include <boost/geometry/srs/projections/impl/base_static.hpp>
51 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
52 #include <boost/geometry/srs/projections/impl/projects.hpp>
53 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
54 #include <boost/geometry/srs/projections/impl/pj_zpoly1.hpp>
56 namespace boost { namespace geometry
61 #ifndef DOXYGEN_NO_DETAIL
62 namespace detail { namespace nzmg
65 static const double epsilon = 1e-10;
66 static const int Nbf = 5;
67 static const int Ntpsi = 9;
68 static const int Ntphi = 8;
71 inline T sec5_to_rad() { return 0.4848136811095359935899141023; }
73 inline T rad_to_sec5() { return 2.062648062470963551564733573; }
76 inline const pj_complex<T> * bf()
78 static const pj_complex<T> result[] = {
80 {.249204646, .003371507},
81 {-.001541739, .041058560},
82 {-.10162907, .01727609},
83 {-.26623489, -.36249218},
84 {-.6870983, -1.1651967}
90 inline const T * tphi()
92 static const T result[] = { 1.5627014243, .5185406398, -.03333098,
93 -.1052906, -.0368594, .007317,
94 .01220, .00394, -.0013 };
98 inline const T * tpsi()
100 static const T result[] = { .6399175073, -.1358797613, .063294409, -.02526853, .0117879,
101 -.0055161, .0026906, -.001333, .00067, -.00034 };
105 template <typename T, typename Parameters>
106 struct base_nzmg_ellipsoid
108 // FORWARD(e_forward) ellipsoid
109 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
110 inline void fwd(Parameters const& par, T const& lp_lon, T lp_lat, T& xy_x, T& xy_y) const
112 static const T rad_to_sec5 = nzmg::rad_to_sec5<T>();
118 lp_lat = (lp_lat - par.phi0) * rad_to_sec5;
119 for (p.r = *(C = tpsi<T>() + (i = Ntpsi)); i ; --i)
120 p.r = *--C + lp_lat * p.r;
123 p = pj_zpoly1(p, bf<T>(), Nbf);
128 // INVERSE(e_inverse) ellipsoid
129 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
130 inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
132 static const T sec5_to_rad = nzmg::sec5_to_rad<T>();
135 pj_complex<T> p, f, fp, dp;
141 for (nn = 20; nn ;--nn) {
142 f = pj_zpolyd1(p, bf<T>(), Nbf, &fp);
145 den = fp.r * fp.r + fp.i * fp.i;
146 p.r += dp.r = -(f.r * fp.r + f.i * fp.i) / den;
147 p.i += dp.i = -(f.i * fp.r - f.r * fp.i) / den;
148 if ((fabs(dp.r) + fabs(dp.i)) <= epsilon)
153 for (lp_lat = *(C = tphi<T>() + (i = Ntphi)); i ; --i)
154 lp_lat = *--C + p.r * lp_lat;
155 lp_lat = par.phi0 + p.r * lp_lat * sec5_to_rad;
157 lp_lon = lp_lat = HUGE_VAL;
160 static inline std::string get_name()
162 return "nzmg_ellipsoid";
167 // New Zealand Map Grid
168 template <typename Parameters>
169 inline void setup_nzmg(Parameters& par)
171 typedef typename Parameters::type calc_t;
172 static const calc_t d2r = geometry::math::d2r<calc_t>();
174 /* force to International major axis */
177 par.lam0 = 173. * d2r;
178 par.phi0 = -41. * d2r;
183 }} // namespace detail::nzmg
187 \brief New Zealand Map Grid projection
189 \tparam Geographic latlong point type
190 \tparam Cartesian xy point type
191 \tparam Parameters parameter type
192 \par Projection characteristics
195 \image html ex_nzmg.gif
197 template <typename T, typename Parameters>
198 struct nzmg_ellipsoid : public detail::nzmg::base_nzmg_ellipsoid<T, Parameters>
200 template <typename Params>
201 inline nzmg_ellipsoid(Params const& , Parameters & par)
203 detail::nzmg::setup_nzmg(par);
207 #ifndef DOXYGEN_NO_DETAIL
212 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_nzmg, nzmg_ellipsoid)
215 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(nzmg_entry, nzmg_ellipsoid)
217 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(nzmg_init)
219 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(nzmg, nzmg_entry)
222 } // namespace detail
225 } // namespace projections
227 }} // namespace boost::geometry
229 #endif // BOOST_GEOMETRY_PROJECTIONS_NZMG_HPP