col_urban.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Boost.Geometry - gis-projections (based on PROJ4)
  2. // Copyright (c) 2022, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // This file is converted from PROJ4, http://trac.osgeo.org/proj
  8. // PROJ4 is originally written by Gerald Evenden (then of the USGS)
  9. // PROJ4 is maintained by Frank Warmerdam
  10. // PROJ4 is converted to Boost.Geometry by Barend Gehrels
  11. // Last updated version of proj: 9.0.0
  12. // Original copyright notice:
  13. // Permission is hereby granted, free of charge, to any person obtaining a
  14. // copy of this software and associated documentation files (the "Software"),
  15. // to deal in the Software without restriction, including without limitation
  16. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. // and/or sell copies of the Software, and to permit persons to whom the
  18. // Software is furnished to do so, subject to the following conditions:
  19. // The above copyright notice and this permission notice shall be included
  20. // in all copies or substantial portions of the Software.
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  22. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  24. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  26. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  27. // DEALINGS IN THE SOFTWARE.
  28. #ifndef BOOST_GEOMETRY_PROJECTIONS_COL_URBAN_HPP
  29. #define BOOST_GEOMETRY_PROJECTIONS_COL_URBAN_HPP
  30. #include <boost/geometry/util/math.hpp>
  31. #include <boost/geometry/srs/projections/impl/base_static.hpp>
  32. #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
  33. #include <boost/geometry/srs/projections/impl/pj_param.hpp>
  34. #include <boost/geometry/srs/projections/impl/projects.hpp>
  35. #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
  36. namespace boost { namespace geometry
  37. {
  38. namespace projections
  39. {
  40. #ifndef DOXYGEN_NO_DETAIL
  41. namespace detail { namespace col_urban
  42. {
  43. template <typename T>
  44. struct par_col_urban
  45. {
  46. T h0; // height of projection origin, divided by semi-major axis (a)
  47. T rho0; // adimensional value, contrary to Guidance note 7.2
  48. T A;
  49. T B; // adimensional value, contrary to Guidance note 7.2
  50. T C;
  51. T D; // adimensional value, contrary to Guidance note 7.2
  52. };
  53. template <typename T, typename Parameters>
  54. struct base_col_urban_spheroid
  55. {
  56. par_col_urban<T> m_proj_parm;
  57. // FORWARD(s_forward) spheroid
  58. // Project coordinates from geographic (lon, lat) to cartesian (x, y)
  59. inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
  60. {
  61. const T cosphi = cos(lp_lat);
  62. const T sinphi = sin(lp_lat);
  63. const T nu = 1. / sqrt(1 - par.es * sinphi * sinphi);
  64. const T lam_nu_cosphi = lp_lon * nu * cosphi;
  65. xy_x = this->m_proj_parm.A * lam_nu_cosphi;
  66. const T sinphi_m = sin(0.5 * (lp_lat + par.phi0));
  67. const T rho_m = (1 - par.es) / pow(1 - par.es * sinphi_m * sinphi_m, 1.5);
  68. const T G = 1 + this->m_proj_parm.h0 / rho_m;
  69. xy_y = G * this->m_proj_parm.rho0 * ((lp_lat - par.phi0) + this->m_proj_parm.B * lam_nu_cosphi * lam_nu_cosphi);
  70. }
  71. // INVERSE(s_inverse) spheroid
  72. // Project coordinates from cartesian (x, y) to geographic (lon, lat)
  73. inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
  74. {
  75. lp_lat = par.phi0 + xy_y / this->m_proj_parm.D - this->m_proj_parm.B * (xy_x / this->m_proj_parm.C) * (xy_x / this->m_proj_parm.C);
  76. const double sinphi = sin(lp_lat);
  77. const double nu = 1. / sqrt(1 - par.es * sinphi * sinphi);
  78. lp_lon = xy_x / (this->m_proj_parm.C * nu * cos(lp_lat));
  79. }
  80. static inline std::string get_name()
  81. {
  82. return "col_urban_spheroid";
  83. }
  84. };
  85. // Colombia Urban
  86. template <typename Params, typename Parameters, typename T>
  87. inline void setup(Params const& params, Parameters const& par, par_col_urban<T>& proj_parm)
  88. {
  89. T h0_unscaled;
  90. if ( !pj_param_f<srs::spar::h_0>(params, "h_0", srs::dpar::h_0, h0_unscaled) ){
  91. h0_unscaled = T(0);
  92. }
  93. proj_parm.h0 = h0_unscaled / par.a;
  94. const T sinphi0 = sin(par.phi0);
  95. const T nu0 = 1. / sqrt(1 - par.es * sinphi0 * sinphi0);
  96. proj_parm.A = 1 + proj_parm.h0 / nu0;
  97. proj_parm.rho0 = (1 - par.es) / pow(1 - par.es * sinphi0 * sinphi0, 1.5);
  98. proj_parm.B = tan(par.phi0) / (2 * proj_parm.rho0 * nu0);
  99. proj_parm.C = 1 + proj_parm.h0;
  100. proj_parm.D = proj_parm.rho0 * (1 + proj_parm.h0 / (1 - par.es));
  101. }
  102. }} // namespace col_urban
  103. #endif // doxygen
  104. /*!
  105. \brief Colombia Urban
  106. \ingroup projections
  107. \tparam Geographic latlong point type
  108. \tparam Cartesian xy point type
  109. \tparam Parameters parameter type
  110. */
  111. template <typename T, typename Parameters>
  112. struct col_urban_spheroid : public detail::col_urban::base_col_urban_spheroid<T, Parameters>
  113. {
  114. template <typename Params>
  115. inline col_urban_spheroid(Params const& params, Parameters & par)
  116. {
  117. detail::col_urban::setup(params, par, this->m_proj_parm);
  118. }
  119. };
  120. #ifndef DOXYGEN_NO_DETAIL
  121. namespace detail
  122. {
  123. // Static projection
  124. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_col_urban, col_urban_spheroid)
  125. // Factory entry(s)
  126. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(col_urban_entry, col_urban_spheroid)
  127. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(col_urban_init)
  128. {
  129. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(col_urban, col_urban_entry);
  130. }
  131. } // namespace detail
  132. #endif // doxygen
  133. } // namespace projections
  134. }} // namespace boost::geometry
  135. #endif // BOOST_GEOMETRY_PROJECTIONS_COL_URBAN_HPP