]>
Commit | Line | Data |
---|---|---|
1 | // Boost.Geometry | |
2 | ||
3 | // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | ||
5 | // This file was modified by Oracle on 2014. | |
6 | // Modifications copyright (c) 2014 Oracle and/or its affiliates. | |
7 | ||
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 | #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_VINCENTY_HPP | |
15 | #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_VINCENTY_HPP | |
16 | ||
17 | ||
18 | #include <boost/geometry/core/coordinate_type.hpp> | |
19 | #include <boost/geometry/core/radian_access.hpp> | |
20 | ||
21 | #include <boost/geometry/strategies/distance.hpp> | |
22 | ||
23 | #include <boost/geometry/util/promote_floating_point.hpp> | |
24 | #include <boost/geometry/util/select_calculation_type.hpp> | |
25 | ||
26 | #include <boost/geometry/algorithms/detail/vincenty_inverse.hpp> | |
27 | ||
28 | namespace boost { namespace geometry | |
29 | { | |
30 | ||
31 | namespace strategy { namespace distance | |
32 | { | |
33 | ||
34 | /*! | |
35 | \brief Distance calculation formulae on latlong coordinates, after Vincenty, 1975 | |
36 | \ingroup distance | |
37 | \tparam Spheroid The reference spheroid model | |
38 | \tparam CalculationType \tparam_calculation | |
39 | \author See | |
40 | - http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf | |
41 | - http://www.icsm.gov.au/gda/gdav2.3.pdf | |
42 | \author Adapted from various implementations to get it close to the original document | |
43 | - http://www.movable-type.co.uk/scripts/LatLongVincenty.html | |
44 | - http://exogen.case.edu/projects/geopy/source/geopy.distance.html | |
45 | - http://futureboy.homeip.net/fsp/colorize.fsp?fileName=navigation.frink | |
46 | ||
47 | */ | |
48 | template | |
49 | < | |
50 | typename Spheroid, | |
51 | typename CalculationType = void | |
52 | > | |
53 | class vincenty | |
54 | { | |
55 | public : | |
56 | template <typename Point1, typename Point2> | |
57 | struct calculation_type | |
58 | : promote_floating_point | |
59 | < | |
60 | typename select_calculation_type | |
61 | < | |
62 | Point1, | |
63 | Point2, | |
64 | CalculationType | |
65 | >::type | |
66 | > | |
67 | {}; | |
68 | ||
69 | typedef Spheroid model_type; | |
70 | ||
71 | inline vincenty() | |
72 | : m_spheroid() | |
73 | {} | |
74 | ||
75 | explicit inline vincenty(Spheroid const& spheroid) | |
76 | : m_spheroid(spheroid) | |
77 | {} | |
78 | ||
79 | template <typename Point1, typename Point2> | |
80 | inline typename calculation_type<Point1, Point2>::type | |
81 | apply(Point1 const& point1, Point2 const& point2) const | |
82 | { | |
83 | return geometry::detail::vincenty_inverse | |
84 | < | |
85 | typename calculation_type<Point1, Point2>::type, | |
86 | true, false | |
87 | >::apply(get_as_radian<0>(point1), | |
88 | get_as_radian<1>(point1), | |
89 | get_as_radian<0>(point2), | |
90 | get_as_radian<1>(point2), | |
91 | m_spheroid).distance; | |
92 | } | |
93 | ||
94 | inline Spheroid const& model() const | |
95 | { | |
96 | return m_spheroid; | |
97 | } | |
98 | ||
99 | private : | |
100 | Spheroid m_spheroid; | |
101 | }; | |
102 | ||
103 | #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS | |
104 | namespace services | |
105 | { | |
106 | ||
107 | template <typename Spheroid, typename CalculationType> | |
108 | struct tag<vincenty<Spheroid, CalculationType> > | |
109 | { | |
110 | typedef strategy_tag_distance_point_point type; | |
111 | }; | |
112 | ||
113 | ||
114 | template <typename Spheroid, typename CalculationType, typename P1, typename P2> | |
115 | struct return_type<vincenty<Spheroid, CalculationType>, P1, P2> | |
116 | : vincenty<Spheroid, CalculationType>::template calculation_type<P1, P2> | |
117 | {}; | |
118 | ||
119 | ||
120 | template <typename Spheroid, typename CalculationType> | |
121 | struct comparable_type<vincenty<Spheroid, CalculationType> > | |
122 | { | |
123 | typedef vincenty<Spheroid, CalculationType> type; | |
124 | }; | |
125 | ||
126 | ||
127 | template <typename Spheroid, typename CalculationType> | |
128 | struct get_comparable<vincenty<Spheroid, CalculationType> > | |
129 | { | |
130 | static inline vincenty<Spheroid, CalculationType> apply(vincenty<Spheroid, CalculationType> const& input) | |
131 | { | |
132 | return input; | |
133 | } | |
134 | }; | |
135 | ||
136 | template <typename Spheroid, typename CalculationType, typename P1, typename P2> | |
137 | struct result_from_distance<vincenty<Spheroid, CalculationType>, P1, P2 > | |
138 | { | |
139 | template <typename T> | |
140 | static inline typename return_type<vincenty<Spheroid, CalculationType>, P1, P2>::type | |
141 | apply(vincenty<Spheroid, CalculationType> const& , T const& value) | |
142 | { | |
143 | return value; | |
144 | } | |
145 | }; | |
146 | ||
147 | ||
148 | } // namespace services | |
149 | #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS | |
150 | ||
151 | ||
152 | // We might add a vincenty-like strategy also for point-segment distance, but to calculate the projected point is not trivial | |
153 | ||
154 | ||
155 | ||
156 | }} // namespace strategy::distance | |
157 | ||
158 | ||
159 | }} // namespace boost::geometry | |
160 | ||
161 | ||
162 | #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_VINCENTY_HPP |