]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | // This file is manually converted from PROJ4 | |
3 | ||
4 | // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
5 | ||
6 | // This file was modified by Oracle on 2017, 2018. | |
7 | // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates. | |
8 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
9 | ||
10 | // Use, modification and distribution is subject to the Boost Software License, | |
11 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
12 | // http://www.boost.org/LICENSE_1_0.txt) | |
13 | ||
14 | // This file is converted from PROJ4, http://trac.osgeo.org/proj | |
15 | // PROJ4 is originally written by Gerald Evenden (then of the USGS) | |
16 | // PROJ4 is maintained by Frank Warmerdam | |
17 | // PROJ4 is converted to Geometry Library by Barend Gehrels (Geodan, Amsterdam) | |
18 | ||
19 | // Original copyright notice: | |
20 | ||
21 | // Permission is hereby granted, free of charge, to any person obtaining a | |
22 | // copy of this software and associated documentation files (the "Software"), | |
23 | // to deal in the Software without restriction, including without limitation | |
24 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
25 | // and/or sell copies of the Software, and to permit persons to whom the | |
26 | // Software is furnished to do so, subject to the following conditions: | |
27 | ||
28 | // The above copyright notice and this permission notice shall be included | |
29 | // in all copies or substantial portions of the Software. | |
30 | ||
31 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
32 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
33 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
34 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
35 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
36 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
37 | // DEALINGS IN THE SOFTWARE. | |
38 | ||
39 | #ifndef BOOST_GEOMETRY_PROJECTIONS_IMPL_PJ_DATUM_SET_HPP | |
40 | #define BOOST_GEOMETRY_PROJECTIONS_IMPL_PJ_DATUM_SET_HPP | |
41 | ||
42 | ||
43 | #include <string> | |
44 | #include <vector> | |
45 | ||
46 | #include <boost/algorithm/string.hpp> | |
47 | ||
48 | #include <boost/geometry/srs/projections/exception.hpp> | |
49 | #include <boost/geometry/srs/projections/impl/projects.hpp> | |
50 | #include <boost/geometry/srs/projections/impl/pj_datums.hpp> | |
51 | #include <boost/geometry/srs/projections/impl/pj_param.hpp> | |
52 | #include <boost/geometry/srs/projections/par4.hpp> | |
53 | #include <boost/geometry/srs/projections/proj4.hpp> | |
54 | ||
55 | ||
56 | namespace boost { namespace geometry { namespace projections { | |
57 | ||
58 | namespace detail { | |
59 | ||
60 | ||
61 | /* SEC_TO_RAD = Pi/180/3600 */ | |
62 | template <typename T> | |
63 | inline T SEC_TO_RAD() { return 4.84813681109535993589914102357e-6; } | |
64 | ||
65 | template <typename BGParams, typename T> | |
66 | inline void pj_datum_add_defn(BGParams const& , std::vector<pvalue<T> >& pvalues) | |
67 | { | |
68 | /* -------------------------------------------------------------------- */ | |
69 | /* Is there a datum definition in the parameter list? If so, */ | |
70 | /* add the defining values to the parameter list. Note that */ | |
71 | /* this will append the ellipse definition as well as the */ | |
72 | /* towgs84= and related parameters. It should also be pointed */ | |
73 | /* out that the addition is permanent rather than temporary */ | |
74 | /* like most other keyword expansion so that the ellipse */ | |
75 | /* definition will last into the pj_ell_set() function called */ | |
76 | /* after this one. */ | |
77 | /* -------------------------------------------------------------------- */ | |
78 | std::string name = pj_param(pvalues, "sdatum").s; | |
79 | if(! name.empty()) | |
80 | { | |
81 | /* find the datum definition */ | |
82 | const int n = sizeof(pj_datums) / sizeof(pj_datums[0]); | |
83 | int index = -1; | |
84 | for (int i = 0; i < n && index == -1; i++) | |
85 | { | |
86 | if(pj_datums[i].id == name) | |
87 | { | |
88 | index = i; | |
89 | } | |
90 | } | |
91 | ||
92 | if (index == -1) | |
93 | { | |
94 | BOOST_THROW_EXCEPTION( projection_exception(-9) ); | |
95 | } | |
96 | ||
97 | if(! pj_datums[index].ellipse_id.empty()) | |
98 | { | |
99 | std::string entry("ellps="); | |
100 | entry +=pj_datums[index].ellipse_id; | |
101 | pvalues.push_back(pj_mkparam<T>(entry)); | |
102 | } | |
103 | ||
104 | if(! pj_datums[index].defn.empty()) | |
105 | { | |
106 | pvalues.push_back(pj_mkparam<T>(pj_datums[index].defn)); | |
107 | } | |
108 | } | |
109 | } | |
110 | ||
111 | template <BOOST_GEOMETRY_PROJECTIONS_DETAIL_TYPENAME_PX, typename T> | |
112 | inline void pj_datum_add_defn(srs::static_proj4<BOOST_GEOMETRY_PROJECTIONS_DETAIL_PX> const& /*bg_params*/, | |
113 | std::vector<pvalue<T> >& pvalues) | |
114 | { | |
115 | typedef srs::static_proj4<BOOST_GEOMETRY_PROJECTIONS_DETAIL_PX> bg_parameters_type; | |
116 | typedef typename srs::par4::detail::tuples_find_if | |
117 | < | |
118 | bg_parameters_type, | |
119 | //srs::par4::detail::is_datum | |
120 | srs::par4::detail::is_param_t<srs::par4::datum>::pred | |
121 | >::type datum_type; | |
122 | typedef typename srs::par4::detail::datum_traits | |
123 | < | |
124 | datum_type | |
125 | > datum_traits; | |
126 | ||
127 | // is unknown if datum parameter found but traits are not specialized | |
128 | static const bool not_set_or_known = boost::is_same<datum_type, void>::value | |
129 | || ! boost::is_same<typename datum_traits::ellps_type, void>::value; | |
130 | BOOST_MPL_ASSERT_MSG((not_set_or_known), UNKNOWN_DATUM, (bg_parameters_type)); | |
131 | ||
132 | std::string defn = datum_traits::definition(); | |
133 | ||
134 | if (! defn.empty()) | |
135 | { | |
136 | pvalues.push_back(pj_mkparam<T>(defn)); | |
137 | } | |
138 | } | |
139 | ||
140 | /************************************************************************/ | |
141 | /* pj_datum_set() */ | |
142 | /************************************************************************/ | |
143 | ||
144 | template <typename BGParams, typename T> | |
145 | inline void pj_datum_set(BGParams const& bg_params, std::vector<pvalue<T> >& pvalues, parameters<T>& projdef) | |
146 | { | |
147 | static const T SEC_TO_RAD = detail::SEC_TO_RAD<T>(); | |
148 | ||
149 | projdef.datum_type = PJD_UNKNOWN; | |
150 | ||
151 | pj_datum_add_defn(bg_params, pvalues); | |
152 | ||
153 | /* -------------------------------------------------------------------- */ | |
154 | /* Check for nadgrids parameter. */ | |
155 | /* -------------------------------------------------------------------- */ | |
156 | std::string nadgrids = pj_param(pvalues, "snadgrids").s; | |
157 | std::string towgs84 = pj_param(pvalues, "stowgs84").s; | |
158 | if(! nadgrids.empty()) | |
159 | { | |
160 | /* We don't actually save the value separately. It will continue | |
161 | to exist int he param list for use in pj_apply_gridshift.c */ | |
162 | ||
163 | projdef.datum_type = PJD_GRIDSHIFT; | |
164 | } | |
165 | ||
166 | /* -------------------------------------------------------------------- */ | |
167 | /* Check for towgs84 parameter. */ | |
168 | /* -------------------------------------------------------------------- */ | |
169 | else if(! towgs84.empty()) | |
170 | { | |
171 | int parm_count = 0; | |
172 | ||
173 | int n = sizeof(projdef.datum_params) / sizeof(projdef.datum_params[0]); | |
174 | ||
175 | /* parse out the pvalues */ | |
176 | std::vector<std::string> parm; | |
177 | boost::split(parm, towgs84, boost::is_any_of(" ,")); | |
178 | for (std::vector<std::string>::const_iterator it = parm.begin(); | |
179 | it != parm.end() && parm_count < n; | |
180 | ++it) | |
181 | { | |
182 | projdef.datum_params[parm_count++] = atof(it->c_str()); | |
183 | } | |
184 | ||
185 | if( projdef.datum_params[3] != 0.0 | |
186 | || projdef.datum_params[4] != 0.0 | |
187 | || projdef.datum_params[5] != 0.0 | |
188 | || projdef.datum_params[6] != 0.0 ) | |
189 | { | |
190 | projdef.datum_type = PJD_7PARAM; | |
191 | ||
192 | /* transform from arc seconds to radians */ | |
193 | projdef.datum_params[3] *= SEC_TO_RAD; | |
194 | projdef.datum_params[4] *= SEC_TO_RAD; | |
195 | projdef.datum_params[5] *= SEC_TO_RAD; | |
196 | /* transform from parts per million to scaling factor */ | |
197 | projdef.datum_params[6] = | |
198 | (projdef.datum_params[6]/1000000.0) + 1; | |
199 | } | |
200 | else | |
201 | { | |
202 | projdef.datum_type = PJD_3PARAM; | |
203 | } | |
204 | ||
205 | /* Note that pj_init() will later switch datum_type to | |
206 | PJD_WGS84 if shifts are all zero, and ellipsoid is WGS84 or GRS80 */ | |
207 | } | |
208 | } | |
209 | ||
210 | } // namespace detail | |
211 | }}} // namespace boost::geometry::projections | |
212 | ||
213 | #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_PJ_DATUM_SET_HPP |