projection.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #define BOOST_GEOMETRY_SRS_ENABLE_STATIC_PROJECTION_HYBRID_INTERFACE
  18. #include <geometry_test_common.hpp>
  19. #include <boost/geometry/srs/projection.hpp>
  20. #include <boost/geometry/algorithms/transform.hpp>
  21. #include <boost/geometry/core/coordinate_type.hpp>
  22. #include <boost/geometry/geometries/geometries.hpp>
  23. #include <boost/geometry/geometries/point_xy.hpp>
  24. #include <boost/geometry/geometries/adapted/c_array.hpp>
  25. #include <test_common/test_point.hpp>
  26. namespace srs = bg::srs;
  27. template <typename P1, typename P2, typename Params>
  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. Params const& params)
  32. {
  33. // hybrid interface disabled by default
  34. // static_proj4 default ctor, dynamic parameters passed
  35. srs::projection<Params> prj(params);
  36. P1 ll;
  37. bg::set<0>(ll, lon);
  38. bg::set<1>(ll, lat);
  39. P2 xy;
  40. prj.forward(ll, xy);
  41. BOOST_CHECK_CLOSE(bg::get<0>(xy), x, 0.001);
  42. BOOST_CHECK_CLOSE(bg::get<1>(xy), y, 0.001);
  43. }
  44. template <typename P>
  45. void test_all()
  46. {
  47. typedef typename bg::coordinate_type<P>::type coord_type;
  48. typedef bg::model::point<coord_type, 2, bg::cs::geographic<bg::degree> > point_type;
  49. using namespace srs::spar;
  50. // aea
  51. test_one<point_type, P>
  52. (4.897000, 52.371000, 334609.583974, 5218502.503686,
  53. parameters<proj_aea, ellps_wgs84, units_m, lat_1<>, lat_2<> >(
  54. proj_aea(), ellps_wgs84(), units_m(), lat_1<>(55), lat_2<>(65)));
  55. }
  56. BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(bg::cs::cartesian)
  57. int test_main(int, char* [])
  58. {
  59. //test_all<int[2]>();
  60. test_all<float[2]>();
  61. test_all<double[2]>();
  62. // 2D -> 3D
  63. //test_all<test::test_point>();
  64. //test_all<bg::model::d2::point_xy<int> >();
  65. test_all<bg::model::d2::point_xy<float> >();
  66. test_all<bg::model::d2::point_xy<double> >();
  67. test_all<bg::model::d2::point_xy<long double> >();
  68. return 0;
  69. }