Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
ProjectionConversions.hpp
1//---- GPL ---------------------------------------------------------------------
2//
3// Copyright (C) Stichting Deltares, 2011-2023.
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation version 3.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17// contact: delft3d.support@deltares.nl
18// Stichting Deltares
19// P.O. Box 177
20// 2600 MH Delft, The Netherlands
21//
22// All indications and logos of, and references to, "Delft3D" and "Deltares"
23// are registered trademarks of Stichting Deltares, and remain the property of
24// Stichting Deltares. All rights reserved.
25//
26//------------------------------------------------------------------------------
27
28#pragma once
29
30#include <string>
31
32#if defined(__linux__) || defined(__APPLE__)
33#pragma GCC diagnostic push
34#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
35#endif
36
37#define BOOST_ALLOW_DEPRECATED_HEADERS
38#include <boost/geometry.hpp>
39#include <boost/geometry/srs/epsg.hpp>
40#undef BOOST_ALLOW_DEPRECATED_HEADERS
41
42#if defined(__linux__) || defined(__APPLE__)
43#pragma GCC diagnostic pop
44#endif
45
46namespace meshkernel
47{
48
50 namespace bg = boost::geometry;
51
53 template <typename ProjectionConversion>
55 {
56 public:
58 using LongLat = bg::model::d2::point_xy<double, bg::cs::geographic<bg::degree>>;
59
61 using UTM = bg::model::d2::point_xy<double, Projection>;
62
64 explicit ConvertSphericalToCartesianBase(const ProjectionConversion& proj) : m_projection(proj) {}
65
68
71 {
72 return Projection::spherical;
73 }
74
77 {
78 return Projection::cartesian;
79 }
80
82 Point operator()(const Point& pnt) const
83 {
84 LongLat longLat(pnt.x, pnt.y);
85 UTM utm{0.0, 0.0};
86 m_projection.forward(longLat, utm);
87
88 Point result(utm.x(), utm.y());
89 return result;
90 }
91
92 private:
94 ProjectionConversion m_projection;
95 };
96
98 template <const int EpsgCode>
99 class ConvertSphericalToCartesianEPSG : public ConvertSphericalToCartesianBase<bg::srs::projection<bg::srs::static_epsg<EpsgCode>>>
100 {
101 public:
103 using EpsgProjection = bg::srs::projection<bg::srs::static_epsg<EpsgCode>>;
104
106 ConvertSphericalToCartesianEPSG() : ConvertSphericalToCartesianBase<bg::srs::projection<bg::srs::static_epsg<EpsgCode>>>(EpsgProjection()) {}
107 };
108
111 {
112 public:
114 explicit ConvertSphericalToCartesian(const std::string& zone) : ConvertSphericalToCartesianBase<bg::srs::projection<>>(bg::srs::proj4(zone)) {}
115 };
116
117 //--------------------------------
118
120 template <typename ProjectionConversion>
122 {
123 public:
125 using LongLat = bg::model::d2::point_xy<double, bg::cs::geographic<bg::degree>>;
126
128 using UTM = bg::model::d2::point_xy<double>;
129
131 explicit ConvertCartesianToSphericalBase(const ProjectionConversion& proj) : m_projection(proj) {}
132
135
138 {
139 return Projection::cartesian;
140 }
141
144 {
145 return Projection::spherical;
146 }
147
149 Point operator()(const Point& pnt) const
150 {
151 UTM utm{pnt.x, pnt.y};
152 LongLat longLat{0.0, 0.0};
153 m_projection.inverse(utm, longLat);
154
155 Point result(longLat.x(), longLat.y());
156 return result;
157 }
158
159 private:
161 ProjectionConversion m_projection;
162 };
163
165 template <const int EpsgCode>
166 class ConvertCartesianToSphericalEPSG : public ConvertCartesianToSphericalBase<boost::geometry::srs::projection<boost::geometry::srs::static_epsg<EpsgCode>>>
167 {
168 public:
170 using EpsgProjection = boost::geometry::srs::projection<boost::geometry::srs::static_epsg<EpsgCode>>;
171
173 ConvertCartesianToSphericalEPSG() : ConvertCartesianToSphericalBase<boost::geometry::srs::projection<boost::geometry::srs::static_epsg<EpsgCode>>>(EpsgProjection()) {}
174 };
175
178 {
179 public:
181 explicit ConvertCartesianToSpherical(const std::string& zone) : ConvertCartesianToSphericalBase<bg::srs::projection<>>(bg::srs::proj4(zone)) {}
182 };
183
184} // namespace meshkernel
Converts points from spherical to Cartesian coordinate system.
Definition ProjectionConversions.hpp:122
Projection SourceProjection() const
The coordinate system of the point parameter to the conversion operation.
Definition ProjectionConversions.hpp:137
Projection TargetProjection() const
The coordinate system of the point result of the conversion operation.
Definition ProjectionConversions.hpp:143
bg::model::d2::point_xy< double, bg::cs::geographic< bg::degree > > LongLat
point in longitude-latitude space
Definition ProjectionConversions.hpp:125
virtual ~ConvertCartesianToSphericalBase()=default
Default destructor.
Point operator()(const Point &pnt) const
Apply the conversion of a point in Cartesian coordinate system to spherical.
Definition ProjectionConversions.hpp:149
bg::model::d2::point_xy< double > UTM
Point in x-y space.
Definition ProjectionConversions.hpp:128
ConvertCartesianToSphericalBase(const ProjectionConversion &proj)
Constructor with projection.
Definition ProjectionConversions.hpp:131
Converts points from spherical to Cartesian coordinate system using an EPSG code.
Definition ProjectionConversions.hpp:167
boost::geometry::srs::projection< boost::geometry::srs::static_epsg< EpsgCode > > EpsgProjection
The EPSG projection.
Definition ProjectionConversions.hpp:170
ConvertCartesianToSphericalEPSG()
Construct spherical to Cartesian with an EPSG code.
Definition ProjectionConversions.hpp:173
Converts points from spherical to Cartesian coordinate system.
Definition ProjectionConversions.hpp:178
ConvertCartesianToSpherical(const std::string &zone)
Construct spherical to Cartesian with an zone string.
Definition ProjectionConversions.hpp:181
Namespace alias for boost::geometry.
Definition ProjectionConversions.hpp:55
bg::model::d2::point_xy< double, bg::cs::geographic< bg::degree > > LongLat
point in longitude-latitude space
Definition ProjectionConversions.hpp:58
ConvertSphericalToCartesianBase(const ProjectionConversion &proj)
Constructor with projection.
Definition ProjectionConversions.hpp:64
bg::model::d2::point_xy< double, Projection > UTM
Point in x-y space.
Definition ProjectionConversions.hpp:61
Point operator()(const Point &pnt) const
Apply the conversion of a point in Spherical coordinate system to Cartesian.
Definition ProjectionConversions.hpp:82
Projection SourceProjection() const
The coordinate system of the point parameter to the conversion operation.
Definition ProjectionConversions.hpp:70
virtual ~ConvertSphericalToCartesianBase()=default
Default destructor.
Projection TargetProjection() const
The coordinate system of the point result of the conversion operation.
Definition ProjectionConversions.hpp:76
Converts points from spherical to Cartesian coordinate system using an ESPG code.
Definition ProjectionConversions.hpp:100
bg::srs::projection< bg::srs::static_epsg< EpsgCode > > EpsgProjection
The EPSG projection.
Definition ProjectionConversions.hpp:103
ConvertSphericalToCartesianEPSG()
Construct spherical to Cartesian with an EPSG code.
Definition ProjectionConversions.hpp:106
Converts points from spherical to Cartesian coordinate system.
Definition ProjectionConversions.hpp:111
ConvertSphericalToCartesian(const std::string &zone)
Construct spherical to Cartesian with an zone string.
Definition ProjectionConversions.hpp:114
A struct describing a point in a two-dimensional space.
Definition Point.hpp:41
double x
X-coordinate.
Definition Point.hpp:43
double y
Y-coordinate.
Definition Point.hpp:44
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
Projection
Enumerator describing the supported projections.
Definition Definitions.hpp:43