Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:39

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 // This file is manually converted from PROJ4
0003 
0004 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
0005 
0006 // This file was modified by Oracle on 2017-2020.
0007 // Modifications copyright (c) 2017-2020, Oracle and/or its affiliates.
0008 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0009 
0010 // Use, modification and distribution is subject to the Boost Software License,
0011 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0012 // http://www.boost.org/LICENSE_1_0.txt)
0013 
0014 // This file is converted from PROJ4, http://trac.osgeo.org/proj
0015 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
0016 // PROJ4 is maintained by Frank Warmerdam
0017 // PROJ4 is converted to Geometry Library by Barend Gehrels (Geodan, Amsterdam)
0018 
0019 // Original copyright notice:
0020 
0021 // Permission is hereby granted, free of charge, to any person obtaining a
0022 // copy of this software and associated documentation files (the "Software"),
0023 // to deal in the Software without restriction, including without limitation
0024 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
0025 // and/or sell copies of the Software, and to permit persons to whom the
0026 // Software is furnished to do so, subject to the following conditions:
0027 
0028 // The above copyright notice and this permission notice shall be included
0029 // in all copies or substantial portions of the Software.
0030 
0031 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0032 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0033 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0034 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0035 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0036 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0037 // DEALINGS IN THE SOFTWARE.
0038 
0039 #ifndef BOOST_GEOMETRY_PROJECTIONS_PJ_PARAM_HPP
0040 #define BOOST_GEOMETRY_PROJECTIONS_PJ_PARAM_HPP
0041 
0042 
0043 #include <iterator>
0044 #include <string>
0045 #include <type_traits>
0046 #include <vector>
0047 
0048 #include <boost/geometry/core/static_assert.hpp>
0049 
0050 #include <boost/geometry/srs/projections/exception.hpp>
0051 
0052 #include <boost/geometry/srs/projections/impl/dms_parser.hpp>
0053 #include <boost/geometry/srs/projections/impl/projects.hpp>
0054 #include <boost/geometry/srs/projections/proj4.hpp>
0055 #include <boost/geometry/srs/projections/dpar.hpp>
0056 #include <boost/geometry/srs/projections/spar.hpp>
0057 
0058 
0059 namespace boost { namespace geometry { namespace projections {
0060 
0061 
0062 namespace detail {
0063 
0064 inline bool pj_param_pred(srs::detail::proj4_parameter const& p, std::string const& name)
0065 {
0066     return p.name == name;
0067 }
0068 
0069 template
0070 <
0071     typename T, typename Id,
0072     std::enable_if_t<! std::is_convertible<Id, std::string>::value, int> = 0
0073 >
0074 inline bool pj_param_pred(srs::dpar::parameter<T> const& p, Id const& id)
0075 {
0076     return p.is_id_equal(id);
0077 }
0078 
0079 /* input exists */
0080 template <typename Params, typename Name>
0081 inline typename Params::const_iterator
0082     pj_param_find(Params const& params, Name const& name)
0083 {
0084     typedef typename Params::const_iterator iterator;
0085     for (iterator it = params.begin(); it != params.end(); it++)
0086     {
0087         if (pj_param_pred(*it, name))
0088         {
0089             //it->used = true;
0090             return it;
0091         }
0092         // TODO: needed for pipeline
0093         /*else if (it->name == "step")
0094         {
0095             return pl.end();
0096         }*/
0097     }
0098 
0099     return params.end();
0100 }
0101 
0102 /*
0103 template
0104 <
0105     typename StaticParams,
0106     typename IsParamPred,
0107     int I = tuples_find_index_if<StaticParams, typename IsParamPred::pred>::value,
0108     int N = geometry::tuples::size<StaticParams>::value
0109 >
0110 struct pj_param_find_static
0111 {
0112     typedef geometry::tuples::element<I, StaticParams> type;
0113     typedef const type* result_type;
0114     static result_type get(StaticParams const& params)
0115     {
0116         return boost::addressof(boost::get<I>(params));
0117     }
0118 };
0119 
0120 template <typename StaticParams, typename IsParamPred, int N>
0121 struct pj_param_find_static<StaticParams, IsParamPred, N>
0122 {
0123     typedef void type;
0124     typedef const type* result_type;
0125     static result_type get(StaticParams const& ) { return NULL; }
0126 };*/
0127 
0128 
0129 /* input exists */
0130 template <typename Params, typename Name>
0131 inline bool pj_param_exists(Params const& params, Name const& name)
0132 {
0133     return pj_param_find(params, name) != params.end();
0134 }
0135 
0136 template <typename Param, typename ...Ps>
0137 inline bool pj_param_exists(srs::spar::parameters<Ps...> const& )
0138 {
0139     return geometry::tuples::is_found
0140         <
0141             typename geometry::tuples::find_if
0142                 <
0143                     srs::spar::parameters<Ps...>,
0144                     srs::spar::detail::is_param<Param>::template pred
0145                 >::type
0146         >::value;
0147 }
0148 
0149 template <template <typename> class Param, typename ...Ps>
0150 inline bool pj_param_exists(srs::spar::parameters<Ps...> const& )
0151 {
0152     return geometry::tuples::is_found
0153         <
0154             typename geometry::tuples::find_if
0155                 <
0156                     srs::spar::parameters<Ps...>,
0157                     srs::spar::detail::is_param_t<Param>::template pred
0158                 >::type
0159         >::value;
0160 }
0161 
0162 
0163 template <typename T>
0164 inline void set_value(T & val, srs::detail::proj4_parameter const& p)
0165 {
0166     val = geometry::str_cast<T>(p.value);
0167 }
0168 
0169 template <typename T, typename T2>
0170 inline void set_value(T & val, srs::dpar::parameter<T2> const& p)
0171 {
0172     val = p.template get_value<T>();
0173 }
0174 
0175 template <typename T>
0176 inline void set_value_r(T & val, srs::detail::proj4_parameter const& p)
0177 {
0178     val = dms_parser<T, true>::apply(p.value.c_str()).angle();
0179 }
0180 
0181 template <typename T>
0182 inline void set_value_r(T & val, srs::dpar::parameter<T> const& p)
0183 {
0184     val = p.template get_value<T>() * math::d2r<T>();
0185 }
0186 
0187 template <typename Name>
0188 inline void check_name(Name const&)
0189 {
0190     static const bool is_ok = std::is_convertible<Name, std::string>::value
0191                            || std::is_same<Name, srs::dpar::name_i>::value
0192                            || std::is_same<Name, srs::dpar::name_f>::value
0193                            || std::is_same<Name, srs::dpar::name_r>::value;
0194     BOOST_GEOMETRY_STATIC_ASSERT((is_ok), "Invalid argument.", Name);
0195 }
0196 
0197 
0198 /* integer input */
0199 template <typename Params, typename Name>
0200 inline bool _pj_param_i(Params const& params, Name const& name, int & par)
0201 {
0202     check_name(name);
0203     typename Params::const_iterator it = pj_param_find(params, name);
0204     if (it != params.end())
0205     {
0206         set_value(par, *it);
0207         return true;
0208     }
0209     return false;
0210 }
0211 
0212 /* floating point input */
0213 template <typename T, typename Params, typename Name>
0214 inline bool _pj_param_f(Params const& params, Name const& name, T & par)
0215 {
0216     check_name(name);
0217     typename Params::const_iterator it = pj_param_find(params, name);
0218     if (it != params.end())
0219     {
0220         set_value(par, *it);
0221         return true;
0222     }
0223     return false;
0224 }
0225 
0226 /* radians input */
0227 template <typename T, typename Params, typename Name>
0228 inline bool _pj_param_r(Params const& params, Name const& name, T & par)
0229 {
0230     check_name(name);
0231     typename Params::const_iterator it = pj_param_find(params, name);
0232     if (it != params.end())
0233     {
0234         set_value_r(par, *it);
0235         return true;
0236     }
0237     return false;
0238 }
0239 
0240 /* bool input */
0241 inline bool _pj_get_param_b(srs::detail::proj4_parameters const& pl, std::string const& name)
0242 {
0243     srs::detail::proj4_parameters::const_iterator it = pj_param_find(pl, name);
0244     if (it != pl.end())
0245     {
0246         switch (it->value[0])
0247         {
0248         case '\0': case 'T': case 't':
0249             return true;
0250         case 'F': case 'f':
0251             return false;
0252         default:
0253             BOOST_THROW_EXCEPTION( projection_exception(error_invalid_boolean_param) );
0254             return false;
0255         }
0256     }
0257     return false;
0258 }
0259 
0260 template <typename T>
0261 inline bool _pj_get_param_b(srs::dpar::parameters<T> const& pl, srs::dpar::name_be const& name)
0262 {
0263     bool result = false;
0264     typename srs::dpar::parameters<T>::const_iterator it = pj_param_find(pl, name);
0265     if (it != pl.end())
0266         set_value(result, *it);
0267     return result;
0268 }
0269 
0270 /* string input */
0271 inline bool pj_param_s(srs::detail::proj4_parameters const& pl, std::string const& name, std::string & par)
0272 {
0273     srs::detail::proj4_parameters::const_iterator it = pj_param_find(pl, name);
0274     if (it != pl.end())
0275     {
0276         par = it->value;
0277         return true;
0278     }
0279     return false;
0280 }
0281 
0282 template
0283 <
0284     typename Params,
0285     template <typename> class IsSamePred,
0286     int I = geometry::tuples::find_index_if<Params, IsSamePred>::value,
0287     int N = geometry::tuples::size<Params>::value
0288 >
0289 struct _pj_param_x_static
0290 {
0291     static const bool result = true;
0292     template <typename T>
0293     static void apply(Params const& params, T & out)
0294     {
0295         // TODO: int values could be extracted directly from the type
0296         out = geometry::tuples::get<I>(params).value;
0297     }
0298 };
0299 
0300 template
0301 <
0302     typename Params,
0303     template <typename> class IsSamePred,
0304     int N
0305 >
0306 struct _pj_param_x_static<Params, IsSamePred, N, N>
0307 {
0308     static const bool result = false;
0309     template <typename T>
0310     static void apply(Params const& , T & )
0311     {}
0312 };
0313 
0314 template <template <int> class Param, typename ...Ps>
0315 inline bool _pj_param_i(srs::spar::parameters<Ps...> const& params, int & par)
0316 {
0317     typedef _pj_param_x_static
0318         <
0319             srs::spar::parameters<Ps...>,
0320             srs::spar::detail::is_param_i<Param>::template pred
0321         > impl;
0322     impl::apply(params, par);
0323     return impl::result;
0324 }
0325 
0326 template <template <typename> class Param, typename ...Ps, typename T>
0327 inline bool _pj_param_f(srs::spar::parameters<Ps...> const& params, T & par)
0328 {
0329     typedef _pj_param_x_static
0330         <
0331             srs::spar::parameters<Ps...>,
0332             srs::spar::detail::is_param_t<Param>::template pred
0333         > impl;
0334     impl::apply(params, par);
0335     return impl::result;
0336 }
0337 
0338 template <template <typename> class Param, typename ...Ps, typename T>
0339 inline bool _pj_param_r(srs::spar::parameters<Ps...> const& params, T & par)
0340 {
0341     typedef _pj_param_x_static
0342         <
0343             srs::spar::parameters<Ps...>,
0344             srs::spar::detail::is_param_t<Param>::template pred
0345         > impl;
0346     impl::apply(params, par);
0347     if (impl::result)
0348         par *= math::d2r<T>();
0349     return impl::result;
0350 }
0351 
0352 template <typename Param, typename ...Ps>
0353 inline bool _pj_get_param_b(srs::spar::parameters<Ps...> const& params)
0354 {
0355     return pj_param_exists<Param>(params);
0356 }
0357 
0358 //template <typename T, typename Name, typename Value>
0359 //inline bool pj_param_id(srs::dpar::parameters<T> const& pl, Name const& name, Value & par)
0360 //{
0361 //    typename srs::dpar::parameters<T>::const_iterator it = pj_param_find(pl, name);
0362 //    if (it != pl.end())
0363 //    {
0364 //        par = static_cast<Value>(it->template get_value<int>());
0365 //        return true;
0366 //    }
0367 //    return false;
0368 //}
0369 
0370 // NOTE: In the original code, in pl_ell_set.c there is a function pj_get_param
0371 // which behavior is similar to pj_param but it doesn't set `user` member to TRUE
0372 // while pj_param does in the original code. In Boost.Geometry this member is not used.
0373 template <typename Params, typename Name>
0374 inline int _pj_get_param_i(Params const& pl, Name const& name)
0375 {
0376     int res = 0;
0377     _pj_param_i(pl, name, res);
0378     return res;
0379 }
0380 
0381 template <template <int> class Param, typename Params>
0382 inline int _pj_get_param_i(Params const& pl)
0383 {
0384     int res = 0;
0385     _pj_param_i<Param>(pl, res);
0386     return res;
0387 }
0388 
0389 template <typename T, typename Params, typename Name>
0390 inline T _pj_get_param_f(Params const& pl, Name const& name)
0391 {
0392     T res = 0;
0393     _pj_param_f(pl, name, res);
0394     return res;
0395 }
0396 
0397 template <typename T, template <typename> class Param, typename Params>
0398 inline T _pj_get_param_f(Params const& pl)
0399 {
0400     T res = 0;
0401     _pj_param_f<Param>(pl, res);
0402     return res;
0403 }
0404 
0405 template <typename T, typename Params, typename Name>
0406 inline T _pj_get_param_r(Params const& pl, Name const& name)
0407 {
0408     T res = 0;
0409     _pj_param_r(pl, name, res);
0410     return res;
0411 }
0412 
0413 template <typename T, template <typename> class Param, typename Params>
0414 inline T _pj_get_param_r(Params const& pl)
0415 {
0416     T res = 0;
0417     _pj_param_r<Param>(pl, res);
0418     return res;
0419 }
0420 
0421 inline std::string pj_get_param_s(srs::detail::proj4_parameters const& pl, std::string const& name)
0422 {
0423     std::string res;
0424     pj_param_s(pl, name, res);
0425     return res;
0426 }
0427 
0428 
0429 // ------------------------------------------------------------------------- //
0430 
0431 template <typename Param, typename Name>
0432 inline bool pj_param_exists(srs::detail::proj4_parameters const& pl,
0433                             std::string const& sn,
0434                             Name const& )
0435 {
0436     return pj_param_exists(pl, sn);
0437 }
0438 template <template <typename> class Param, typename Name>
0439 inline bool pj_param_exists(srs::detail::proj4_parameters const& pl,
0440                             std::string const& sn,
0441                             Name const& )
0442 {
0443     return pj_param_exists(pl, sn);
0444 }
0445 template <typename Param, typename T, typename Name>
0446 inline bool pj_param_exists(srs::dpar::parameters<T> const& pl,
0447                             std::string const& ,
0448                             Name const& n)
0449 {
0450     return pj_param_exists(pl, n);
0451 }
0452 template <template <typename> class Param, typename T, typename Name>
0453 inline bool pj_param_exists(srs::dpar::parameters<T> const& pl,
0454                             std::string const& ,
0455                             Name const& n)
0456 {
0457     return pj_param_exists(pl, n);
0458 }
0459 template <typename Param, typename ...Ps, typename Name>
0460 inline bool pj_param_exists(srs::spar::parameters<Ps...> const& pl,
0461                             std::string const& ,
0462                             Name const& )
0463 {
0464     return pj_param_exists<Param>(pl);
0465 }
0466 template <template <typename> class Param, typename ...Ps, typename Name>
0467 inline bool pj_param_exists(srs::spar::parameters<Ps...> const& pl,
0468                             std::string const& ,
0469                             Name const& )
0470 {
0471     return pj_param_exists<Param>(pl);
0472 }
0473 
0474 template <typename Param>
0475 inline bool pj_get_param_b(srs::detail::proj4_parameters const& pl,
0476                            std::string const& sn,
0477                            srs::dpar::name_be const& )
0478 {
0479     return _pj_get_param_b(pl, sn);
0480 }
0481 template <typename Param, typename T>
0482 inline bool pj_get_param_b(srs::dpar::parameters<T> const& pl,
0483                            std::string const& ,
0484                            srs::dpar::name_be const& n)
0485 {
0486     return _pj_get_param_b(pl, n);
0487 }
0488 template <typename Param, typename ...Ps>
0489 inline bool pj_get_param_b(srs::spar::parameters<Ps...> const& pl,
0490                            std::string const& ,
0491                            srs::dpar::name_be const& )
0492 {
0493     return _pj_get_param_b<Param>(pl);
0494 }
0495 
0496 //#define BOOST_GEOMETRY_GET_PARAM_B(PARAMS, NAME) pj_get_param_b(PARAMS, #NAME, srs::dpar::NAME)
0497 
0498 template <template <int> class Param>
0499 inline bool pj_param_i(srs::detail::proj4_parameters const& pl,
0500                        std::string const& sn,
0501                        srs::dpar::name_i const& ,
0502                        int & par)
0503 {
0504     return _pj_param_i(pl, sn, par);
0505 }
0506 template <template <int> class Param, typename T>
0507 inline bool pj_param_i(srs::dpar::parameters<T> const& pl,
0508                        std::string const& ,
0509                        srs::dpar::name_i const& n,
0510                        int & par)
0511 {
0512     return _pj_param_i(pl, n, par);
0513 }
0514 template <template <int> class Param, typename ...Ps>
0515 inline bool pj_param_i(srs::spar::parameters<Ps...> const& pl,
0516                        std::string const& ,
0517                        srs::dpar::name_i const& ,
0518                        int & par)
0519 {
0520     return _pj_param_i<Param>(pl, par);
0521 }
0522 
0523 //#define BOOST_GEOMETRY_PARAM_I(PARAMS, NAME, PAR) pj_param_i(PARAMS, #NAME, srs::dpar::NAME, PAR)
0524 
0525 template <template <int> class Param>
0526 inline int pj_get_param_i(srs::detail::proj4_parameters const& pl,
0527                           std::string const& sn,
0528                           srs::dpar::name_i const& )
0529 {
0530     return _pj_get_param_i(pl, sn);
0531 }
0532 template <template <int> class Param, typename T>
0533 inline int pj_get_param_i(srs::dpar::parameters<T> const& pl,
0534                           std::string const& ,
0535                           srs::dpar::name_i const& n)
0536 {
0537     return _pj_get_param_i(pl, n);
0538 }
0539 template <template <int> class Param, typename ...Ps>
0540 inline bool pj_get_param_i(srs::spar::parameters<Ps...> const& pl,
0541                            std::string const& ,
0542                            srs::dpar::name_i const& )
0543 {
0544     return _pj_get_param_i<Param>(pl);
0545 }
0546 
0547 //#define BOOST_GEOMETRY_GET_PARAM_I(PARAMS, NAME) pj_get_param_i(PARAMS, #NAME, srs::dpar::NAME)
0548 
0549 template <template <typename> class Param, typename T>
0550 inline bool pj_param_f(srs::detail::proj4_parameters const& pl,
0551                        std::string const& sn,
0552                        srs::dpar::name_f const& ,
0553                        T & par)
0554 {
0555     return _pj_param_f(pl, sn, par);
0556 }
0557 template <template <typename> class Param, typename T>
0558 inline bool pj_param_f(srs::dpar::parameters<T> const& pl,
0559                        std::string const& ,
0560                        srs::dpar::name_f const& n,
0561                        T & par)
0562 {
0563     return _pj_param_f(pl, n, par);
0564 }
0565 template <template <typename> class Param, typename ...Ps, typename T>
0566 inline bool pj_param_f(srs::spar::parameters<Ps...> const& pl,
0567                        std::string const& ,
0568                        srs::dpar::name_f const& ,
0569                        T & par)
0570 {
0571     return _pj_param_f<Param>(pl, par);
0572 }
0573 
0574 //#define BOOST_GEOMETRY_PARAM_F(PARAMS, NAME, PAR) pj_param_f(PARAMS, #NAME, srs::dpar::NAME, PAR)
0575 
0576 template <typename T, template <typename> class Param>
0577 inline T pj_get_param_f(srs::detail::proj4_parameters const& pl,
0578                         std::string const& sn,
0579                         srs::dpar::name_f const& )
0580 {
0581     return _pj_get_param_f<T>(pl, sn);
0582 }
0583 template <typename T, template <typename> class Param>
0584 inline T pj_get_param_f(srs::dpar::parameters<T> const& pl,
0585                         std::string const& ,
0586                         srs::dpar::name_f const& n)
0587 {
0588     return _pj_get_param_f<T>(pl, n);
0589 }
0590 template <typename T, template <typename> class Param, typename ...Ps>
0591 inline T pj_get_param_f(srs::spar::parameters<Ps...> const& pl,
0592                         std::string const& ,
0593                         srs::dpar::name_f const& )
0594 {
0595     return _pj_get_param_f<T, Param>(pl);
0596 }
0597 
0598 
0599 //#define BOOST_GEOMETRY_GET_PARAM_F(PARAMS, NAME) pj_get_param_f<T>(PARAMS, #NAME, srs::dpar::NAME)
0600 
0601 template <template <typename> class Param, typename T>
0602 inline bool pj_param_r(srs::detail::proj4_parameters const& pl,
0603                        std::string const& sn,
0604                        srs::dpar::name_r const& ,
0605                        T & par)
0606 {
0607     return _pj_param_r(pl, sn, par);
0608 }
0609 template <template <typename> class Param, typename T>
0610 inline bool pj_param_r(srs::dpar::parameters<T> const& pl,
0611                        std::string const& ,
0612                        srs::dpar::name_r const& n,
0613                        T & par)
0614 {
0615     return _pj_param_r(pl, n, par);
0616 }
0617 template <template <typename> class Param, typename ...Ps, typename T>
0618 inline bool pj_param_r(srs::spar::parameters<Ps...> const& pl,
0619                        std::string const& ,
0620                        srs::dpar::name_r const& ,
0621                        T & par)
0622 {
0623     return _pj_param_r<Param>(pl, par);
0624 }
0625 
0626 //#define BOOST_GEOMETRY_PARAM_R(PARAMS, NAME, PAR) pj_param_r(PARAMS, #NAME, srs::dpar::NAME, PAR)
0627 
0628 template <typename T, template <typename> class Param>
0629 inline T pj_get_param_r(srs::detail::proj4_parameters const& pl,
0630                         std::string const& sn,
0631                         srs::dpar::name_r const& )
0632 {
0633     return _pj_get_param_r<T>(pl, sn);
0634 }
0635 template <typename T, template <typename> class Param>
0636 inline T pj_get_param_r(srs::dpar::parameters<T> const& pl,
0637                         std::string const& ,
0638                         srs::dpar::name_r const& n)
0639 {
0640     return _pj_get_param_r<T>(pl, n);
0641 }
0642 template <typename T, template <typename> class Param, typename ...Ps>
0643 inline T pj_get_param_r(srs::spar::parameters<Ps...> const& pl,
0644                         std::string const& ,
0645                         srs::dpar::name_r const& )
0646 {
0647     return _pj_get_param_r<T, Param>(pl);
0648 }
0649 
0650 //#define BOOST_GEOMETRY_GET_PARAM_R(PARAMS, NAME) pj_get_param_r<T>(PARAMS, #NAME, srs::dpar::NAME)
0651 
0652 } // namespace detail
0653 }}} // namespace boost::geometry::projections
0654 
0655 #endif