Skip to content

Commit 1aeef5d

Browse files
committedApr 8, 2018
[srs] Support horizontal shift grids (nadgrids) in transformation.
Relevant proj4 code was converted to C++ and Boostified. So all grids formats are supported (ctable, ctable2, ntv1, ntv2), also vertical geoid grid GTX format but it is not used right now. There are some differences though: - proj4 stores loaded grids in global storage and pointers to a relevant subset of grids in projection parameters structure. In Boost.Geometry this is moved outside transformation structure to allow users to place global storage(s) wherever they like. - in proj4 the grids are loaded implicitly when there is +nadgrids parameter passed. In Boost.Geometry an object representing a subset of grids explicitly has to be initialized and then passed into transforming function. - in proj4 grids has to be "installed" into certain directories. In Boost.Geometry user can implement StreamPolicy opening any input stream having unformatted input interface. The default one uses std::ifstream opening files having the same names as the ones in +nadgrids parameter in working directory. Added classes: srs::grids, srs::ifstream_policy, srs::grids_storage, srs::projection_grids, srs::transformation_grids and for multithreading: srs::shared_grids Added functions (also overloads) srs::transformation::initialize_grids(grids_storage) srs::transformation::forward(in, out, transformation_grids) srs::transformation::inverse(in, out, transformation_grids)
1 parent 7df9d6d commit 1aeef5d

10 files changed

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

0 commit comments

Comments
 (0)