area_geo.cpp 9.2 KB

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