projection_epsg.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // This file was modified by Oracle on 2017, 2018.
  7. // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #if defined(_MSC_VER)
  15. #pragma warning( disable : 4305 ) // truncation double -> float
  16. #endif // defined(_MSC_VER)
  17. #include <boost/core/ignore_unused.hpp>
  18. #include <geometry_test_common.hpp>
  19. #include <boost/geometry/srs/epsg.hpp>
  20. #include <boost/geometry/srs/projection.hpp>
  21. #include <boost/geometry/core/coordinate_type.hpp>
  22. #include <boost/geometry/geometries/adapted/c_array.hpp>
  23. #include <boost/geometry/geometries/geometries.hpp>
  24. #include <boost/geometry/geometries/point_xy.hpp>
  25. #include <test_common/test_point.hpp>
  26. namespace srs = bg::srs;
  27. template <int E, typename P1, typename P2>
  28. void test_one(double lon, double lat,
  29. typename bg::coordinate_type<P2>::type x,
  30. typename bg::coordinate_type<P2>::type y)
  31. {
  32. srs::projection<srs::static_epsg<E> > prj;
  33. P1 ll;
  34. bg::set<0>(ll, lon);
  35. bg::set<1>(ll, lat);
  36. P2 xy;
  37. bg::set<0>(xy, 0.0);
  38. bg::set<1>(xy, 0.0);
  39. prj.forward(ll, xy);
  40. BOOST_CHECK_CLOSE(bg::get<0>(xy), x, 0.001);
  41. BOOST_CHECK_CLOSE(bg::get<1>(xy), y, 0.001);
  42. }
  43. template <typename D, typename P>
  44. void test_deg_rad(double factor)
  45. {
  46. typedef typename bg::coordinate_type<P>::type coord_type;
  47. typedef bg::model::point<coord_type, 2, bg::cs::geographic<D> > point_type;
  48. // sterea
  49. test_one<28992, point_type, P>(4.897000 * factor, 52.371000 * factor, 121590.388077, 487013.903377);
  50. // utm
  51. test_one<29118, point_type, P>(4.897000 * factor, 52.371000 * factor, 4938115.7568751378, 9139797.6057944782);
  52. }
  53. template <typename P>
  54. void test_all()
  55. {
  56. test_deg_rad<bg::degree, P>(1.0);
  57. test_deg_rad<bg::radian, P>(bg::math::d2r<double>());
  58. }
  59. int test_main(int, char* [])
  60. {
  61. // Commented out most the types because otherwise it cannot be linked
  62. //test_all<int[2]>();
  63. //test_all<float[2]>();
  64. //test_all<double[2]>();
  65. //test_all<test::test_point>();
  66. //test_all<bg::model::d2::point_xy<int> >();
  67. ////test_all<bg::model::d2::point_xy<float> >();
  68. ////test_all<bg::model::d2::point_xy<long double> >();
  69. test_all<bg::model::d2::point_xy<double> >();
  70. return 0;
  71. }