File indexing completed on 2025-01-18 09:35:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_IMPL_PJ_GRIDLIST_HPP
0041 #define BOOST_GEOMETRY_SRS_PROJECTIONS_IMPL_PJ_GRIDLIST_HPP
0042
0043
0044 #include <boost/geometry/srs/projections/exception.hpp>
0045 #include <boost/geometry/srs/projections/grids.hpp>
0046 #include <boost/geometry/srs/projections/impl/pj_gridinfo.hpp>
0047 #include <boost/geometry/srs/projections/impl/pj_strerrno.hpp>
0048 #include <boost/geometry/srs/projections/par_data.hpp>
0049
0050
0051 namespace boost { namespace geometry { namespace projections
0052 {
0053
0054 namespace detail
0055 {
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 inline bool pj_gridlist_find_all(std::string const& gridname,
0068 pj_gridinfo const& grids,
0069 std::vector<std::size_t> & gridindexes)
0070 {
0071 bool result = false;
0072 for (std::size_t i = 0 ; i < grids.size() ; ++i)
0073 {
0074 if (grids[i].gridname == gridname)
0075 {
0076 result = true;
0077 gridindexes.push_back(i);
0078 }
0079 }
0080 return result;
0081 }
0082
0083
0084 inline void pj_gridlist_add_seq_inc(std::vector<std::size_t> & gridindexes,
0085 std::size_t first, std::size_t last)
0086 {
0087 gridindexes.reserve(gridindexes.size() + (last - first));
0088 for ( ; first < last ; ++first)
0089 {
0090 gridindexes.push_back(first);
0091 }
0092 }
0093
0094
0095 template <typename StreamPolicy, typename Grids>
0096 inline bool pj_gridlist_merge_gridfile(std::string const& gridname,
0097 StreamPolicy const& stream_policy,
0098 Grids & grids,
0099 std::vector<std::size_t> & gridindexes,
0100 grids_tag)
0101 {
0102
0103
0104
0105 if (pj_gridlist_find_all(gridname, grids.gridinfo, gridindexes))
0106 return true;
0107
0108 std::size_t orig_size = grids.gridinfo.size();
0109
0110
0111 typename StreamPolicy::stream_type is;
0112 stream_policy.open(is, gridname);
0113
0114 if (! pj_gridinfo_init(gridname, is, grids.gridinfo))
0115 {
0116 return false;
0117 }
0118
0119
0120 pj_gridlist_add_seq_inc(gridindexes, orig_size, grids.gridinfo.size());
0121
0122 return true;
0123 }
0124
0125
0126 template <typename StreamPolicy, typename SharedGrids>
0127 inline bool pj_gridlist_merge_gridfile(std::string const& gridname,
0128 StreamPolicy const& stream_policy,
0129 SharedGrids & grids,
0130 std::vector<std::size_t> & gridindexes,
0131 shared_grids_tag)
0132 {
0133
0134
0135
0136 {
0137 typename SharedGrids::read_locked lck_grids(grids);
0138
0139 if (pj_gridlist_find_all(gridname, lck_grids.gridinfo, gridindexes))
0140 return true;
0141 }
0142
0143
0144 typename StreamPolicy::stream_type is;
0145 stream_policy.open(is, gridname);
0146
0147 pj_gridinfo new_grids;
0148
0149 if (! pj_gridinfo_init(gridname, is, new_grids))
0150 {
0151 return false;
0152 }
0153
0154
0155
0156 std::size_t orig_size = 0;
0157 std::size_t new_size = 0;
0158
0159 {
0160 typename SharedGrids::write_locked lck_grids(grids);
0161
0162
0163
0164 if (pj_gridlist_find_all(gridname, lck_grids.gridinfo, gridindexes))
0165 return true;
0166
0167 orig_size = lck_grids.gridinfo.size();
0168 new_size = orig_size + new_grids.size();
0169
0170 lck_grids.gridinfo.resize(new_size);
0171 for (std::size_t i = 0 ; i < new_grids.size() ; ++ i)
0172 new_grids[i].swap(lck_grids.gridinfo[i + orig_size]);
0173 }
0174
0175 pj_gridlist_add_seq_inc(gridindexes, orig_size, new_size);
0176
0177 return true;
0178 }
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 template <typename StreamPolicy, typename Grids>
0192 inline void pj_gridlist_from_nadgrids(srs::detail::nadgrids const& nadgrids,
0193 StreamPolicy const& stream_policy,
0194 Grids & grids,
0195 std::vector<std::size_t> & gridindexes)
0196
0197 {
0198
0199 for (srs::detail::nadgrids::const_iterator it = nadgrids.begin() ;
0200 it != nadgrids.end() ; ++it)
0201 {
0202 bool required = (*it)[0] != '@';
0203
0204 std::string name(it->begin() + (required ? 0 : 1), it->end());
0205
0206 if ( ! pj_gridlist_merge_gridfile(name, stream_policy, grids, gridindexes,
0207 typename Grids::tag())
0208 && required )
0209 {
0210 BOOST_THROW_EXCEPTION( projection_exception(error_failed_to_load_grid) );
0211 }
0212 }
0213 }
0214
0215 template <typename Par, typename ProjectionGrids>
0216 inline void pj_gridlist_from_nadgrids(Par const& defn, ProjectionGrids & proj_grids)
0217 {
0218 pj_gridlist_from_nadgrids(defn.nadgrids,
0219 proj_grids.grids_storage().stream_policy,
0220 proj_grids.grids_storage().hgrids,
0221 proj_grids.hindexes);
0222 }
0223
0224
0225 }
0226
0227 }}}
0228
0229 #endif