123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634 |
- #ifndef BOOST_GEOMETRY_PROJECTIONS_OB_TRAN_HPP
- #define BOOST_GEOMETRY_PROJECTIONS_OB_TRAN_HPP
- #include <memory>
- #include <type_traits>
- #include <boost/geometry/core/static_assert.hpp>
- #include <boost/geometry/srs/projections/impl/aasincos.hpp>
- #include <boost/geometry/srs/projections/impl/base_static.hpp>
- #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
- #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
- #include <boost/geometry/srs/projections/impl/pj_ell_set.hpp>
- #include <boost/geometry/srs/projections/impl/projects.hpp>
- #include <boost/geometry/util/math.hpp>
- namespace boost { namespace geometry
- {
- namespace projections
- {
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail {
-
- template <typename T>
- inline detail::dynamic_wrapper_b<T, projections::parameters<T> >*
- create_new(srs::detail::proj4_parameters const& params,
- projections::parameters<T> const& parameters);
- template <typename T>
- inline detail::dynamic_wrapper_b<T, projections::parameters<T> >*
- create_new(srs::dpar::parameters<T> const& params,
- projections::parameters<T> const& parameters);
- }
- namespace detail { namespace ob_tran
- {
- static const double tolerance = 1e-10;
- template <typename Parameters>
- inline Parameters o_proj_parameters(srs::detail::proj4_parameters const& params,
- Parameters const& par)
- {
-
- Parameters pj = par;
-
- pj.id = pj_get_param_s(params, "o_proj");
- if (pj.id.is_unknown())
- BOOST_THROW_EXCEPTION( projection_exception(error_no_rotation_proj) );
-
- if( pj.id.name == "ob_tran")
- BOOST_THROW_EXCEPTION( projection_exception(error_failed_to_find_proj) );
-
-
-
-
- return pj;
- }
- template <typename T, typename Parameters>
- inline Parameters o_proj_parameters(srs::dpar::parameters<T> const& params,
- Parameters const& par)
- {
-
- Parameters pj = par;
-
- typename srs::dpar::parameters<T>::const_iterator
- it = pj_param_find(params, srs::dpar::o_proj);
- if (it != params.end())
- pj.id = static_cast<srs::dpar::value_proj>(it->template get_value<int>());
- else
- BOOST_THROW_EXCEPTION( projection_exception(error_no_rotation_proj) );
-
- if( pj.id.id == srs::dpar::proj_ob_tran)
- BOOST_THROW_EXCEPTION( projection_exception(error_failed_to_find_proj) );
-
-
-
-
- return pj;
- }
- template <typename ...Ps, typename Parameters>
- inline Parameters o_proj_parameters(srs::spar::parameters<Ps...> const& ,
- Parameters const& par)
- {
-
- Parameters pj = par;
-
- typedef srs::spar::parameters<Ps...> params_type;
- typedef typename geometry::tuples::find_if
- <
- params_type,
- srs::spar::detail::is_param_t<srs::spar::o_proj>::pred
- >::type o_proj_type;
- static const bool is_found = geometry::tuples::is_found<o_proj_type>::value;
- BOOST_GEOMETRY_STATIC_ASSERT((is_found),
- "Rotation projection not specified.",
- params_type);
- typedef typename o_proj_type::type proj_type;
- static const bool is_specialized = srs::spar::detail::proj_traits<proj_type>::is_specialized;
- BOOST_GEOMETRY_STATIC_ASSERT((is_specialized),
- "Rotation projection not specified.",
- params_type);
- pj.id = srs::spar::detail::proj_traits<proj_type>::id;
-
- static const bool is_non_resursive = ! std::is_same<proj_type, srs::spar::proj_ob_tran>::value;
- BOOST_GEOMETRY_STATIC_ASSERT((is_non_resursive),
- "o_proj parameter can not be set to ob_tran projection.",
- params_type);
-
-
-
-
- return pj;
- }
-
-
-
-
- template <typename T, typename Parameters>
- struct par_ob_tran
- {
- template <typename Params>
- par_ob_tran(Params const& params, Parameters const& par)
- : link(projections::detail::create_new(params, o_proj_parameters(params, par)))
- {
- if (! link.get())
- BOOST_THROW_EXCEPTION( projection_exception(error_unknown_projection_id) );
- }
- inline void fwd(T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
- link->fwd(link->params(), lp_lon, lp_lat, xy_x, xy_y);
- }
- inline void inv(T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
- link->inv(link->params(), xy_x, xy_y, lp_lon, lp_lat);
- }
- std::shared_ptr<dynamic_wrapper_b<T, Parameters> > link;
- T lamp;
- T cphip, sphip;
- };
- template <typename StaticParameters, typename T, typename Parameters>
- struct par_ob_tran_static
- {
-
- typedef typename srs::spar::detail::pick_o_proj_tag
- <
- StaticParameters
- >::type o_proj_tag;
-
- static const bool is_o_proj_not_ob_tran = ! std::is_same<o_proj_tag, srs::spar::proj_ob_tran>::value;
- BOOST_GEOMETRY_STATIC_ASSERT((is_o_proj_not_ob_tran),
- "o_proj parameter can not be set to ob_tran projection.",
- StaticParameters);
- typedef typename projections::detail::static_projection_type
- <
- o_proj_tag,
-
-
- typename projections::detail::static_srs_tag<StaticParameters>::type,
- StaticParameters,
- T,
- Parameters
- >::type projection_type;
- par_ob_tran_static(StaticParameters const& params, Parameters const& par)
- : link(params, o_proj_parameters(params, par))
- {}
- inline void fwd(T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
- link.fwd(link.params(), lp_lon, lp_lat, xy_x, xy_y);
- }
- inline void inv(T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
- link.inv(link.params(), xy_x, xy_y, lp_lon, lp_lat);
- }
- projection_type link;
- T lamp;
- T cphip, sphip;
- };
- template <typename T, typename Par>
- inline void o_forward(T lp_lon, T lp_lat, T& xy_x, T& xy_y, Par const& proj_parm)
- {
- T coslam, sinphi, cosphi;
- coslam = cos(lp_lon);
- sinphi = sin(lp_lat);
- cosphi = cos(lp_lat);
- lp_lon = adjlon(aatan2(cosphi * sin(lp_lon), proj_parm.sphip * cosphi * coslam +
- proj_parm.cphip * sinphi) + proj_parm.lamp);
- lp_lat = aasin(proj_parm.sphip * sinphi - proj_parm.cphip * cosphi * coslam);
- proj_parm.fwd(lp_lon, lp_lat, xy_x, xy_y);
- }
- template <typename T, typename Par>
- inline void o_inverse(T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat, Par const& proj_parm)
- {
- T coslam, sinphi, cosphi;
- proj_parm.inv(xy_x, xy_y, lp_lon, lp_lat);
- if (lp_lon != HUGE_VAL) {
- coslam = cos(lp_lon -= proj_parm.lamp);
- sinphi = sin(lp_lat);
- cosphi = cos(lp_lat);
- lp_lat = aasin(proj_parm.sphip * sinphi + proj_parm.cphip * cosphi * coslam);
- lp_lon = aatan2(cosphi * sin(lp_lon), proj_parm.sphip * cosphi * coslam -
- proj_parm.cphip * sinphi);
- }
- }
- template <typename T, typename Par>
- inline void t_forward(T lp_lon, T lp_lat, T& xy_x, T& xy_y, Par const& proj_parm)
- {
- T cosphi, coslam;
- cosphi = cos(lp_lat);
- coslam = cos(lp_lon);
- lp_lon = adjlon(aatan2(cosphi * sin(lp_lon), sin(lp_lat)) + proj_parm.lamp);
- lp_lat = aasin(- cosphi * coslam);
- proj_parm.fwd(lp_lon, lp_lat, xy_x, xy_y);
- }
- template <typename T, typename Par>
- inline void t_inverse(T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat, Par const& proj_parm)
- {
- T cosphi, t;
- proj_parm.inv(xy_x, xy_y, lp_lon, lp_lat);
- if (lp_lon != HUGE_VAL) {
- cosphi = cos(lp_lat);
- t = lp_lon - proj_parm.lamp;
- lp_lon = aatan2(cosphi * sin(t), - sin(lp_lat));
- lp_lat = aasin(cosphi * cos(t));
- }
- }
-
- template <typename T, typename Params, typename Parameters, typename ProjParameters>
- inline T setup_ob_tran(Params const& params, Parameters & , ProjParameters& proj_parm)
- {
- static const T half_pi = detail::half_pi<T>();
- T phip, alpha;
-
-
-
- if (pj_param_r<srs::spar::o_alpha>(params, "o_alpha", srs::dpar::o_alpha, alpha)) {
- T lamc, phic;
- lamc = pj_get_param_r<T, srs::spar::o_lon_c>(params, "o_lon_c", srs::dpar::o_lon_c);
- phic = pj_get_param_r<T, srs::spar::o_lon_c>(params, "o_lat_c", srs::dpar::o_lat_c);
-
- if (fabs(fabs(phic) - half_pi) <= tolerance)
- BOOST_THROW_EXCEPTION( projection_exception(error_lat_0_or_alpha_eq_90) );
- proj_parm.lamp = lamc + aatan2(-cos(alpha), -sin(alpha) * sin(phic));
- phip = aasin(cos(phic) * sin(alpha));
- } else if (pj_param_r<srs::spar::o_lat_p>(params, "o_lat_p", srs::dpar::o_lat_p, phip)) {
- proj_parm.lamp = pj_get_param_r<T, srs::spar::o_lon_p>(params, "o_lon_p", srs::dpar::o_lon_p);
-
- } else {
- T lam1, lam2, phi1, phi2, con;
- lam1 = pj_get_param_r<T, srs::spar::o_lon_1>(params, "o_lon_1", srs::dpar::o_lon_1);
- phi1 = pj_get_param_r<T, srs::spar::o_lat_1>(params, "o_lat_1", srs::dpar::o_lat_1);
- lam2 = pj_get_param_r<T, srs::spar::o_lon_2>(params, "o_lon_2", srs::dpar::o_lon_2);
- phi2 = pj_get_param_r<T, srs::spar::o_lat_2>(params, "o_lat_2", srs::dpar::o_lat_2);
- if (fabs(phi1 - phi2) <= tolerance || (con = fabs(phi1)) <= tolerance ||
- fabs(con - half_pi) <= tolerance || fabs(fabs(phi2) - half_pi) <= tolerance)
- BOOST_THROW_EXCEPTION( projection_exception(error_lat_1_or_2_zero_or_90) );
- proj_parm.lamp = atan2(cos(phi1) * sin(phi2) * cos(lam1) -
- sin(phi1) * cos(phi2) * cos(lam2),
- sin(phi1) * cos(phi2) * sin(lam2) -
- cos(phi1) * sin(phi2) * sin(lam1));
- phip = atan(-cos(proj_parm.lamp - lam1) / tan(phi1));
- }
- if (fabs(phip) > tolerance) {
- proj_parm.cphip = cos(phip);
- proj_parm.sphip = sin(phip);
- } else {
- }
-
-
-
-
-
-
- return phip;
- }
- template <typename T, typename Parameters>
- struct base_ob_tran_oblique
- {
- par_ob_tran<T, Parameters> m_proj_parm;
- inline base_ob_tran_oblique(par_ob_tran<T, Parameters> const& proj_parm)
- : m_proj_parm(proj_parm)
- {}
-
-
- inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
-
- o_forward(lp_lon, lp_lat, xy_x, xy_y, this->m_proj_parm);
- }
-
-
- inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
-
- o_inverse(xy_x, xy_y, lp_lon, lp_lat, this->m_proj_parm);
- }
- static inline std::string get_name()
- {
- return "ob_tran_oblique";
- }
- };
- template <typename T, typename Parameters>
- struct base_ob_tran_transverse
- {
- par_ob_tran<T, Parameters> m_proj_parm;
- inline base_ob_tran_transverse(par_ob_tran<T, Parameters> const& proj_parm)
- : m_proj_parm(proj_parm)
- {}
-
-
- inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
-
- t_forward(lp_lon, lp_lat, xy_x, xy_y, this->m_proj_parm);
- }
-
-
- inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
-
- t_inverse(xy_x, xy_y, lp_lon, lp_lat, this->m_proj_parm);
- }
- static inline std::string get_name()
- {
- return "ob_tran_transverse";
- }
- };
- template <typename StaticParameters, typename T, typename Parameters>
- struct base_ob_tran_static
- {
- par_ob_tran_static<StaticParameters, T, Parameters> m_proj_parm;
- bool m_is_oblique;
- inline base_ob_tran_static(StaticParameters const& params, Parameters const& par)
- : m_proj_parm(params, par)
- {}
-
-
- inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
-
- if (m_is_oblique) {
- o_forward(lp_lon, lp_lat, xy_x, xy_y, this->m_proj_parm);
- } else {
- t_forward(lp_lon, lp_lat, xy_x, xy_y, this->m_proj_parm);
- }
- }
-
-
- inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
-
- if (m_is_oblique) {
- o_inverse(xy_x, xy_y, lp_lon, lp_lat, this->m_proj_parm);
- } else {
- t_inverse(xy_x, xy_y, lp_lon, lp_lat, this->m_proj_parm);
- }
- }
- static inline std::string get_name()
- {
- return "ob_tran";
- }
- };
- }}
- #endif
-
- template <typename T, typename Parameters>
- struct ob_tran_oblique : public detail::ob_tran::base_ob_tran_oblique<T, Parameters>
- {
- template <typename Params>
- inline ob_tran_oblique(Params const& , Parameters const& ,
- detail::ob_tran::par_ob_tran<T, Parameters> const& proj_parm)
- : detail::ob_tran::base_ob_tran_oblique<T, Parameters>(proj_parm)
- {
-
-
- }
- };
-
- template <typename T, typename Parameters>
- struct ob_tran_transverse : public detail::ob_tran::base_ob_tran_transverse<T, Parameters>
- {
- template <typename Params>
- inline ob_tran_transverse(Params const& , Parameters const& ,
- detail::ob_tran::par_ob_tran<T, Parameters> const& proj_parm)
- : detail::ob_tran::base_ob_tran_transverse<T, Parameters>(proj_parm)
- {
-
-
- }
- };
-
- template <typename StaticParameters, typename T, typename Parameters>
- struct ob_tran_static : public detail::ob_tran::base_ob_tran_static<StaticParameters, T, Parameters>
- {
- inline ob_tran_static(StaticParameters const& params, Parameters const& par)
- : detail::ob_tran::base_ob_tran_static<StaticParameters, T, Parameters>(params, par)
- {
- T phip = detail::ob_tran::setup_ob_tran<T>(params, par, this->m_proj_parm);
- this->m_is_oblique = fabs(phip) > detail::ob_tran::tolerance;
- }
- };
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
-
- template <typename SP, typename CT, typename P>
- struct static_projection_type<srs::spar::proj_ob_tran, srs_sphere_tag, SP, CT, P>
- {
- typedef static_wrapper_fi<ob_tran_static<SP, CT, P>, P> type;
- };
- template <typename SP, typename CT, typename P>
- struct static_projection_type<srs::spar::proj_ob_tran, srs_spheroid_tag, SP, CT, P>
- {
- typedef static_wrapper_fi<ob_tran_static<SP, CT, P>, P> type;
- };
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_BEGIN(ob_tran_entry)
- {
- Parameters parameters_copy = parameters;
- detail::ob_tran::par_ob_tran<T, Parameters> proj_parm(params, parameters_copy);
- T phip = detail::ob_tran::setup_ob_tran<T>(params, parameters_copy, proj_parm);
- if (fabs(phip) > detail::ob_tran::tolerance)
- return new dynamic_wrapper_fi<ob_tran_oblique<T, Parameters>, T, Parameters>(params, parameters_copy, proj_parm);
- else
- return new dynamic_wrapper_fi<ob_tran_transverse<T, Parameters>, T, Parameters>(params, parameters_copy, proj_parm);
- }
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_END
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(ob_tran_init)
- {
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(ob_tran, ob_tran_entry)
- }
- }
- #endif
- }
- }}
- #endif
|