123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- #ifndef BOOST_GEOMETRY_PROJECTIONS_MERC_HPP
- #define BOOST_GEOMETRY_PROJECTIONS_MERC_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_msfn.hpp>
- #include <boost/geometry/srs/projections/impl/pj_param.hpp>
- #include <boost/geometry/srs/projections/impl/pj_phi2.hpp>
- #include <boost/geometry/srs/projections/impl/pj_tsfn.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 { namespace merc
- {
- static const double epsilon10 = 1.e-10;
- template <typename T, typename Parameters>
- struct base_merc_ellipsoid
- {
-
-
- inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
- static const T half_pi = detail::half_pi<T>();
- if (fabs(fabs(lp_lat) - half_pi) <= epsilon10) {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- xy_x = par.k0 * lp_lon;
- xy_y = - par.k0 * log(pj_tsfn(lp_lat, sin(lp_lat), par.e));
- }
-
-
- inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
- if ((lp_lat = pj_phi2(exp(- xy_y / par.k0), par.e)) == HUGE_VAL) {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- lp_lon = xy_x / par.k0;
- }
- static inline std::string get_name()
- {
- return "merc_ellipsoid";
- }
- };
- template <typename T, typename Parameters>
- struct base_merc_spheroid
- {
-
-
- inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
- static const T half_pi = detail::half_pi<T>();
- static const T fourth_pi = detail::fourth_pi<T>();
- if (fabs(fabs(lp_lat) - half_pi) <= epsilon10) {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- xy_x = par.k0 * lp_lon;
- xy_y = par.k0 * log(tan(fourth_pi + .5 * lp_lat));
- }
-
-
- inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
- static const T half_pi = detail::half_pi<T>();
- lp_lat = half_pi - 2. * atan(exp(-xy_y / par.k0));
- lp_lon = xy_x / par.k0;
- }
- static inline std::string get_name()
- {
- return "merc_spheroid";
- }
- };
-
- template <typename Params, typename Parameters>
- inline void setup_merc(Params const& params, Parameters& par)
- {
- typedef typename Parameters::type calc_t;
- static const calc_t half_pi = detail::half_pi<calc_t>();
- calc_t phits=0.0;
- int is_phits;
- if( (is_phits = pj_param_r<srs::spar::lat_ts>(params, "lat_ts", srs::dpar::lat_ts, phits)) ) {
- phits = fabs(phits);
- if (phits >= half_pi)
- BOOST_THROW_EXCEPTION( projection_exception(error_lat_ts_larger_than_90) );
- }
- if (par.es != 0.0) {
- if (is_phits)
- par.k0 = pj_msfn(sin(phits), cos(phits), par.es);
- } else {
- if (is_phits)
- par.k0 = cos(phits);
- }
- }
- }}
- #endif
-
- template <typename T, typename Parameters>
- struct merc_ellipsoid : public detail::merc::base_merc_ellipsoid<T, Parameters>
- {
- template <typename Params>
- inline merc_ellipsoid(Params const& params, Parameters & par)
- {
- detail::merc::setup_merc(params, par);
- }
- };
-
- template <typename T, typename Parameters>
- struct merc_spheroid : public detail::merc::base_merc_spheroid<T, Parameters>
- {
- template <typename Params>
- inline merc_spheroid(Params const& params, Parameters & par)
- {
- detail::merc::setup_merc(params, par);
- }
- };
-
- template <typename T, typename Parameters>
- struct webmerc_spheroid : public detail::merc::base_merc_spheroid<T, Parameters>
- {
- template <typename Params>
- inline webmerc_spheroid(Params const&, Parameters & par)
- {
- par.k0 = 1;
- }
- };
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI2(srs::spar::proj_merc, merc_spheroid,
- merc_ellipsoid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_webmerc,
- webmerc_spheroid)
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI2(merc_entry, merc_spheroid,
- merc_ellipsoid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(webmerc_entry, webmerc_spheroid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(merc_init)
- {
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(merc, merc_entry)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(webmerc, webmerc_entry)
- }
- }
- #endif
- }
- }}
- #endif
|