• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
5 
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
10 
11 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
12 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
13 
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)
17 
18 #include <boost/geometry.hpp>
19 #include <geometry_test_common.hpp>
20 
21 namespace bg = boost::geometry;
22 
23 //Testing geographic strategies
24 template <typename CT>
test_geo_strategies()25 void test_geo_strategies()
26 {
27     std::string poly = "POLYGON((52 0, 41 -74, -23 -43, -26 28, 52 0))";
28 
29     typedef bg::model::point<CT, 2, bg::cs::geographic<bg::degree> > pt_geo;
30 
31     bg::strategy::area::geographic<> geographic_default;
32 
33     bg::strategy::area::geographic<bg::strategy::andoyer, 1>
34         geographic_andoyer1;
35     bg::strategy::area::geographic<bg::strategy::andoyer, 2>
36         geographic_andoyer2;
37     bg::strategy::area::geographic<bg::strategy::andoyer, 3>
38         geographic_andoyer3;
39     bg::strategy::area::geographic<bg::strategy::andoyer, 4>
40         geographic_andoyer4;
41     bg::strategy::area::geographic<bg::strategy::andoyer, 5>
42         geographic_andoyer5;
43 
44     bg::strategy::area::geographic<bg::strategy::thomas, 1>
45         geographic_thomas1;
46     bg::strategy::area::geographic<bg::strategy::thomas, 2>
47         geographic_thomas2;
48     bg::strategy::area::geographic<bg::strategy::thomas, 3>
49         geographic_thomas3;
50     bg::strategy::area::geographic<bg::strategy::thomas, 4>
51         geographic_thomas4;
52     bg::strategy::area::geographic<bg::strategy::thomas, 5>
53         geographic_thomas5;
54 
55     bg::strategy::area::geographic<bg::strategy::vincenty, 1>
56         geographic_vincenty1;
57     bg::strategy::area::geographic<bg::strategy::vincenty, 2>
58         geographic_vincenty2;
59     bg::strategy::area::geographic<bg::strategy::vincenty, 3>
60         geographic_vincenty3;
61     bg::strategy::area::geographic<bg::strategy::vincenty, 4>
62         geographic_vincenty4;
63     bg::strategy::area::geographic<bg::strategy::vincenty, 5>
64         geographic_vincenty5;
65 
66     bg::strategy::area::geographic<bg::strategy::andoyer>
67         geographic_andoyer_default;
68     bg::strategy::area::geographic<bg::strategy::thomas>
69         geographic_thomas_default;
70     bg::strategy::area::geographic<bg::strategy::vincenty>
71         geographic_vincenty_default;
72 
73     bg::model::polygon<pt_geo> geometry_geo;
74 
75     //GeographicLib         63316536351834.289
76     //PostGIS (v2.2.2)      6.33946+13
77     //MS SQL SERVER         632930207487035
78 
79     bg::read_wkt(poly, geometry_geo);
80     CT area;
81     CT err = 0.0000001;
82 
83     CT area_default = bg::area(geometry_geo);
84     BOOST_CHECK_CLOSE(area_default, 63316309346280.18, err);
85     area = bg::area(geometry_geo, geographic_default);
86     BOOST_CHECK_CLOSE(area, 63316309346280.18, err);
87 
88     CT area_less_accurate = bg::area(geometry_geo, geographic_andoyer1);
89     BOOST_CHECK_CLOSE(area, 63316309346280.18, err);
90     area = bg::area(geometry_geo, geographic_andoyer2);
91     BOOST_CHECK_CLOSE(area, 63316309224306.5, err);
92     area = bg::area(geometry_geo, geographic_andoyer3);
93     BOOST_CHECK_CLOSE(area, 63316309224411.195, err);
94     area = bg::area(geometry_geo, geographic_andoyer4);
95     BOOST_CHECK_CLOSE(area, 63316309224411.094, err);
96     area = bg::area(geometry_geo, geographic_andoyer5);
97     BOOST_CHECK_CLOSE(area, 63316309224411.094, err);
98 
99     area = bg::area(geometry_geo, geographic_thomas1);
100     BOOST_CHECK_CLOSE(area, 63316536214315.32, err);
101     area = bg::area(geometry_geo, geographic_thomas2);
102     BOOST_CHECK_CLOSE(area, 63316536092341.266, err);
103     area = bg::area(geometry_geo, geographic_thomas3);
104     BOOST_CHECK_CLOSE(area, 63316536092445.961, err);
105     area = bg::area(geometry_geo, geographic_thomas4);
106     BOOST_CHECK_CLOSE(area, 63316536092445.859, err);
107     area = bg::area(geometry_geo, geographic_thomas5);
108     BOOST_CHECK_CLOSE(area, 63316536092445.859, err);
109 
110     area = bg::area(geometry_geo, geographic_vincenty1);
111     BOOST_CHECK_CLOSE(area, 63316536473798.984, err);
112     area = bg::area(geometry_geo, geographic_vincenty2);
113     BOOST_CHECK_CLOSE(area, 63316536351824.93, err);
114     area = bg::area(geometry_geo, geographic_vincenty3);
115     BOOST_CHECK_CLOSE(area, 63316536351929.625, err);
116     area = bg::area(geometry_geo, geographic_vincenty4);
117     BOOST_CHECK_CLOSE(area, 63316536351929.523, err);
118     CT area_most_accurate = bg::area(geometry_geo, geographic_vincenty5);
119     BOOST_CHECK_CLOSE(area, 63316536351929.523, err);
120 
121     area = bg::area(geometry_geo, geographic_andoyer_default);
122     BOOST_CHECK_CLOSE(area, 63316309346280.18, err);
123     area = bg::area(geometry_geo, geographic_thomas_default);
124     BOOST_CHECK_CLOSE(area, 63316536092341.266, err);
125     area = bg::area(geometry_geo, geographic_vincenty_default);
126     BOOST_CHECK_CLOSE(area, 63316536351929.523, err);
127 
128     BOOST_CHECK_CLOSE(area_most_accurate, area_less_accurate, .001);
129     BOOST_CHECK_CLOSE(area_most_accurate, area_default, .001);
130 /*
131     // timings and accuracy
132     std::cout.precision(25);
133     std::size_t exp_times = 100000;
134     {   clock_t startTime = clock();
135         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer1);
136         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
137         std::cout  << area << std::endl;}
138     {   clock_t startTime = clock();
139         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer2);
140         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
141         std::cout  << area << std::endl;}
142     {   clock_t startTime = clock();
143         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer3);
144         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
145         std::cout  << area << std::endl;}
146     {   clock_t startTime = clock();
147         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer4);
148         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
149         std::cout  << area << std::endl;}
150     {   clock_t startTime = clock();
151         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer5);
152         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
153         std::cout  << area << std::endl;}
154     {   clock_t startTime = clock();
155         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas1);
156         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
157         std::cout  << area << std::endl;}
158     {   clock_t startTime = clock();
159         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas2);
160         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
161         std::cout  << area << std::endl;}
162     {   clock_t startTime = clock();
163         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas3);
164         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
165         std::cout  << area << std::endl;}
166     {   clock_t startTime = clock();
167         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas4);
168         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
169         std::cout  << area << std::endl;}
170     {   clock_t startTime = clock();
171         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas5);
172         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
173         std::cout  << area << std::endl;}
174     {   clock_t startTime = clock();
175         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty1);
176         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
177         std::cout  << area << std::endl;}
178     {   clock_t startTime = clock();
179         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty2);
180         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
181         std::cout  << area << std::endl;}
182     {   clock_t startTime = clock();
183         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty3);
184         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
185         std::cout  << area << std::endl;}
186     {   clock_t startTime = clock();
187         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty4);
188         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
189         std::cout  << area << std::endl;}
190     {   clock_t startTime = clock();
191         for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty5);
192         std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
193         std::cout  << area << std::endl;}
194 */
195 }
196 
test_main(int,char * [])197 int test_main(int, char* [])
198 {
199 
200     test_geo_strategies<double>();
201 
202     return 0;
203 }
204