radolan  1.2.0
coordinate_system.h
1 /* The MIT License (MIT)
2  *
3  * (c) Jürgen Simon 2014 (juergen.simon@uni-bonn.de)
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef RADOLAN_COORDINATE_SYSTEM_H
25 #define RADOLAN_COORDINATE_SYSTEM_H
26 
27 //C-headers
28 //C++ headers
29 //3rd-party headers
30 #include <radolan/types.h>
31 
32 // TODO: refactor using RDGridPoint and RDGeographicalPointRad etc
33 
34 namespace Radolan {
35 
40  typedef struct
41  {
43  double latitude;
45  double longitude;
47 
48  inline RDGeographicalPointRad rdGeographicalPointRad(double longitude, double latitude) {
50  p.longitude = longitude;
51  p.latitude = latitude;
52  return p;
53  }
54 
55  inline bool RDEquals(RDGeographicalPointRad a, RDGeographicalPointRad b) {
56  return a.latitude == b.latitude && a.longitude == b.longitude;
57  }
58 
59 #define RDGeographicalPointRadUndefined rdGeographicalPointRad(NAN,NAN)
60 
64  typedef struct
65  {
67  double latitude;
69  double longitude;
71 
72  inline RDGeographicalPoint rdGeographicalPoint(double longitude, double latitude) {
74  p.longitude = longitude;
75  p.latitude = latitude;
76  return p;
77  }
78 
79  inline bool RDEquals(RDGeographicalPoint a, RDGeographicalPoint b) {
80  return a.latitude == b.latitude && a.longitude == b.longitude;
81  }
82 
83 #define RDGeographicalPointUndefined rdGeographicalPoint(NAN,NAN)
84 
88  typedef struct
89  {
91  double x;
93  double y;
95 
96  inline RDCartesianPoint rdCartesianPoint(double x, double y) {
98  p.x = x;
99  p.y = y;
100  return p;
101  }
102 
103  inline bool RDEquals(RDCartesianPoint a, RDCartesianPoint b) {
104  return a.x == b.x && a.y == b.y;
105  }
106 
107 #define RDCartesianPointUndefined rdCartesianPoint(NAN,NAN)
108 
112  typedef struct
113  {
115  int ix;
117  int iy;
118  } RDGridPoint;
119 
120  inline RDGridPoint rdGridPoint(int ix, int iy) {
121  RDGridPoint p;
122  p.ix = ix;
123  p.iy = iy;
124  return p;
125  }
126 
127  inline bool RDEquals(RDGridPoint a, RDGridPoint b) {
128  return a.ix == b.ix && a.iy == b.iy;
129  }
130 
131 #define RDGridPointUndefined rdGridPoint(-1, -1)
132 
133  inline RDDataType RDValueAt(RDScan *scan, RDGridPoint gridPoint) {
134  return scan->data[gridPoint.iy * scan->dimLon + gridPoint.ix];
135  }
136 
137  // 1 | 2
138  // - + -
139  // 0 | 3
140 
141  typedef enum
142  {
143  RDLowerLeft = 0,
144  RDUpperLeft = 1,
145  RDUpperRight = 2,
146  RDLowerRight = 3
147  } RDGridQuadrant;
148 
154  {
155  public:
156 
163  RDCoordinateSystem(RDScanType type);
164 
168  virtual ~RDCoordinateSystem();
169 
175  void setScanType(RDScanType type);
176 
184 
192 
200 
208 
216 
224 
232 
240 
248 
257 
266  RDGridPoint gridPoint(RDCartesianPoint p, bool &isInside);
267 
276  RDGridPoint gridPoint(RDGeographicalPoint p, bool &isInside);
277 
286  RDGridPoint gridPoint(RDGeographicalPointRad p, bool &isInside);
287 
295  RDGridQuadrant RDQuadrant(RDGridPoint p);
296 
304  double polarStereographicScalingFactor(double phi0, double phi);
305 
306  private:
307 
308  // these parameters depend on the radolan product
309  int m_radolanGridCountHorizontal;
310  int m_radolanGridCountVertical;
311 
312  // Origin of the coordinate system in geographical coordinates
313  RDGeographicalPoint m_originGeographical;
314 
315  // Origin in cartesian coordinates
316  RDCartesianPoint m_originCartesian;
317 
318  // Offset of the origin from lower left corner (example: EX: -600, -800)
319  RDCartesianPoint m_offset;
320 
321  RDScanType m_scanType;
322 
323  // These are parameters of the projection itself and don't change
324  static const double LAMBDA_0;
325  static const double PHI_0;
326  static const double R_EARTH;
327  static const double MESH_WIDTH;
328  static const double RADOLAN_GRID_COUNT;
329  static const double LAMBDA_MIN_BOTTOM;
330  static const double PHI_MIN_BOTTOM;
331  static const double LAMBDA_MAX_TOP;
332  static const double PHI_MAX_TOP;
333 
335  double deg(double rad);
336 
338  double rad(double deg);
339 
340  // Called after changing scan type to update internals
341  void updateGridInfo();
342 
343  }; //class RDCoordinateSystem
344 }
345 
346 #endif /* Header Guard */
double latitude
Geographical latitude (in radians)
RDGeographicalPoint toDeg(RDGeographicalPointRad p)
Convert radians to deg.
Data type for reading and handling radolan products.
Definition: types.h:171
RDGridQuadrant RDQuadrant(RDGridPoint p)
Find out what quadrant of the grid with respect to the grid&#39;s cartesian origin coordinates the given ...
RDGeographicalPointRad geographicalCoordinateRad(RDCartesianPoint p)
Calculate geographical coordinate from the given polar stereographic coordinate.
Represents a point in geographical coordinate system in grad as (latitude,longitude) ...
RDGeographicalPointRad toRad(RDGeographicalPoint p)
Convert deg to radians.
double x
Cartesian x coordinate.
Represents a point in the cartesian coordinate system (polar stereographic projection) as (x...
Represents a point in geographical coordinate system in radians as (latitude,longitude) ...
void setScanType(RDScanType type)
Changes the scan type.
Represents a point in the radolan grid by the column/row indexes as (ix,iy)
RDCoordinateSystem(RDScanType type)
Constructs a coordinate system for a specific RDScanType.
int dimLon
Number of longitudinal vertices.
Definition: types.h:183
double longitude
Geographical longitute (in radians)
int iy
vertical index
double y
Cartesian y coordinate.
double latitude
Geographical latitude.
RDGeographicalPoint * geographicalPolygonForGridpoint(RDGridPoint p, int &num)
Calculate the geographical coordinates for the bounding box of the given grid point.
double longitude
Geographical longitude.
This class wraps a number of routines to deal with the radolan specific coordinate systems...
RDGeographicalPoint geographicalCoordinate(RDCartesianPoint p)
Calculate geographical coordinate from the given polar stereographic coordinate.
RDGridPoint gridPoint(RDCartesianPoint p, bool &isInside)
Calculate the nearest grid point for the given cartesian coordinate.
RDDataType * data
Array of rd_data[header.payloadSize].
Definition: types.h:180
int ix
horizontal index
RDCartesianPoint cartesianCoordinate(RDGeographicalPointRad coord)
Calculate the polar stereographic coordinate from the given geographical coordinate.
double polarStereographicScalingFactor(double phi0, double phi)
Scaling Factor for the polar stereographic projection.
virtual ~RDCoordinateSystem()
Destructor.