1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
6 // This file was modified by Oracle on 2015, 2016, 2017.
7 // Modifications copyright (c) 2015-2017, Oracle and/or its affiliates.
8 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
12 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14 // Use, modification and distribution is subject to the Boost Software License,
15 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt)
18 #include <boost/geometry.hpp>
19 #include <geometry_test_common.hpp>
21 namespace bg
= boost::geometry
;
30 bool EnableReverseAzimuth
= false,
31 bool EnableReducedLength
= false,
32 bool EnableGeodesicScale
= false
35 : bg::formula::detail::karney_inverse
38 EnableAzimuth
, EnableReverseAzimuth
,
39 EnableReducedLength
, EnableGeodesicScale
,
45 //Testing geographic strategies
46 template <typename CT
>
47 void test_geo_strategies()
49 std::string poly
= "POLYGON((52 0, 41 -74, -23 -43, -26 28, 52 0))";
51 typedef bg::model::point
<CT
, 2, bg::cs::geographic
<bg::degree
> > pt_geo
;
53 bg::strategy::area::geographic
<> geographic_default
;
55 bg::strategy::area::geographic
<bg::strategy::andoyer
, 1>
57 bg::strategy::area::geographic
<bg::strategy::andoyer
, 2>
59 bg::strategy::area::geographic
<bg::strategy::andoyer
, 3>
61 bg::strategy::area::geographic
<bg::strategy::andoyer
, 4>
63 bg::strategy::area::geographic
<bg::strategy::andoyer
, 5>
66 bg::strategy::area::geographic
<bg::strategy::thomas
, 1>
68 bg::strategy::area::geographic
<bg::strategy::thomas
, 2>
70 bg::strategy::area::geographic
<bg::strategy::thomas
, 3>
72 bg::strategy::area::geographic
<bg::strategy::thomas
, 4>
74 bg::strategy::area::geographic
<bg::strategy::thomas
, 5>
77 bg::strategy::area::geographic
<bg::strategy::vincenty
, 1>
79 bg::strategy::area::geographic
<bg::strategy::vincenty
, 2>
81 bg::strategy::area::geographic
<bg::strategy::vincenty
, 3>
83 bg::strategy::area::geographic
<bg::strategy::vincenty
, 4>
85 bg::strategy::area::geographic
<bg::strategy::vincenty
, 5>
88 bg::strategy::area::geographic
<bg::strategy::karney
, 1>
90 bg::strategy::area::geographic
<bg::strategy::karney
, 2>
92 bg::strategy::area::geographic
<bg::strategy::karney
, 3>
94 bg::strategy::area::geographic
<bg::strategy::karney
, 4>
96 bg::strategy::area::geographic
<bg::strategy::karney
, 5>
99 bg::strategy::area::geographic
<custom_karney
, 3>
100 geographic_custom_karney3
;
102 bg::strategy::area::geographic
<bg::strategy::andoyer
>
103 geographic_andoyer_default
;
104 bg::strategy::area::geographic
<bg::strategy::thomas
>
105 geographic_thomas_default
;
106 bg::strategy::area::geographic
<bg::strategy::vincenty
>
107 geographic_vincenty_default
;
109 bg::model::polygon
<pt_geo
> geometry_geo
;
111 //GeographicLib 63316536351834.289
112 //PostGIS (v2.2.2) 6.33946+13
113 //MS SQL SERVER 632930207487035
115 bg::read_wkt(poly
, geometry_geo
);
119 CT area_default
= bg::area(geometry_geo
);
120 BOOST_CHECK_CLOSE(area_default
, 63316423532570.688, err
);
121 area
= bg::area(geometry_geo
, geographic_default
);
122 BOOST_CHECK_CLOSE(area
, 63316423532570.688, err
);
124 CT area_less_accurate
= bg::area(geometry_geo
, geographic_andoyer1
);
125 BOOST_CHECK_CLOSE(area
, 63316423532570.688, err
);
126 area
= bg::area(geometry_geo
, geographic_andoyer2
);
127 BOOST_CHECK_CLOSE(area
, 63316423410597.016, err
);
128 area
= bg::area(geometry_geo
, geographic_andoyer3
);
129 BOOST_CHECK_CLOSE(area
, 63316423410701.703, err
);
130 area
= bg::area(geometry_geo
, geographic_andoyer4
);
131 BOOST_CHECK_CLOSE(area
, 63316423410701.602, err
);
132 area
= bg::area(geometry_geo
, geographic_andoyer5
);
133 BOOST_CHECK_CLOSE(area
, 63316423410701.602, err
);
135 area
= bg::area(geometry_geo
, geographic_thomas1
);
136 BOOST_CHECK_CLOSE(area
, 63316536214315.32, err
);
137 area
= bg::area(geometry_geo
, geographic_thomas2
);
138 BOOST_CHECK_CLOSE(area
, 63316536092341.266, err
);
139 area
= bg::area(geometry_geo
, geographic_thomas3
);
140 BOOST_CHECK_CLOSE(area
, 63316536092445.961, err
);
141 area
= bg::area(geometry_geo
, geographic_thomas4
);
142 BOOST_CHECK_CLOSE(area
, 63316536092445.859, err
);
143 area
= bg::area(geometry_geo
, geographic_thomas5
);
144 BOOST_CHECK_CLOSE(area
, 63316536092445.859, err
);
146 area
= bg::area(geometry_geo
, geographic_vincenty1
);
147 BOOST_CHECK_CLOSE(area
, 63316536473798.984, err
);
148 area
= bg::area(geometry_geo
, geographic_vincenty2
);
149 BOOST_CHECK_CLOSE(area
, 63316536351824.93, err
);
150 area
= bg::area(geometry_geo
, geographic_vincenty3
);
151 BOOST_CHECK_CLOSE(area
, 63316536351929.625, err
);
152 area
= bg::area(geometry_geo
, geographic_vincenty4
);
153 BOOST_CHECK_CLOSE(area
, 63316536351929.523, err
);
154 area
= bg::area(geometry_geo
, geographic_vincenty5
);
155 BOOST_CHECK_CLOSE(area
, 63316536351929.523, err
);
157 area
= bg::area(geometry_geo
, geographic_karney1
);
158 BOOST_CHECK_CLOSE(area
, 63316536473703.75, err
);
159 area
= bg::area(geometry_geo
, geographic_karney2
);
160 BOOST_CHECK_CLOSE(area
, 63316536351729.695, err
);
161 area
= bg::area(geometry_geo
, geographic_karney3
);
162 BOOST_CHECK_CLOSE(area
, 63316536351834.383, err
);
163 area
= bg::area(geometry_geo
, geographic_custom_karney3
);
164 BOOST_CHECK_CLOSE(area
, 63316536351834.352, err
);
165 area
= bg::area(geometry_geo
, geographic_karney4
);
166 BOOST_CHECK_CLOSE(area
, 63316536351834.281, err
);
167 CT area_most_accurate
= bg::area(geometry_geo
, geographic_karney5
);
168 BOOST_CHECK_CLOSE(area
, 63316536351834.281, err
);
170 area
= bg::area(geometry_geo
, geographic_andoyer_default
);
171 BOOST_CHECK_CLOSE(area
, 63316423532570.688, err
);
172 area
= bg::area(geometry_geo
, geographic_thomas_default
);
173 BOOST_CHECK_CLOSE(area
, 63316536092341.266, err
);
174 area
= bg::area(geometry_geo
, geographic_vincenty_default
);
175 BOOST_CHECK_CLOSE(area
, 63316536351929.523, err
);
177 BOOST_CHECK_CLOSE(area_most_accurate
, area_less_accurate
, .001);
178 BOOST_CHECK_CLOSE(area_most_accurate
, area_default
, .001);
181 // timings and accuracy
182 std::cout.precision(25);
183 std::size_t exp_times = 100000;
184 { clock_t startTime = clock();
185 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer1);
186 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
187 std::cout << area << std::endl;}
188 { clock_t startTime = clock();
189 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer2);
190 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
191 std::cout << area << std::endl;}
192 { clock_t startTime = clock();
193 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer3);
194 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
195 std::cout << area << std::endl;}
196 { clock_t startTime = clock();
197 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer4);
198 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
199 std::cout << area << std::endl;}
200 { clock_t startTime = clock();
201 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer5);
202 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
203 std::cout << area << std::endl;}
204 { clock_t startTime = clock();
205 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas1);
206 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
207 std::cout << area << std::endl;}
208 { clock_t startTime = clock();
209 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas2);
210 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
211 std::cout << area << std::endl;}
212 { clock_t startTime = clock();
213 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas3);
214 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
215 std::cout << area << std::endl;}
216 { clock_t startTime = clock();
217 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas4);
218 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
219 std::cout << area << std::endl;}
220 { clock_t startTime = clock();
221 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas5);
222 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
223 std::cout << area << std::endl;}
224 { clock_t startTime = clock();
225 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty1);
226 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
227 std::cout << area << std::endl;}
228 { clock_t startTime = clock();
229 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty2);
230 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
231 std::cout << area << std::endl;}
232 { clock_t startTime = clock();
233 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty3);
234 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
235 std::cout << area << std::endl;}
236 { clock_t startTime = clock();
237 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty4);
238 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
239 std::cout << area << std::endl;}
240 { clock_t startTime = clock();
241 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty5);
242 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
243 std::cout << area << std::endl;}
247 int test_main(int, char* [])
250 test_geo_strategies
<double>();