spheroid.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2014, 2016, 2017, 2018.
  6. // Modifications copyright (c) 2014-2018 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  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. #ifndef BOOST_GEOMETRY_SRS_SPHEROID_HPP
  14. #define BOOST_GEOMETRY_SRS_SPHEROID_HPP
  15. #include <cstddef>
  16. #include <boost/static_assert.hpp>
  17. #include <boost/geometry/core/radius.hpp>
  18. #include <boost/geometry/core/tag.hpp>
  19. #include <boost/geometry/core/tags.hpp>
  20. namespace boost { namespace geometry
  21. {
  22. namespace srs
  23. {
  24. /*!
  25. \brief Defines spheroid radius values for use in geographical CS calculations
  26. \ingroup srs
  27. \note See http://en.wikipedia.org/wiki/Figure_of_the_Earth
  28. and http://en.wikipedia.org/wiki/World_Geodetic_System#A_new_World_Geodetic_System:_WGS84
  29. \tparam RadiusType tparam_radius
  30. */
  31. template <typename RadiusType>
  32. class spheroid
  33. {
  34. public:
  35. spheroid(RadiusType const& a, RadiusType const& b)
  36. : m_a(a)
  37. , m_b(b)
  38. {}
  39. spheroid()
  40. : m_a(RadiusType(6378137.0))
  41. , m_b(RadiusType(6356752.3142451793))
  42. {}
  43. template <std::size_t I>
  44. RadiusType get_radius() const
  45. {
  46. BOOST_STATIC_ASSERT(I < 3);
  47. return I < 2 ? m_a : m_b;
  48. }
  49. template <std::size_t I>
  50. void set_radius(RadiusType const& radius)
  51. {
  52. BOOST_STATIC_ASSERT(I < 3);
  53. (I < 2 ? m_a : m_b) = radius;
  54. }
  55. private:
  56. RadiusType m_a, m_b; // equatorial radius, polar radius
  57. };
  58. } // namespace srs
  59. // Traits specializations for spheroid
  60. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  61. namespace traits
  62. {
  63. template <typename RadiusType>
  64. struct tag< srs::spheroid<RadiusType> >
  65. {
  66. typedef srs_spheroid_tag type;
  67. };
  68. template <typename RadiusType>
  69. struct radius_type< srs::spheroid<RadiusType> >
  70. {
  71. typedef RadiusType type;
  72. };
  73. template <typename RadiusType, std::size_t Dimension>
  74. struct radius_access<srs::spheroid<RadiusType>, Dimension>
  75. {
  76. typedef srs::spheroid<RadiusType> spheroid_type;
  77. static inline RadiusType get(spheroid_type const& s)
  78. {
  79. return s.template get_radius<Dimension>();
  80. }
  81. static inline void set(spheroid_type& s, RadiusType const& value)
  82. {
  83. s.template set_radius<Dimension>(value);
  84. }
  85. };
  86. } // namespace traits
  87. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  88. }} // namespace boost::geometry
  89. #endif // BOOST_GEOMETRY_SRS_SPHEROID_HPP