2 // This file is manually converted from PROJ4
4 // This file was modified by Oracle on 2018, 2019.
5 // Modifications copyright (c) 2018-2019, Oracle and/or its affiliates.
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
12 // This file is converted from PROJ4, http://trac.osgeo.org/proj
13 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
14 // PROJ4 is maintained by Frank Warmerdam
15 // This file was converted to Geometry Library by Adam Wulkiewicz
17 // Original copyright notice:
18 // Author: Frank Warmerdam, warmerdam@pobox.com
20 // Copyright (c) 2000, Frank Warmerdam
22 // Permission is hereby granted, free of charge, to any person obtaining a
23 // copy of this software and associated documentation files (the "Software"),
24 // to deal in the Software without restriction, including without limitation
25 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
26 // and/or sell copies of the Software, and to permit persons to whom the
27 // Software is furnished to do so, subject to the following conditions:
29 // The above copyright notice and this permission notice shall be included
30 // in all copies or substantial portions of the Software.
32 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
33 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
35 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
37 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
38 // DEALINGS IN THE SOFTWARE.
40 #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_IMPL_PJ_APPLY_GRIDSHIFT_SHARED_HPP
41 #define BOOST_GEOMETRY_SRS_PROJECTIONS_IMPL_PJ_APPLY_GRIDSHIFT_SHARED_HPP
44 #include <boost/geometry/core/assert.hpp>
45 #include <boost/geometry/core/radian_access.hpp>
47 #include <boost/geometry/srs/projections/impl/pj_apply_gridshift.hpp>
48 #include <boost/geometry/srs/projections/impl/pj_gridlist_shared.hpp>
51 namespace boost { namespace geometry { namespace projections
57 template <bool Inverse, typename CalcT, typename StreamPolicy, typename Range>
58 inline bool pj_apply_gridshift_3(StreamPolicy const& stream_policy,
61 std::vector<std::size_t> const& gridindexes)
63 typedef typename boost::range_size<Range>::type size_type;
65 // If the grids are empty the indexes are as well
66 if (gridindexes.empty())
68 //pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
69 //return PJD_ERR_FAILED_TO_LOAD_GRID;
73 size_type point_count = boost::size(range);
78 for (size_type i = 0 ; i < point_count ; )
80 bool load_needed = false;
86 boost::shared_lock<boost::shared_mutex> lock(grids.mutex);
88 for ( ; i < point_count ; ++i )
90 typename boost::range_reference<Range>::type
91 point = range::at(range, i);
93 in_lon = geometry::get_as_radian<0>(point);
94 in_lat = geometry::get_as_radian<1>(point);
96 pj_gi * gip = find_grid(in_lon, in_lat, grids.gridinfo, gridindexes);
102 else if (! gip->ct.cvs.empty())
104 // TODO: use set_invalid_point() or similar mechanism
105 CalcT out_lon = HUGE_VAL;
106 CalcT out_lat = HUGE_VAL;
108 nad_cvt<Inverse>(in_lon, in_lat, out_lon, out_lat, *gip);
110 // TODO: check differently
111 if (out_lon != HUGE_VAL)
113 geometry::set_from_radian<0>(point, out_lon);
114 geometry::set_from_radian<1>(point, out_lat);
129 if (load_grid(stream_policy, local_gi))
131 boost::unique_lock<boost::shared_mutex> lock(grids.mutex);
133 // check again in case other thread already loaded the grid.
134 pj_gi * gip = find_grid(in_lon, in_lat, grids.gridinfo, gridindexes);
136 if (gip != NULL && gip->ct.cvs.empty())
138 // swap loaded local storage with empty grid
153 } // namespace detail
155 }}} // namespace boost::geometry::projections
157 #endif // BOOST_GEOMETRY_SRS_PROJECTIONS_IMPL_PJ_APPLY_GRIDSHIFT_SHARED_HPP