]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | #ifndef BOOST_GEOMETRY_PROJECTIONS_IMW_P_HPP |
2 | #define BOOST_GEOMETRY_PROJECTIONS_IMW_P_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. | |
10 | // Modifications copyright (c) 2017, 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/geometry/util/math.hpp> | |
45 | ||
46 | #include <boost/geometry/srs/projections/impl/base_static.hpp> | |
47 | #include <boost/geometry/srs/projections/impl/base_dynamic.hpp> | |
48 | #include <boost/geometry/srs/projections/impl/projects.hpp> | |
49 | #include <boost/geometry/srs/projections/impl/factory_entry.hpp> | |
50 | #include <boost/geometry/srs/projections/impl/pj_mlfn.hpp> | |
51 | ||
52 | namespace boost { namespace geometry | |
53 | { | |
54 | ||
55 | namespace srs { namespace par4 | |
56 | { | |
57 | struct imw_p {}; | |
58 | ||
59 | }} //namespace srs::par4 | |
60 | ||
61 | namespace projections | |
62 | { | |
63 | #ifndef DOXYGEN_NO_DETAIL | |
64 | namespace detail { namespace imw_p | |
65 | { | |
66 | ||
67 | static const double TOL = 1e-10; | |
68 | static const double EPS = 1e-10; | |
69 | ||
70 | template <typename T> | |
71 | struct XY { T x, y; }; // specific for IMW_P | |
72 | ||
73 | template <typename T> | |
74 | struct par_imw_p | |
75 | { | |
76 | T P, Pp, Q, Qp, R_1, R_2, sphi_1, sphi_2, C2; | |
77 | T phi_1, phi_2, lam_1; | |
78 | T en[EN_SIZE]; | |
79 | int mode; /* = 0, phi_1 and phi_2 != 0, = 1, phi_1 = 0, = -1 phi_2 = 0 */ | |
80 | }; | |
81 | ||
82 | template <typename Parameters, typename T> | |
83 | inline int | |
84 | phi12(Parameters& par, par_imw_p<T>& proj_parm, T *del, T *sig) | |
85 | { | |
86 | int err = 0; | |
87 | ||
88 | if (!pj_param(par.params, "tlat_1").i || | |
89 | !pj_param(par.params, "tlat_2").i) { | |
90 | err = -41; | |
91 | } else { | |
92 | proj_parm.phi_1 = pj_param(par.params, "rlat_1").f; | |
93 | proj_parm.phi_2 = pj_param(par.params, "rlat_2").f; | |
94 | *del = 0.5 * (proj_parm.phi_2 - proj_parm.phi_1); | |
95 | *sig = 0.5 * (proj_parm.phi_2 + proj_parm.phi_1); | |
96 | err = (fabs(*del) < EPS || fabs(*sig) < EPS) ? -42 : 0; | |
97 | } | |
98 | return err; | |
99 | } | |
100 | template <typename Parameters, typename T> | |
101 | inline XY<T> | |
102 | loc_for(T const& lp_lam, T const& lp_phi, Parameters const& par, par_imw_p<T> const& proj_parm, T *yc) | |
103 | { | |
104 | XY<T> xy; | |
105 | ||
106 | if (! lp_phi) { | |
107 | xy.x = lp_lam; | |
108 | xy.y = 0.; | |
109 | } else { | |
110 | T xa, ya, xb, yb, xc, D, B, m, sp, t, R, C; | |
111 | ||
112 | sp = sin(lp_phi); | |
113 | m = pj_mlfn(lp_phi, sp, cos(lp_phi), proj_parm.en); | |
114 | xa = proj_parm.Pp + proj_parm.Qp * m; | |
115 | ya = proj_parm.P + proj_parm.Q * m; | |
116 | R = 1. / (tan(lp_phi) * sqrt(1. - par.es * sp * sp)); | |
117 | C = sqrt(R * R - xa * xa); | |
118 | if (lp_phi < 0.) C = - C; | |
119 | C += ya - R; | |
120 | if (proj_parm.mode < 0) { | |
121 | xb = lp_lam; | |
122 | yb = proj_parm.C2; | |
123 | } else { | |
124 | t = lp_lam * proj_parm.sphi_2; | |
125 | xb = proj_parm.R_2 * sin(t); | |
126 | yb = proj_parm.C2 + proj_parm.R_2 * (1. - cos(t)); | |
127 | } | |
128 | if (proj_parm.mode > 0) { | |
129 | xc = lp_lam; | |
130 | *yc = 0.; | |
131 | } else { | |
132 | t = lp_lam * proj_parm.sphi_1; | |
133 | xc = proj_parm.R_1 * sin(t); | |
134 | *yc = proj_parm.R_1 * (1. - cos(t)); | |
135 | } | |
136 | D = (xb - xc)/(yb - *yc); | |
137 | B = xc + D * (C + R - *yc); | |
138 | xy.x = D * sqrt(R * R * (1 + D * D) - B * B); | |
139 | if (lp_phi > 0) | |
140 | xy.x = - xy.x; | |
141 | xy.x = (B + xy.x) / (1. + D * D); | |
142 | xy.y = sqrt(R * R - xy.x * xy.x); | |
143 | if (lp_phi > 0) | |
144 | xy.y = - xy.y; | |
145 | xy.y += C + R; | |
146 | } | |
147 | return (xy); | |
148 | } | |
149 | template <typename Parameters, typename T> | |
150 | inline void | |
151 | xy(Parameters const& par, par_imw_p<T> const& proj_parm, T const& phi, T *x, T *y, T *sp, T *R) | |
152 | { | |
153 | T F; | |
154 | ||
155 | *sp = sin(phi); | |
156 | *R = 1./(tan(phi) * sqrt(1. - par.es * *sp * *sp )); | |
157 | F = proj_parm.lam_1 * *sp; | |
158 | *y = *R * (1 - cos(F)); | |
159 | *x = *R * sin(F); | |
160 | } | |
161 | ||
162 | // template class, using CRTP to implement forward/inverse | |
163 | template <typename CalculationType, typename Parameters> | |
164 | struct base_imw_p_ellipsoid : public base_t_fi<base_imw_p_ellipsoid<CalculationType, Parameters>, | |
165 | CalculationType, Parameters> | |
166 | { | |
167 | ||
168 | typedef CalculationType geographic_type; | |
169 | typedef CalculationType cartesian_type; | |
170 | ||
171 | par_imw_p<CalculationType> m_proj_parm; | |
172 | ||
173 | inline base_imw_p_ellipsoid(const Parameters& par) | |
174 | : base_t_fi<base_imw_p_ellipsoid<CalculationType, Parameters>, | |
175 | CalculationType, Parameters>(*this, par) {} | |
176 | ||
177 | // FORWARD(e_forward) ellipsoid | |
178 | // Project coordinates from geographic (lon, lat) to cartesian (x, y) | |
179 | inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const | |
180 | { | |
181 | CalculationType yc = 0; | |
182 | XY<CalculationType> xy = loc_for(lp_lon, lp_lat, this->m_par, m_proj_parm, &yc); | |
183 | xy_x = xy.x; xy_y = xy.y; | |
184 | } | |
185 | ||
186 | // INVERSE(e_inverse) ellipsoid | |
187 | // Project coordinates from cartesian (x, y) to geographic (lon, lat) | |
188 | inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const | |
189 | { | |
190 | XY<CalculationType> t; | |
191 | CalculationType yc = 0; | |
192 | ||
193 | lp_lat = this->m_proj_parm.phi_2; | |
194 | lp_lon = xy_x / cos(lp_lat); | |
195 | do { | |
196 | t = loc_for(lp_lon, lp_lat, this->m_par, m_proj_parm, &yc); | |
197 | lp_lat = ((lp_lat - this->m_proj_parm.phi_1) * (xy_y - yc) / (t.y - yc)) + this->m_proj_parm.phi_1; | |
198 | lp_lon = lp_lon * xy_x / t.x; | |
199 | } while (fabs(t.x - xy_x) > TOL || fabs(t.y - xy_y) > TOL); | |
200 | } | |
201 | ||
202 | static inline std::string get_name() | |
203 | { | |
204 | return "imw_p_ellipsoid"; | |
205 | } | |
206 | ||
207 | }; | |
208 | ||
209 | // International Map of the World Polyconic | |
210 | template <typename Parameters, typename T> | |
211 | inline void setup_imw_p(Parameters& par, par_imw_p<T>& proj_parm) | |
212 | { | |
213 | T del, sig, s, t, x1, x2, T2, y1, m1, m2, y2; | |
214 | int i; | |
215 | ||
216 | if (!pj_enfn(par.es, proj_parm.en)) | |
217 | BOOST_THROW_EXCEPTION( projection_exception(0) ); | |
218 | if( (i = phi12(par, proj_parm, &del, &sig)) != 0) | |
219 | BOOST_THROW_EXCEPTION( projection_exception(i) ); | |
220 | if (proj_parm.phi_2 < proj_parm.phi_1) { /* make sure proj_parm.phi_1 most southerly */ | |
221 | del = proj_parm.phi_1; | |
222 | proj_parm.phi_1 = proj_parm.phi_2; | |
223 | proj_parm.phi_2 = del; | |
224 | } | |
225 | if (pj_param(par.params, "tlon_1").i) | |
226 | proj_parm.lam_1 = pj_param(par.params, "rlon_1").f; | |
227 | else { /* use predefined based upon latitude */ | |
228 | sig = fabs(sig * geometry::math::r2d<T>()); | |
229 | if (sig <= 60) sig = 2.; | |
230 | else if (sig <= 76) sig = 4.; | |
231 | else sig = 8.; | |
232 | proj_parm.lam_1 = sig * geometry::math::d2r<T>(); | |
233 | } | |
234 | proj_parm.mode = 0; | |
235 | if (proj_parm.phi_1) xy(par, proj_parm, proj_parm.phi_1, &x1, &y1, &proj_parm.sphi_1, &proj_parm.R_1); | |
236 | else { | |
237 | proj_parm.mode = 1; | |
238 | y1 = 0.; | |
239 | x1 = proj_parm.lam_1; | |
240 | } | |
241 | if (proj_parm.phi_2) xy(par, proj_parm, proj_parm.phi_2, &x2, &T2, &proj_parm.sphi_2, &proj_parm.R_2); | |
242 | else { | |
243 | proj_parm.mode = -1; | |
244 | T2 = 0.; | |
245 | x2 = proj_parm.lam_1; | |
246 | } | |
247 | m1 = pj_mlfn(proj_parm.phi_1, proj_parm.sphi_1, cos(proj_parm.phi_1), proj_parm.en); | |
248 | m2 = pj_mlfn(proj_parm.phi_2, proj_parm.sphi_2, cos(proj_parm.phi_2), proj_parm.en); | |
249 | t = m2 - m1; | |
250 | s = x2 - x1; | |
251 | y2 = sqrt(t * t - s * s) + y1; | |
252 | proj_parm.C2 = y2 - T2; | |
253 | t = 1. / t; | |
254 | proj_parm.P = (m2 * y1 - m1 * y2) * t; | |
255 | proj_parm.Q = (y2 - y1) * t; | |
256 | proj_parm.Pp = (m2 * x1 - m1 * x2) * t; | |
257 | proj_parm.Qp = (x2 - x1) * t; | |
258 | } | |
259 | ||
260 | }} // namespace detail::imw_p | |
261 | #endif // doxygen | |
262 | ||
263 | /*! | |
264 | \brief International Map of the World Polyconic 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 | - Mod. Polyconic | |
271 | - Ellipsoid | |
272 | \par Projection parameters | |
273 | - lat_1: Latitude of first standard parallel | |
274 | - lat_2: Latitude of second standard parallel | |
275 | - lon_1 (degrees) | |
276 | \par Example | |
277 | \image html ex_imw_p.gif | |
278 | */ | |
279 | template <typename CalculationType, typename Parameters> | |
280 | struct imw_p_ellipsoid : public detail::imw_p::base_imw_p_ellipsoid<CalculationType, Parameters> | |
281 | { | |
282 | inline imw_p_ellipsoid(const Parameters& par) : detail::imw_p::base_imw_p_ellipsoid<CalculationType, Parameters>(par) | |
283 | { | |
284 | detail::imw_p::setup_imw_p(this->m_par, this->m_proj_parm); | |
285 | } | |
286 | }; | |
287 | ||
288 | #ifndef DOXYGEN_NO_DETAIL | |
289 | namespace detail | |
290 | { | |
291 | ||
292 | // Static projection | |
293 | BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::imw_p, imw_p_ellipsoid, imw_p_ellipsoid) | |
294 | ||
295 | // Factory entry(s) | |
296 | template <typename CalculationType, typename Parameters> | |
297 | class imw_p_entry : public detail::factory_entry<CalculationType, Parameters> | |
298 | { | |
299 | public : | |
300 | virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const | |
301 | { | |
302 | return new base_v_fi<imw_p_ellipsoid<CalculationType, Parameters>, CalculationType, Parameters>(par); | |
303 | } | |
304 | }; | |
305 | ||
306 | template <typename CalculationType, typename Parameters> | |
307 | inline void imw_p_init(detail::base_factory<CalculationType, Parameters>& factory) | |
308 | { | |
309 | factory.add_to_factory("imw_p", new imw_p_entry<CalculationType, Parameters>); | |
310 | } | |
311 | ||
312 | } // namespace detail | |
313 | #endif // doxygen | |
314 | ||
315 | } // namespace projections | |
316 | ||
317 | }} // namespace boost::geometry | |
318 | ||
319 | #endif // BOOST_GEOMETRY_PROJECTIONS_IMW_P_HPP | |
320 |