1 // Boost.Geometry
2 // Unit Test
3
4 // Copyright (c) 2017-2018, Oracle and/or its affiliates.
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11
12 #include <geometry_test_common.hpp>
13
14 #include <boost/geometry.hpp>
15 #include <boost/geometry/geometries/geometries.hpp>
16 #include <boost/geometry/srs/projection.hpp>
17
18 #include "check_geometry.hpp"
19
test_main(int,char * [])20 int test_main(int, char*[])
21 {
22 using namespace boost::geometry;
23 using namespace boost::geometry::model;
24 using namespace boost::geometry::srs;
25
26 typedef point<double, 2, cs::geographic<degree> > point_ll;
27 typedef point<double, 2, cs::cartesian> point_xy;
28
29 {
30 point_ll pt_ll(1, 1);
31 point_ll pt_ll2(0, 0);
32 point_xy pt_xy(0, 0);
33
34 projection<> prj = proj4("+proj=tmerc +ellps=WGS84 +units=m");
35
36 prj.forward(pt_ll, pt_xy);
37 test::check_geometry(pt_xy, "POINT(111308.33561309829 110591.34223734379)", 0.001);
38
39 prj.inverse(pt_xy, pt_ll2);
40 test::check_geometry(pt_ll2, "POINT(1 1)", 0.001);
41 }
42
43 // run-time errors
44 {
45 point_ll pt_ll(1, 1);
46 point_xy pt_xy(0, 0);
47
48 BOOST_CHECK_THROW(projection<> prj1((proj4(""))), bg::projection_exception);
49
50 BOOST_CHECK_THROW(projection<> prj1((proj4("+proj=abcd"))), bg::projection_exception);
51
52 projection<> prj3 = proj4("+proj=bacon +a=6400000");
53 BOOST_CHECK_THROW(prj3.inverse(pt_xy, pt_ll), bg::projection_exception);
54 }
55
56 {
57 segment<point_ll> seg_ll;
58 segment<point_xy> seg_xy;
59 linestring<point_ll> ls_ll;
60 linestring<point_xy> ls_xy;
61 ring<point_ll> ring_ll;
62 ring<point_xy> ring_xy;
63 polygon<point_ll> poly_ll;
64 polygon<point_xy> poly_xy;
65 multi_point<point_ll> mpt_ll;
66 multi_point<point_xy> mpt_xy;
67 multi_linestring<linestring<point_ll> > mls_ll;
68 multi_linestring<linestring<point_xy> > mls_xy;
69 multi_polygon<polygon<point_ll> > mpoly_ll;
70 multi_polygon<polygon<point_xy> > mpoly_xy;
71
72 bg::read_wkt("LINESTRING(0 0, 1 1)", seg_ll);
73 bg::read_wkt("LINESTRING(0 0, 1 1, 2 2)", ls_ll);
74 bg::read_wkt("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", ring_ll);
75 bg::read_wkt("POLYGON((0 0, 0 3, 3 3, 3 0, 0 0),(1 1, 2 1, 2 2, 1 2, 1 1))", poly_ll);
76 bg::read_wkt("MULTIPOINT(0 0, 1 1, 2 2)", mpt_ll);
77 bg::read_wkt("MULTILINESTRING((0 0, 1 1),(2 2, 3 3))", mls_ll);
78 bg::read_wkt("MULTIPOLYGON(((0 0, 0 3, 3 3, 3 0, 0 0),(1 1, 2 1, 2 2, 1 2, 1 1)),((3 3,3 4,4 4,4 3,3 3)))", mpoly_ll);
79
80 projection<> prj = proj4("+proj=tmerc +ellps=WGS84 +units=m");
81
82 prj.forward(seg_ll, seg_xy);
83 prj.forward(ls_ll, ls_xy);
84 prj.forward(ring_ll, ring_xy);
85 prj.forward(poly_ll, poly_xy);
86 prj.forward(mpt_ll, mpt_xy);
87 prj.forward(mls_ll, mls_xy);
88 prj.forward(mpoly_ll, mpoly_xy);
89
90 test::check_geometry(seg_xy, "LINESTRING(0 0,111308 110591)", 0.001);
91 test::check_geometry(ls_xy, "LINESTRING(0 0,111308 110591,222550 221285)", 0.001);
92 test::check_geometry(ring_xy, "POLYGON((0 0,0 110574,111308 110591,111325 0,0 0))", 0.001);
93 test::check_geometry(poly_xy, "POLYGON((0 0,0 331726,333657 332183,334112 0,0 0),(111308 110591,222651 110642,222550 221285,111258 221183,111308 110591))", 0.001);
94 test::check_geometry(mpt_xy, "MULTIPOINT((0 0),(111308 110591),(222550 221285))", 0.001);
95 test::check_geometry(mls_xy, "MULTILINESTRING((0 0,111308 110591),(222550 221285,333657 332183))", 0.001);
96 test::check_geometry(mpoly_xy, "MULTIPOLYGON(((0 0,0 331726,333657 332183,334112 0,0 0),(111308 110591,222651 110642,222550 221285,111258 221183,111308 110591)),((333657 332183,333302 442913,444561 443388,445034 332540,333657 332183)))", 0.001);
97
98 bg::clear(seg_ll);
99 bg::clear(ls_ll);
100 bg::clear(ring_ll);
101 bg::clear(poly_ll);
102 bg::clear(mpt_ll);
103 bg::clear(mls_ll);
104 bg::clear(mpoly_ll);
105
106 prj.inverse(seg_xy, seg_ll);
107 prj.inverse(ls_xy, ls_ll);
108 prj.inverse(ring_xy, ring_ll);
109 prj.inverse(poly_xy, poly_ll);
110 prj.inverse(mpt_xy, mpt_ll);
111 prj.inverse(mls_xy, mls_ll);
112 prj.inverse(mpoly_xy, mpoly_ll);
113
114 test::check_geometry(seg_ll, "LINESTRING(0 0, 1 1)", 0.001);
115 test::check_geometry(ls_ll, "LINESTRING(0 0, 1 1, 2 2)", 0.001);
116 test::check_geometry(ring_ll, "POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", 0.001);
117 test::check_geometry(poly_ll, "POLYGON((0 0, 0 3, 3 3, 3 0, 0 0),(1 1, 2 1, 2 2, 1 2, 1 1))", 0.001);
118 test::check_geometry(mpt_ll, "MULTIPOINT(0 0, 1 1, 2 2)", 0.001);
119 test::check_geometry(mls_ll, "MULTILINESTRING((0 0, 1 1),(2 2, 3 3))", 0.001);
120 test::check_geometry(mpoly_ll, "MULTIPOLYGON(((0 0, 0 3, 3 3, 3 0, 0 0),(1 1, 2 1, 2 2, 1 2, 1 1)),((3 3,3 4,4 4,4 3,3 3)))", 0.001);
121 }
122
123 return 0;
124 }
125