grids.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // Boost.Geometry
  2. // This file was modified by Oracle on 2018.
  3. // Modifications copyright (c) 2018, Oracle and/or its affiliates.
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_GRIDS_HPP
  9. #define BOOST_GEOMETRY_SRS_PROJECTIONS_GRIDS_HPP
  10. #include <boost/geometry/srs/projections/impl/pj_gridinfo.hpp>
  11. #include <fstream>
  12. namespace boost { namespace geometry
  13. {
  14. namespace srs
  15. {
  16. // Forward declarations for functions declarations below
  17. class grids;
  18. template <typename GridsStorage>
  19. class projection_grids;
  20. } // namespace srs
  21. namespace projections { namespace detail
  22. {
  23. // Forward declaratios of grids friends
  24. template <typename StreamPolicy>
  25. inline bool pj_gridlist_merge_gridfile(std::string const& gridname,
  26. StreamPolicy const& stream_policy,
  27. srs::grids & grids,
  28. std::vector<std::size_t> & gridindexes);
  29. template <bool Inverse, typename CalcT, typename StreamPolicy, typename Range>
  30. inline bool pj_apply_gridshift_3(StreamPolicy const& stream_policy,
  31. Range & range,
  32. srs::grids & grids,
  33. std::vector<std::size_t> const& gridindexes);
  34. // Forward declaratios of projection_grids friends
  35. template <typename Par, typename GridsStorage>
  36. inline void pj_gridlist_from_nadgrids(Par const& defn,
  37. srs::projection_grids<GridsStorage> & grids);
  38. template <bool Inverse, typename Par, typename Range, typename Grids>
  39. inline bool pj_apply_gridshift_2(Par const& defn, Range & range, Grids const& grids);
  40. }} // namespace projections::detail
  41. namespace srs
  42. {
  43. class grids
  44. {
  45. public:
  46. std::size_t size() const
  47. {
  48. return gridinfo.size();
  49. }
  50. bool empty() const
  51. {
  52. return gridinfo.empty();
  53. }
  54. private:
  55. template <typename StreamPolicy>
  56. friend inline bool projections::detail::pj_gridlist_merge_gridfile(
  57. std::string const& gridname,
  58. StreamPolicy const& stream_policy,
  59. srs::grids & grids,
  60. std::vector<std::size_t> & gridindexes);
  61. template <bool Inverse, typename CalcT, typename StreamPolicy, typename Range>
  62. friend inline bool projections::detail::pj_apply_gridshift_3(
  63. StreamPolicy const& stream_policy,
  64. Range & range,
  65. srs::grids & grids,
  66. std::vector<std::size_t> const& gridindexes);
  67. projections::detail::pj_gridinfo gridinfo;
  68. };
  69. struct ifstream_policy
  70. {
  71. typedef std::ifstream stream_type;
  72. static inline void open(stream_type & is, std::string const& gridname)
  73. {
  74. is.open(gridname.c_str(), std::ios::binary);
  75. }
  76. };
  77. template
  78. <
  79. typename StreamPolicy = srs::ifstream_policy,
  80. typename Grids = grids
  81. >
  82. struct grids_storage
  83. {
  84. typedef StreamPolicy stream_policy_type;
  85. typedef Grids grids_type;
  86. grids_storage()
  87. {}
  88. explicit grids_storage(stream_policy_type const& policy)
  89. : stream_policy(policy)
  90. {}
  91. stream_policy_type stream_policy;
  92. grids_type hgrids;
  93. };
  94. template <typename GridsStorage = grids_storage<> >
  95. class projection_grids
  96. {
  97. public:
  98. projection_grids(GridsStorage & storage)
  99. : storage_ptr(boost::addressof(storage))
  100. {}
  101. std::size_t size() const
  102. {
  103. return hindexes.size();
  104. }
  105. bool empty() const
  106. {
  107. return hindexes.empty();
  108. }
  109. private:
  110. template <typename Par, typename GridsStor>
  111. friend inline void projections::detail::pj_gridlist_from_nadgrids(
  112. Par const& defn,
  113. srs::projection_grids<GridsStor> & grids);
  114. template <bool Inverse, typename Par, typename Range, typename Grids>
  115. friend inline bool projections::detail::pj_apply_gridshift_2(
  116. Par const& defn, Range & range, Grids const& grids);
  117. GridsStorage * const storage_ptr;
  118. std::vector<std::size_t> hindexes;
  119. };
  120. template <typename GridsStorage = grids_storage<> >
  121. struct transformation_grids
  122. {
  123. explicit transformation_grids(GridsStorage & storage)
  124. : src_grids(storage)
  125. , dst_grids(storage)
  126. {}
  127. projection_grids<GridsStorage> src_grids;
  128. projection_grids<GridsStorage> dst_grids;
  129. };
  130. namespace detail
  131. {
  132. struct empty_grids_storage {};
  133. struct empty_projection_grids {};
  134. } // namespace detail
  135. template <>
  136. struct transformation_grids<detail::empty_grids_storage>
  137. {
  138. detail::empty_projection_grids src_grids;
  139. detail::empty_projection_grids dst_grids;
  140. };
  141. }}} // namespace boost::geometry::srs
  142. #endif // BOOST_GEOMETRY_SRS_PROJECTIONS_GRIDS_HPP