srs_transformer.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Boost.Geometry
  2. // Unit Test
  3. // Copyright (c) 2017-2018, Oracle and/or its affiliates.
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include <geometry_test_common.hpp>
  9. #include <boost/geometry.hpp>
  10. #include <boost/geometry/geometries/geometries.hpp>
  11. #include <boost/geometry/srs/epsg.hpp>
  12. #include <boost/geometry/srs/projection.hpp>
  13. #include <boost/geometry/srs/transformation.hpp>
  14. #include <boost/geometry/strategies/transform/srs_transformer.hpp>
  15. #include <boost/geometry/io/wkt/read.hpp>
  16. #include "check_geometry.hpp"
  17. int test_main(int, char*[])
  18. {
  19. using namespace boost::geometry;
  20. using namespace boost::geometry::model;
  21. using namespace boost::geometry::srs;
  22. using namespace bg::strategy::transform;
  23. typedef point<double, 2, cs::geographic<degree> > point_ll;
  24. typedef point<double, 2, cs::cartesian> point_xy;
  25. //typedef polygon<point_ll> polygon_ll;
  26. //typedef polygon<point_xy> polygon_xy;
  27. {
  28. point_ll pt_ll(1, 1);
  29. point_ll pt_ll2(0, 0);
  30. point_xy pt_xy(0, 0);
  31. point_xy pt_xy2(0, 0);
  32. srs_forward_transformer<projection<> > strategy_pf = proj4("+proj=tmerc +ellps=WGS84 +units=m");
  33. srs_inverse_transformer<projection<> > strategy_pi = proj4("+proj=tmerc +ellps=WGS84 +units=m");
  34. srs_forward_transformer<transformation<> > strategy_tf(proj4("+proj=tmerc +ellps=WGS84 +units=m"),
  35. proj4("+proj=tmerc +ellps=clrk66 +units=m"));
  36. srs_inverse_transformer<transformation<> > strategy_ti(proj4("+proj=tmerc +ellps=WGS84 +units=m"),
  37. proj4("+proj=tmerc +ellps=clrk66 +units=m"));
  38. bg::transform(pt_ll, pt_xy, strategy_pf);
  39. test::check_geometry(pt_xy, "POINT(111308.33561309829 110591.34223734379)", 0.0001);
  40. bg::transform(pt_xy, pt_ll2, strategy_pi);
  41. test::check_geometry(pt_ll2, "POINT(1 1)", 0.0001);
  42. bg::transform(pt_xy, pt_xy2, strategy_tf);
  43. test::check_geometry(pt_xy2, "POINT(111309.54843459482 110584.27813586517)", 0.0001);
  44. bg::transform(pt_xy2, pt_xy, strategy_ti);
  45. test::check_geometry(pt_xy, "POINT(111308.33561309829 110591.34223734379)", 0.0001);
  46. }
  47. {
  48. srs_forward_transformer<projection<> > strategy_pf = epsg(2000);
  49. srs_inverse_transformer<projection<> > strategy_pi = epsg(2000);
  50. srs_forward_transformer<transformation<> > strategy_tf(epsg(2000), epsg(2001));
  51. srs_inverse_transformer<transformation<> > strategy_ti(epsg(2000), epsg(2001));
  52. }
  53. {
  54. using namespace bg::srs::spar;
  55. srs_forward_transformer
  56. <
  57. projection<parameters<proj_tmerc, ellps_wgs84> >
  58. > strategy_pf;
  59. srs_forward_transformer
  60. <
  61. projection<parameters<proj_tmerc, ellps_wgs84> >
  62. > strategy_pi;
  63. srs_forward_transformer
  64. <
  65. transformation
  66. <
  67. parameters<proj_tmerc, ellps_wgs84>,
  68. parameters<proj_tmerc, ellps_clrk66>
  69. >
  70. > strategy_tf;
  71. srs_forward_transformer
  72. <
  73. transformation
  74. <
  75. parameters<proj_tmerc, ellps_wgs84>,
  76. parameters<proj_tmerc, ellps_clrk66>
  77. >
  78. > strategy_ti;
  79. }
  80. {
  81. srs_forward_transformer<projection<static_epsg<2000> > > strategy_pf;
  82. srs_forward_transformer<projection<static_epsg<2000> > > strategy_pi;
  83. srs_forward_transformer<transformation<static_epsg<2000>, static_epsg<2001> > > strategy_tf;
  84. srs_forward_transformer<transformation<static_epsg<2000>, static_epsg<2001> > > strategy_ti;
  85. }
  86. return 0;
  87. }