lcca.hpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // Boost.Geometry - gis-projections (based on PROJ4)
  2. // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2017, 2018, 2019.
  4. // Modifications copyright (c) 2017-2019, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. // This file is converted from PROJ4, http://trac.osgeo.org/proj
  10. // PROJ4 is originally written by Gerald Evenden (then of the USGS)
  11. // PROJ4 is maintained by Frank Warmerdam
  12. // PROJ4 is converted to Boost.Geometry by Barend Gehrels
  13. // Last updated version of proj: 5.0.0
  14. // Original copyright notice:
  15. // Permission is hereby granted, free of charge, to any person obtaining a
  16. // copy of this software and associated documentation files (the "Software"),
  17. // to deal in the Software without restriction, including without limitation
  18. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  19. // and/or sell copies of the Software, and to permit persons to whom the
  20. // Software is furnished to do so, subject to the following conditions:
  21. // The above copyright notice and this permission notice shall be included
  22. // in all copies or substantial portions of the Software.
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  24. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  26. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  28. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  29. // DEALINGS IN THE SOFTWARE.
  30. /*****************************************************************************
  31. Lambert Conformal Conic Alternative
  32. -----------------------------------
  33. This is Gerald Evenden's 2003 implementation of an alternative
  34. "almost" LCC, which has been in use historically, but which
  35. should NOT be used for new projects - i.e: use this implementation
  36. if you need interoperability with old data represented in this
  37. projection, but not in any other case.
  38. The code was originally discussed on the PROJ.4 mailing list in
  39. a thread archived over at
  40. http://lists.maptools.org/pipermail/proj/2003-March/000644.html
  41. It was discussed again in the thread starting at
  42. http://lists.maptools.org/pipermail/proj/2017-October/007828.html
  43. and continuing at
  44. http://lists.maptools.org/pipermail/proj/2017-November/007831.html
  45. which prompted Clifford J. Mugnier to add these clarifying notes:
  46. The French Army Truncated Cubic Lambert (partially conformal) Conic
  47. projection is the Legal system for the projection in France between
  48. the late 1800s and 1948 when the French Legislature changed the law
  49. to recognize the fully conformal version.
  50. It was (might still be in one or two North African prior French
  51. Colonies) used in North Africa in Algeria, Tunisia, & Morocco, as
  52. well as in Syria during the Levant.
  53. Last time I have seen it used was about 30+ years ago in
  54. Algeria when it was used to define Lease Block boundaries for
  55. Petroleum Exploration & Production.
  56. (signed)
  57. Clifford J. Mugnier, c.p., c.m.s.
  58. Chief of Geodesy
  59. LSU Center for GeoInformatics
  60. Dept. of Civil Engineering
  61. LOUISIANA STATE UNIVERSITY
  62. *****************************************************************************/
  63. #ifndef BOOST_GEOMETRY_PROJECTIONS_LCCA_HPP
  64. #define BOOST_GEOMETRY_PROJECTIONS_LCCA_HPP
  65. #include <boost/geometry/srs/projections/impl/base_static.hpp>
  66. #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
  67. #include <boost/geometry/srs/projections/impl/projects.hpp>
  68. #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
  69. #include <boost/geometry/srs/projections/impl/pj_mlfn.hpp>
  70. namespace boost { namespace geometry
  71. {
  72. namespace projections
  73. {
  74. #ifndef DOXYGEN_NO_DETAIL
  75. namespace detail { namespace lcca
  76. {
  77. static const int max_iter = 10;
  78. static const double del_tol = 1e-12;
  79. template <typename T>
  80. struct par_lcca
  81. {
  82. detail::en<T> en;
  83. T r0, l, M0;
  84. T C;
  85. };
  86. template <typename T> /* func to compute dr */
  87. inline T fS(T const& S, T const& C)
  88. {
  89. return(S * ( 1. + S * S * C));
  90. }
  91. template <typename T> /* deriv of fs */
  92. inline T fSp(T const& S, T const& C)
  93. {
  94. return(1. + 3.* S * S * C);
  95. }
  96. template <typename T, typename Parameters>
  97. struct base_lcca_ellipsoid
  98. {
  99. par_lcca<T> m_proj_parm;
  100. // FORWARD(e_forward) ellipsoid
  101. // Project coordinates from geographic (lon, lat) to cartesian (x, y)
  102. inline void fwd(Parameters const& par, T lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
  103. {
  104. T S, r, dr;
  105. S = pj_mlfn(lp_lat, sin(lp_lat), cos(lp_lat), this->m_proj_parm.en) - this->m_proj_parm.M0;
  106. dr = fS(S, this->m_proj_parm.C);
  107. r = this->m_proj_parm.r0 - dr;
  108. xy_x = par.k0 * (r * sin( lp_lon *= this->m_proj_parm.l ) );
  109. xy_y = par.k0 * (this->m_proj_parm.r0 - r * cos(lp_lon) );
  110. }
  111. // INVERSE(e_inverse) ellipsoid & spheroid
  112. // Project coordinates from cartesian (x, y) to geographic (lon, lat)
  113. inline void inv(Parameters const& par, T xy_x, T xy_y, T& lp_lon, T& lp_lat) const
  114. {
  115. T theta, dr, S, dif;
  116. int i;
  117. xy_x /= par.k0;
  118. xy_y /= par.k0;
  119. theta = atan2(xy_x , this->m_proj_parm.r0 - xy_y);
  120. dr = xy_y - xy_x * tan(0.5 * theta);
  121. lp_lon = theta / this->m_proj_parm.l;
  122. S = dr;
  123. for (i = max_iter; i ; --i) {
  124. S -= (dif = (fS(S, this->m_proj_parm.C) - dr) / fSp(S, this->m_proj_parm.C));
  125. if (fabs(dif) < del_tol) break;
  126. }
  127. if (!i) {
  128. BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
  129. }
  130. lp_lat = pj_inv_mlfn(S + this->m_proj_parm.M0, par.es, this->m_proj_parm.en);
  131. }
  132. static inline std::string get_name()
  133. {
  134. return "lcca_ellipsoid";
  135. }
  136. };
  137. // Lambert Conformal Conic Alternative
  138. template <typename Parameters, typename T>
  139. inline void setup_lcca(Parameters const& par, par_lcca<T>& proj_parm)
  140. {
  141. T s2p0, N0, R0, tan0;
  142. proj_parm.en = pj_enfn<T>(par.es);
  143. if (par.phi0 == 0.) {
  144. BOOST_THROW_EXCEPTION( projection_exception(error_lat_0_is_zero) );
  145. }
  146. proj_parm.l = sin(par.phi0);
  147. proj_parm.M0 = pj_mlfn(par.phi0, proj_parm.l, cos(par.phi0), proj_parm.en);
  148. s2p0 = proj_parm.l * proj_parm.l;
  149. R0 = 1. / (1. - par.es * s2p0);
  150. N0 = sqrt(R0);
  151. R0 *= par.one_es * N0;
  152. tan0 = tan(par.phi0);
  153. proj_parm.r0 = N0 / tan0;
  154. proj_parm.C = 1. / (6. * R0 * N0);
  155. }
  156. }} // namespace detail::lcca
  157. #endif // doxygen
  158. /*!
  159. \brief Lambert Conformal Conic Alternative projection
  160. \ingroup projections
  161. \tparam Geographic latlong point type
  162. \tparam Cartesian xy point type
  163. \tparam Parameters parameter type
  164. \par Projection characteristics
  165. - Conic
  166. - Spheroid
  167. - Ellipsoid
  168. \par Projection parameters
  169. - lat_0: Latitude of origin
  170. \par Example
  171. \image html ex_lcca.gif
  172. */
  173. template <typename T, typename Parameters>
  174. struct lcca_ellipsoid : public detail::lcca::base_lcca_ellipsoid<T, Parameters>
  175. {
  176. template <typename Params>
  177. inline lcca_ellipsoid(Params const& , Parameters const& par)
  178. {
  179. detail::lcca::setup_lcca(par, this->m_proj_parm);
  180. }
  181. };
  182. #ifndef DOXYGEN_NO_DETAIL
  183. namespace detail
  184. {
  185. // Static projection
  186. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_lcca, lcca_ellipsoid)
  187. // Factory entry(s)
  188. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(lcca_entry, lcca_ellipsoid)
  189. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(lcca_init)
  190. {
  191. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(lcca, lcca_entry)
  192. }
  193. } // namespace detail
  194. #endif // doxygen
  195. } // namespace projections
  196. }} // namespace boost::geometry
  197. #endif // BOOST_GEOMETRY_PROJECTIONS_LCCA_HPP