latlong.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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.
  4. // Modifications copyright (c) 2017-2018, 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. // Purpose: Stub projection implementation for lat/long coordinates. We
  16. // don't actually change the coordinates, but we want proj=latlong
  17. // to act sort of like a projection.
  18. // Author: Frank Warmerdam, warmerdam@pobox.com
  19. // Copyright (c) 2000, Frank Warmerdam
  20. // Permission is hereby granted, free of charge, to any person obtaining a
  21. // copy of this software and associated documentation files (the "Software"),
  22. // to deal in the Software without restriction, including without limitation
  23. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  24. // and/or sell copies of the Software, and to permit persons to whom the
  25. // Software is furnished to do so, subject to the following conditions:
  26. // The above copyright notice and this permission notice shall be included
  27. // in all copies or substantial portions of the Software.
  28. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  29. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  30. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  31. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  32. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  33. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  34. // DEALINGS IN THE SOFTWARE.
  35. #ifndef BOOST_GEOMETRY_PROJECTIONS_LATLONG_HPP
  36. #define BOOST_GEOMETRY_PROJECTIONS_LATLONG_HPP
  37. #include <boost/geometry/srs/projections/impl/base_static.hpp>
  38. #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
  39. #include <boost/geometry/srs/projections/impl/projects.hpp>
  40. #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
  41. namespace boost { namespace geometry
  42. {
  43. namespace srs { namespace par4
  44. {
  45. struct lonlat {}; // Lat/long (Geodetic)
  46. struct latlon {}; // Lat/long (Geodetic alias)
  47. struct latlong {}; // Lat/long (Geodetic alias)
  48. struct longlat {}; // Lat/long (Geodetic alias)
  49. }} //namespace srs::par4
  50. namespace projections
  51. {
  52. #ifndef DOXYGEN_NO_DETAIL
  53. namespace detail { namespace latlong
  54. {
  55. /* very loosely based upon DMA code by Bradford W. Drew */
  56. // template class, using CRTP to implement forward/inverse
  57. template <typename T, typename Parameters>
  58. struct base_latlong_other
  59. : public base_t_fi<base_latlong_other<T, Parameters>, T, Parameters>
  60. {
  61. inline base_latlong_other(const Parameters& par)
  62. : base_t_fi<base_latlong_other<T, Parameters>, T, Parameters>(*this, par)
  63. {}
  64. // FORWARD(forward)
  65. // Project coordinates from geographic (lon, lat) to cartesian (x, y)
  66. inline void fwd(T& lp_lon, T& lp_lat, T& xy_x, T& xy_y) const
  67. {
  68. // TODO: in the original code a is not used
  69. // different mechanism is probably used instead
  70. xy_x = lp_lon / this->m_par.a;
  71. xy_y = lp_lat / this->m_par.a;
  72. }
  73. // INVERSE(inverse)
  74. // Project coordinates from cartesian (x, y) to geographic (lon, lat)
  75. inline void inv(T& xy_x, T& xy_y, T& lp_lon, T& lp_lat) const
  76. {
  77. // TODO: in the original code a is not used
  78. // different mechanism is probably used instead
  79. lp_lat = xy_y * this->m_par.a;
  80. lp_lon = xy_x * this->m_par.a;
  81. }
  82. static inline std::string get_name()
  83. {
  84. return "latlong_other";
  85. }
  86. };
  87. // Lat/long (Geodetic)
  88. template <typename Parameters>
  89. inline void setup_lonlat(Parameters& par)
  90. {
  91. par.is_latlong = 1;
  92. par.x0 = 0.0;
  93. par.y0 = 0.0;
  94. }
  95. // Lat/long (Geodetic alias)
  96. template <typename Parameters>
  97. inline void setup_latlon(Parameters& par)
  98. {
  99. par.is_latlong = 1;
  100. par.x0 = 0.0;
  101. par.y0 = 0.0;
  102. }
  103. // Lat/long (Geodetic alias)
  104. template <typename Parameters>
  105. inline void setup_latlong(Parameters& par)
  106. {
  107. par.is_latlong = 1;
  108. par.x0 = 0.0;
  109. par.y0 = 0.0;
  110. }
  111. // Lat/long (Geodetic alias)
  112. template <typename Parameters>
  113. inline void setup_longlat(Parameters& par)
  114. {
  115. par.is_latlong = 1;
  116. par.x0 = 0.0;
  117. par.y0 = 0.0;
  118. }
  119. }} // namespace detail::latlong
  120. #endif // doxygen
  121. /*!
  122. \brief Lat/long (Geodetic) projection
  123. \ingroup projections
  124. \tparam Geographic latlong point type
  125. \tparam Cartesian xy point type
  126. \tparam Parameters parameter type
  127. \par Example
  128. \image html ex_lonlat.gif
  129. */
  130. template <typename T, typename Parameters>
  131. struct lonlat_other : public detail::latlong::base_latlong_other<T, Parameters>
  132. {
  133. inline lonlat_other(const Parameters& par) : detail::latlong::base_latlong_other<T, Parameters>(par)
  134. {
  135. detail::latlong::setup_lonlat(this->m_par);
  136. }
  137. };
  138. /*!
  139. \brief Lat/long (Geodetic alias) projection
  140. \ingroup projections
  141. \tparam Geographic latlong point type
  142. \tparam Cartesian xy point type
  143. \tparam Parameters parameter type
  144. \par Example
  145. \image html ex_latlon.gif
  146. */
  147. template <typename T, typename Parameters>
  148. struct latlon_other : public detail::latlong::base_latlong_other<T, Parameters>
  149. {
  150. inline latlon_other(const Parameters& par) : detail::latlong::base_latlong_other<T, Parameters>(par)
  151. {
  152. detail::latlong::setup_latlon(this->m_par);
  153. }
  154. };
  155. /*!
  156. \brief Lat/long (Geodetic alias) projection
  157. \ingroup projections
  158. \tparam Geographic latlong point type
  159. \tparam Cartesian xy point type
  160. \tparam Parameters parameter type
  161. \par Example
  162. \image html ex_latlong.gif
  163. */
  164. template <typename T, typename Parameters>
  165. struct latlong_other : public detail::latlong::base_latlong_other<T, Parameters>
  166. {
  167. inline latlong_other(const Parameters& par) : detail::latlong::base_latlong_other<T, Parameters>(par)
  168. {
  169. detail::latlong::setup_latlong(this->m_par);
  170. }
  171. };
  172. /*!
  173. \brief Lat/long (Geodetic alias) projection
  174. \ingroup projections
  175. \tparam Geographic latlong point type
  176. \tparam Cartesian xy point type
  177. \tparam Parameters parameter type
  178. \par Example
  179. \image html ex_longlat.gif
  180. */
  181. template <typename T, typename Parameters>
  182. struct longlat_other : public detail::latlong::base_latlong_other<T, Parameters>
  183. {
  184. inline longlat_other(const Parameters& par) : detail::latlong::base_latlong_other<T, Parameters>(par)
  185. {
  186. detail::latlong::setup_longlat(this->m_par);
  187. }
  188. };
  189. #ifndef DOXYGEN_NO_DETAIL
  190. namespace detail
  191. {
  192. // Static projection
  193. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::lonlat, lonlat_other, lonlat_other)
  194. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::latlon, latlon_other, latlon_other)
  195. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::latlong, latlong_other, latlong_other)
  196. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::longlat, longlat_other, longlat_other)
  197. // Factory entry(s)
  198. template <typename T, typename Parameters>
  199. class lonlat_entry : public detail::factory_entry<T, Parameters>
  200. {
  201. public :
  202. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  203. {
  204. return new base_v_fi<lonlat_other<T, Parameters>, T, Parameters>(par);
  205. }
  206. };
  207. template <typename T, typename Parameters>
  208. class latlon_entry : public detail::factory_entry<T, Parameters>
  209. {
  210. public :
  211. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  212. {
  213. return new base_v_fi<latlon_other<T, Parameters>, T, Parameters>(par);
  214. }
  215. };
  216. template <typename T, typename Parameters>
  217. class latlong_entry : public detail::factory_entry<T, Parameters>
  218. {
  219. public :
  220. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  221. {
  222. return new base_v_fi<latlong_other<T, Parameters>, T, Parameters>(par);
  223. }
  224. };
  225. template <typename T, typename Parameters>
  226. class longlat_entry : public detail::factory_entry<T, Parameters>
  227. {
  228. public :
  229. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  230. {
  231. return new base_v_fi<longlat_other<T, Parameters>, T, Parameters>(par);
  232. }
  233. };
  234. template <typename T, typename Parameters>
  235. inline void latlong_init(detail::base_factory<T, Parameters>& factory)
  236. {
  237. factory.add_to_factory("lonlat", new lonlat_entry<T, Parameters>);
  238. factory.add_to_factory("latlon", new latlon_entry<T, Parameters>);
  239. factory.add_to_factory("latlong", new latlong_entry<T, Parameters>);
  240. factory.add_to_factory("longlat", new longlat_entry<T, Parameters>);
  241. }
  242. } // namespace detail
  243. #endif // doxygen
  244. } // namespace projections
  245. }} // namespace boost::geometry
  246. #endif // BOOST_GEOMETRY_PROJECTIONS_LATLONG_HPP