3 // Copyright (c) 2017-2018, Oracle and/or its affiliates.
4 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_PAR4_HPP
11 #define BOOST_GEOMETRY_SRS_PROJECTIONS_PAR4_HPP
14 #include <boost/geometry/core/tag.hpp>
15 #include <boost/geometry/core/tags.hpp>
17 #include <boost/geometry/srs/sphere.hpp>
18 #include <boost/geometry/srs/spheroid.hpp>
20 #include <boost/mpl/assert.hpp>
21 #include <boost/mpl/if.hpp>
22 #include <boost/tuple/tuple.hpp>
23 #include <boost/type_traits/integral_constant.hpp>
24 #include <boost/type_traits/is_same.hpp>
25 #include <boost/type_traits/is_void.hpp>
28 namespace boost { namespace geometry { namespace srs { namespace par4
32 // defined in projections' implementation files
80 //struct WGS84 {}; // already defined above
86 struct hermannskogel {};
97 #ifndef DOXYGEN_NO_DETAIL
104 typename Tag = typename geometry::tag<E>::type
107 : private E // empty base optimization
111 ellps_impl() : E() {}
112 explicit ellps_impl(E const& e) : E(e) {}
114 E const& model() const { return *this; }
117 template <typename E>
118 struct ellps_impl<E, void>
123 } // namespace detail
124 #endif // DOXYGEN_NO_DETAIL
128 : par4::detail::ellps_impl<E>
131 explicit ellps(E const& e)
132 : par4::detail::ellps_impl<E>(e)
136 template <typename D>
142 template <typename P>
150 #ifndef DOXYGEN_NO_DETAIL
154 inline double b_from_a_rf(double a, double rf)
156 return a * (1.0 - 1.0 / rf);
162 typename Tag = typename geometry::tag<typename Ellps::type>::type
166 typedef typename Ellps::type model_type;
167 static model_type model(Ellps const& e) { return e.model(); }
170 #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_B(NAME, A, B) \
172 struct ellps_traits<ellps<par4::NAME>, void> \
174 typedef srs::spheroid<double> model_type; \
175 static model_type model(ellps<par4::NAME> const&) { return model_type(A, B); } \
178 #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(NAME, A, RF) \
180 struct ellps_traits<ellps<par4::NAME>, void> \
182 typedef srs::spheroid<double> model_type; \
183 static model_type model(ellps<par4::NAME> const&) { return model_type(A, b_from_a_rf(A, RF)); } \
186 #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_SPHERE(NAME, R) \
188 struct ellps_traits<ellps<par4::NAME>, void> \
190 typedef srs::sphere<double> model_type; \
191 static model_type model(ellps<par4::NAME> const&) { return model_type(R); } \
194 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(MERIT, 6378137.0, 298.257)
195 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(SGS85, 6378136.0, 298.257)
196 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(GRS80, 6378137.0, 298.257222101)
197 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(IAU76, 6378140.0, 298.257)
198 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_B (airy, 6377563.396, 6356256.910)
199 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(APL4_9, 6378137.0, 298.25)
200 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(NWL9D, 6378145.0, 298.25)
201 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_B (mod_airy, 6377340.189, 6356034.446)
202 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(andrae, 6377104.43, 300.0)
203 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(aust_SA, 6378160.0, 298.25)
204 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(GRS67, 6378160.0, 298.2471674270)
205 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(bessel, 6377397.155, 299.1528128)
206 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(bess_nam, 6377483.865, 299.1528128)
207 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_B (clrk66, 6378206.4, 6356583.8)
208 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(clrk80, 6378249.145, 293.4663)
209 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(clrk80ign, 6378249.2, 293.4660212936269)
210 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(CPM, 6375738.7, 334.29)
211 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(delmbr, 6376428.0, 311.5)
212 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(engelis, 6378136.05, 298.2566)
213 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(evrst30, 6377276.345, 300.8017)
214 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(evrst48, 6377304.063, 300.8017)
215 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(evrst56, 6377301.243, 300.8017)
216 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(evrst69, 6377295.664, 300.8017)
217 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(evrstSS, 6377298.556, 300.8017)
218 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(fschr60, 6378166.0, 298.3)
219 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(fschr60m, 6378155.0, 298.3)
220 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(fschr68, 6378150.0, 298.3)
221 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(helmert, 6378200.0, 298.3)
222 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(hough, 6378270.0, 297.0)
223 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(intl, 6378388.0, 297.0)
224 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(krass, 6378245.0, 298.3)
225 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(kaula, 6378163.0, 298.24)
226 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(lerch, 6378139.0, 298.257)
227 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(mprts, 6397300.0, 191.0)
228 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_B (new_intl, 6378157.5, 6356772.2)
229 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_B (plessis, 6376523.0, 6355863.0)
230 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_B (SEasia, 6378155.0, 6356773.3205)
231 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_B (walbeck, 6376896.0, 6355834.8467)
232 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(WGS60, 6378165.0, 298.3)
233 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(WGS66, 6378145.0, 298.25)
234 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(WGS72, 6378135.0, 298.26)
235 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_ELLPS_A_RF(WGS84, 6378137.0, 298.257223563)
236 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_SPHERE (sphere, 6370997.0)
239 template <typename D>
242 typedef void ellps_type;
243 static std::string id() { return ""; }
244 static std::string definition() { return ""; }
247 #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(NAME, ID, ELLPS, DEF) \
249 struct datum_traits< datum<par4::NAME> > \
251 typedef par4::ellps<par4::ELLPS> ellps_type; \
252 static std::string id() { return ID; } \
253 static std::string definition() { return DEF; } \
256 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(WGS84, "WGS84", WGS84, "towgs84=0,0,0")
257 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(GGRS87, "GGRS87", GRS80, "towgs84=-199.87,74.79,246.62")
258 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(NAD83, "NAD83", GRS80, "towgs84=0,0,0")
259 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(NAD27, "NAD27", clrk66, "nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat")
260 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(potsdam, "potsdam", bessel, "towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7")
261 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(carthage, "carthage", clrk80ign, "towgs84=-263.0,6.0,431.0")
262 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(hermannskogel, "hermannskogel", bessel, "towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232")
263 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(ire65, "ire65", mod_airy, "towgs84=482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15")
264 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(nzgd49, "nzgd49", intl, "towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993")
265 BOOST_GEOMETRY_PROJECTIONS_DETAIL_REGISTER_DATUM(OSGB36, "OSGB36", airy, "towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894")
271 template <typename> class IsSamePred,
273 int N = boost::tuples::length<Tuple>::value
275 struct tuples_find_index_if
278 IsSamePred<typename boost::tuples::element<I, Tuple>::type>::value,
279 boost::integral_constant<int, I>,
280 typename tuples_find_index_if<Tuple, IsSamePred, I+1, N>::type
287 template <typename> class IsSamePred,
290 struct tuples_find_index_if<Tuple, IsSamePred, N, N>
291 : boost::integral_constant<int, N>
297 template <typename> class IsSamePred,
298 int I = tuples_find_index_if<Tuple, IsSamePred>::value,
299 int N = boost::tuples::length<Tuple>::value
301 struct tuples_find_if
302 : boost::tuples::element<I, Tuple>
308 template <typename> class IsSamePred,
311 struct tuples_find_if<Tuple, IsSamePred, N, N>
316 /*template <typename Param>
319 template <typename T, int D = 0>
320 struct is_same_impl : boost::false_type {};
322 struct is_same_impl<Param, D> : boost::true_type {};
324 template <typename T>
325 struct is_same : is_same_impl<T> {};
328 template <template <typename> class Param>
331 template <typename T>
332 struct is_same : boost::false_type {};
333 template <typename T>
334 struct is_same<Param<T> > : boost::true_type {};
337 // NOTE: The following metafunctions are implemented one for each parameter
338 // because mingw-gcc-4.1.2 is unable to compile a solution based on template
339 // template parameter and member struct template partial specialization
342 /*template <typename T>
343 struct is_proj : boost::false_type {};
344 template <typename T>
345 struct is_proj<proj<T> > : boost::true_type {};
347 template <typename T>
348 struct is_ellps : boost::false_type {};
349 template <typename T>
350 struct is_ellps<ellps<T> > : boost::true_type {};
352 template <typename T>
353 struct is_datum : boost::false_type {};
354 template <typename T>
355 struct is_datum<datum<T> > : boost::true_type {};
357 template <typename T>
358 struct is_o_proj : boost::false_type {};
359 template <typename T>
360 struct is_o_proj<o_proj<T> > : boost::true_type {};
362 template <typename T>
363 struct is_guam : boost::false_type {};
365 struct is_guam<guam> : boost::true_type {};*/
367 // NOTE: The following implementation seems to work as well.
371 template <typename T, template <typename> class Param>
372 struct is_same_t : boost::false_type {};
373 template <typename T, template <typename> class Param>
374 struct is_same_t<Param<T>, Param> : boost::true_type {};
376 template <typename Param>
379 template <typename T>
380 struct pred : boost::is_same<T, Param> {};
383 template <template <typename> class Param>
386 template <typename T>
387 struct pred : is_same_t<T, Param> {};
390 // pick proj static name
392 template <typename Tuple>
395 typedef typename tuples_find_if
399 is_param_t<proj>::pred
402 static const bool is_non_void = ! boost::is_void<proj_type>::value;
404 BOOST_MPL_ASSERT_MSG((is_non_void), PROJECTION_NOT_NAMED, (Tuple));
406 typedef typename proj_type::type type;
410 template <typename Ellps, typename Datum, int EllpsIndex>
411 struct pick_ellps_impl
414 typedef typename ellps_traits<Ellps>::model_type model_type;
415 template <typename Tuple>
416 static model_type model(Tuple const& tup)
418 return ellps_traits<Ellps>::model(boost::get<EllpsIndex>(tup));
422 template <typename Ellps, int EllpsIndex>
423 struct pick_ellps_impl<Ellps, void, EllpsIndex>
426 typedef typename ellps_traits<Ellps>::model_type model_type;
427 template <typename Tuple>
428 static model_type model(Tuple const& tup)
430 return ellps_traits<Ellps>::model(boost::get<EllpsIndex>(tup));
434 template <typename Datum, int EllpsIndex>
435 struct pick_ellps_impl<void, Datum, EllpsIndex>
437 typedef typename datum_traits<Datum>::ellps_type type;
439 static const bool is_datum_known = ! boost::is_void<type>::value;
440 BOOST_MPL_ASSERT_MSG((is_datum_known), UNKNOWN_DATUM, (types<Datum>));
442 typedef typename ellps_traits<type>::model_type model_type;
443 template <typename Tuple>
444 static model_type model(Tuple const& )
446 return ellps_traits<type>::model(type());
450 template <int EllpsIndex>
451 struct pick_ellps_impl<void, void, EllpsIndex>
454 typedef ellps<WGS84> type;
455 typedef typename ellps_traits<type>::model_type model_type;
456 template <typename Tuple>
457 static model_type model(Tuple const& )
459 return ellps_traits<type>::model(type());
463 // Pick spheroid/sphere model from ellps or datum
464 // mimic pj_init() calling pj_datum_set() and pj_ell_set()
465 template <typename Tuple>
469 typename tuples_find_if<Tuple, /*is_ellps*/is_param_t<ellps>::pred>::type,
470 typename tuples_find_if<Tuple, /*is_datum*/is_param_t<datum>::pred>::type,
471 tuples_find_index_if<Tuple, /*is_ellps*/is_param_t<ellps>::pred>::value
476 template <typename Tuple>
477 struct pick_o_proj_tag
479 typedef typename tuples_find_if
483 is_param_t<o_proj>::pred
486 static const bool is_non_void = ! boost::is_void<proj_type>::value;
488 BOOST_MPL_ASSERT_MSG((is_non_void), PROJECTION_NOT_NAMED, (Tuple));
490 typedef typename proj_type::type type;
494 } // namespace detail
495 #endif // DOXYGEN_NO_DETAIL
498 }}}} // namespace boost::geometry::srs::par4
501 #endif // BOOST_GEOMETRY_SRS_PROJECTIONS_PAR4_HPP