1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2015 Barend Gehrels, Amsterdam, the Netherlands.
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
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)
16 #pragma warning( disable : 4305 ) // truncation double -> float
17 #endif // defined(_MSC_VER)
19 #define BOOST_GEOMETRY_SRS_ENABLE_STATIC_PROJECTION_HYBRID_INTERFACE
21 #include <geometry_test_common.hpp>
23 #include <boost/geometry/srs/projection.hpp>
25 #include <boost/geometry/core/coordinate_type.hpp>
26 #include <boost/geometry/algorithms/make.hpp>
28 #include <boost/geometry.hpp>
29 #include <boost/geometry/geometries/geometries.hpp>
30 #include <boost/geometry/geometries/point_xy.hpp>
34 namespace srs
= bg::srs
;
37 bool check_expected(P
const& p1
, P
const& p2
)
39 return bg::math::abs(bg::get
<0>(p1
) - bg::get
<0>(p2
)) <= 1.0
40 && bg::math::abs(bg::get
<1>(p1
) - bg::get
<1>(p2
)) <= 1.0;
43 template <typename StaticParams
, typename GeoPoint
, typename CartPoint
>
44 void test_forward(std::string
const& id
, GeoPoint
const& geo_point
, CartPoint
const& cart_point
,
45 StaticParams
const& params
, std::string
const& proj4
= "")
49 srs::projection
<StaticParams
> prj
= params
;
52 prj
.forward(geo_point
, xy
);
54 bool ok
= check_expected(xy
, cart_point
);
56 BOOST_CHECK_MESSAGE(ok
,
58 << " point: " << bg::wkt(xy
)
59 << " different than expected: " << bg::wkt(cart_point
));
63 srs::projection
<> prj2
= srs::proj4(proj4
);
66 prj2
.forward(geo_point
, xy2
);
68 bool eq2
= bg::equals(xy
, xy2
);
70 BOOST_CHECK_MESSAGE(eq2
,
71 " id: " << id
<< " result of static: "
72 << bg::wkt(xy
) << " different than dynamic: " << bg::wkt(xy2
));
74 #ifdef TEST_WITH_PROJ4
75 pj_projection
prj3(proj4
);
78 prj3
.forward(geo_point
, xy3
);
80 bool eq3
= bg::equals(xy
, xy3
);
82 BOOST_CHECK_MESSAGE(eq3
,
83 " id: " << id
<< " result: "
84 << bg::wkt(xy
) << " different than proj4: " << bg::wkt(xy3
));
85 #endif // TEST_WITH_PROJ4
88 catch(bg::projection_exception
const& e
)
90 std::cout
<< "Exception in " << id
<< " : " << e
.code() << std::endl
;
94 std::cout
<< "Exception (unknown) in " << id
<< std::endl
;
98 template <typename StaticParams
, typename GeoPoint
, typename CartPoint
>
99 void test_forward(std::string
const& id
, GeoPoint
const& geo_point
, CartPoint
const& cart_point
,
100 std::string
const& proj4
= "")
102 test_forward(id
, geo_point
, cart_point
, StaticParams(), proj4
);
105 template <typename T
>
108 typedef bg::model::point
<T
, 2, bg::cs::geographic
<bg::degree
> > geo_point_type
;
109 typedef bg::model::point
<T
, 2, bg::cs::cartesian
> cart
;
111 geo_point_type amsterdam
= bg::make
<geo_point_type
>(4.8925, 52.3731);
112 geo_point_type utrecht
= bg::make
<geo_point_type
>(5.1213, 52.0907);
114 geo_point_type anchorage
= bg::make
<geo_point_type
>(-149.90, 61.22);
115 geo_point_type juneau
= bg::make
<geo_point_type
>(-134.42, 58.30);
117 geo_point_type auckland
= bg::make
<geo_point_type
>(174.74, -36.84);
118 geo_point_type wellington
= bg::make
<geo_point_type
>(177.78, -41.29);
120 geo_point_type aspen
= bg::make
<geo_point_type
>(-106.84, 39.19);
121 geo_point_type denver
= bg::make
<geo_point_type
>(-104.88, 39.76);
123 using namespace srs::spar
;
125 // IGH (internally using moll/sinu)
127 typedef parameters
<proj_igh
, ellps_sphere
, units_m
> params_t
;
128 std::string sparams
= "+proj=igh +ellps=sphere +units=m";
129 test_forward
<params_t
>("igh-am", amsterdam
, cart(1489299.1509520211, 5776413.4260336142), sparams
);
130 test_forward
<params_t
>("igh-ut", utrecht
, cart(1498750.6627020084, 5747394.3313896423), sparams
);
131 test_forward
<params_t
>("igh-as", aspen
, cart(-11708973.126426676, 4357727.1232166551), sparams
);
132 test_forward
<params_t
>("igh-de", denver
, cart(-11536624.264589204, 4421108.2015589233), sparams
);
133 test_forward
<params_t
>("igh-au", auckland
, cart(18658819.353676274, -4096419.1686476548), sparams
);
134 test_forward
<params_t
>("igh-we", wellington
, cart(18733710.557981707, -4591140.1631184481), sparams
);
135 test_forward
<params_t
>("igh-an", anchorage
, cart(-14275110.630537530, 6648284.9393376000), sparams
);
136 test_forward
<params_t
>("igh-ju", juneau
, cart(-13421076.123140398, 6368936.3597440729), sparams
);
141 typedef parameters
<proj_ob_tran
, ellps_wgs84
, o_proj
<proj_moll
>, units_m
, o_lat_p
<>, o_lon_p
<> > params_t
;
142 params_t params
= params_t(proj_ob_tran(), ellps_wgs84(), o_proj
<proj_moll
>(), units_m(), o_lat_p
<>(10), o_lon_p
<>(90));
143 std::string sparams
= "+proj=ob_tran +ellps=WGS84 +o_proj=moll +units=m +o_lat_p=10 +o_lon_p=90 +o_lon_o=11.50";
144 test_forward
<params_t
>("obt-m-am", amsterdam
, cart(8688778.3518596273, -3348126.4518623645), params
, sparams
);
145 test_forward
<params_t
>("obt-m-ut", utrecht
, cart(8693109.5205437448, -3379708.1134765535), params
, sparams
);
146 test_forward
<params_t
>("obt-m-as", aspen
, cart(3691751.3259231807, 2371456.9674431868), params
, sparams
);
147 test_forward
<params_t
>("obt-m-de", denver
, cart(3764685.2104777521, 2185616.0182080171), params
, sparams
);
152 // In Proj4 >= 5.0.0 ob_tran projection doesn't overwrite the ellipsoid's parameters to make sphere in underlying projection
153 // So in order to use spherical sinu projection WGS84-compatible sphere has to be set manually.
154 typedef parameters
<proj_ob_tran
, a
<>, es
<>, o_proj
<proj_sinu
>, units_m
, o_lat_p
<>, o_lon_p
<> > params_t
;
155 params_t params
= params_t(proj_ob_tran(), a
<>(6378137), es
<>(0), o_proj
<proj_sinu
>(), units_m(), o_lat_p
<>(10), o_lon_p
<>(90));
156 std::string sparams
= "+proj=ob_tran +a=6378137 +es=0 +o_proj=sinu +units=m +o_lat_p=10 +o_lon_p=90 +o_lon_o=11.50";
157 test_forward
<params_t
>("obt-s-am", amsterdam
, cart(9220221.4221933037, -3059652.3579233172), params
, sparams
);
158 test_forward
<params_t
>("obt-s-ut", utrecht
, cart(9216281.0977674071, -3089427.4415689218), params
, sparams
);
159 test_forward
<params_t
>("obt-s-as", aspen
, cart(4010672.3356677019, 2150730.9484995930), params
, sparams
);
160 test_forward
<params_t
>("obt-s-de", denver
, cart(4103945.8062708224, 1979964.9315176210), params
, sparams
);
164 int test_main(int, char* [])