distance_vincenty.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Boost.Geometry
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2014-2017.
  4. // Modifications copyright (c) 2014-2017 Oracle and/or its affiliates.
  5. // 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)
  9. #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_VINCENTY_HPP
  10. #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_VINCENTY_HPP
  11. #include <boost/geometry/strategies/geographic/distance.hpp>
  12. #include <boost/geometry/strategies/geographic/parameters.hpp>
  13. namespace boost { namespace geometry
  14. {
  15. namespace strategy { namespace distance
  16. {
  17. /*!
  18. \brief Distance calculation formulae on latlong coordinates, after Vincenty, 1975
  19. \ingroup distance
  20. \tparam Spheroid The reference spheroid model
  21. \tparam CalculationType \tparam_calculation
  22. \author See
  23. - http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf
  24. - http://www.icsm.gov.au/gda/gdav2.3.pdf
  25. \author Adapted from various implementations to get it close to the original document
  26. - http://www.movable-type.co.uk/scripts/LatLongVincenty.html
  27. - http://exogen.case.edu/projects/geopy/source/geopy.distance.html
  28. - http://futureboy.homeip.net/fsp/colorize.fsp?fileName=navigation.frink
  29. */
  30. template
  31. <
  32. typename Spheroid = srs::spheroid<double>,
  33. typename CalculationType = void
  34. >
  35. class vincenty
  36. : public strategy::distance::geographic
  37. <
  38. strategy::vincenty, Spheroid, CalculationType
  39. >
  40. {
  41. typedef strategy::distance::geographic
  42. <
  43. strategy::vincenty, Spheroid, CalculationType
  44. > base_type;
  45. public:
  46. inline vincenty()
  47. : base_type()
  48. {}
  49. explicit inline vincenty(Spheroid const& spheroid)
  50. : base_type(spheroid)
  51. {}
  52. };
  53. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  54. namespace services
  55. {
  56. template <typename Spheroid, typename CalculationType>
  57. struct tag<vincenty<Spheroid, CalculationType> >
  58. {
  59. typedef strategy_tag_distance_point_point type;
  60. };
  61. template <typename Spheroid, typename CalculationType, typename P1, typename P2>
  62. struct return_type<vincenty<Spheroid, CalculationType>, P1, P2>
  63. : vincenty<Spheroid, CalculationType>::template calculation_type<P1, P2>
  64. {};
  65. template <typename Spheroid, typename CalculationType>
  66. struct comparable_type<vincenty<Spheroid, CalculationType> >
  67. {
  68. typedef vincenty<Spheroid, CalculationType> type;
  69. };
  70. template <typename Spheroid, typename CalculationType>
  71. struct get_comparable<vincenty<Spheroid, CalculationType> >
  72. {
  73. static inline vincenty<Spheroid, CalculationType> apply(vincenty<Spheroid, CalculationType> const& input)
  74. {
  75. return input;
  76. }
  77. };
  78. template <typename Spheroid, typename CalculationType, typename P1, typename P2>
  79. struct result_from_distance<vincenty<Spheroid, CalculationType>, P1, P2 >
  80. {
  81. template <typename T>
  82. static inline typename return_type<vincenty<Spheroid, CalculationType>, P1, P2>::type
  83. apply(vincenty<Spheroid, CalculationType> const& , T const& value)
  84. {
  85. return value;
  86. }
  87. };
  88. } // namespace services
  89. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  90. // We might add a vincenty-like strategy also for point-segment distance, but to calculate the projected point is not trivial
  91. }} // namespace strategy::distance
  92. }} // namespace boost::geometry
  93. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_VINCENTY_HPP