RadarProj.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25  */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30  */
31 #ifndef RADAR_PROJ_
32 #define RADAR_PROJ_ "RadarProj 2023 Markus Peura fmi.fi"
33 
34 #include <math.h>
35 
36 #include <iostream>
37 #include <ostream>
38 #include <sstream>
39 
40 #include "drain/util/Proj6.h"
41 #include "drain/util/Rectangle.h"
42 
43 #include "Constants.h"
44 //#include "radar.h"
45 
46 // See also RadarProj4 @ Geometry?
47 
48 namespace rack {
49 
53 class RadarProj4 : public drain::Proj6 {
54 
55 public:
56 
58  /*
59  * \param lon - longitude of the location, in degrees
60  * \param lat - longitude of the location, in degrees
61  */
62  RadarProj4(double lon=0.0, double lat=0.0){
63  setLocation(lon, lat);
64  }
65 
67  /*
68  * \param lon - longitude of the location, in degrees
69  * \param lat - longitude of the location, in degrees
70  */
71  inline
72  void setLocation(double lon, double lat){
73  std::stringstream sstr;
74  sstr << "+proj=aeqd" << " +lon_0=" << lon << " +lat_0=" << lat << " +ellps=WGS84 +type=crs";
75  setProjectionSrc(sstr.str());
76  };
77 
79  inline
80  void getBoundingBox(double range, double & lonLL, double & latLL, double & lonUR, double & latUR) const {
81  projectFwd(5.0/4.0*M_PI, ::sqrt(2.0)*range, lonLL, latLL);
82  projectFwd(1.0/4.0*M_PI, ::sqrt(2.0)*range, lonUR, latUR);
83  }
84 
86  inline
87  void getBoundingBoxDeg(double range, double & lonLL, double & latLL, double & lonUR, double & latUR) const {
88  getBoundingBox(range, lonLL, latLL, lonUR, latUR);
89  lonLL *= drain::RAD2DEG;
90  latLL *= drain::RAD2DEG;
91  lonUR *= drain::RAD2DEG;
92  latUR *= drain::RAD2DEG;
93  }
94 
95 
96 
97 };
98 
99 class RadarProj : public drain::Proj6 {
100 
101 public:
102 
104  /*
105  * \param lon - longitude of the location, in degrees
106  * \param lat - longitude of the location, in degrees
107  */
108  RadarProj(double lonDeg=0.0, double latDeg=0.0){
109  setSiteLocationDeg(lonDeg, latDeg);
110  }
111 
113  /*
114  * \param lon - longitude of the location, in degrees
115  * \param lat - longitude of the location, in degrees
116  inline
117  void setLocation(double lon, double lat){
118  std::stringstream sstr;
119  sstr << "+proj=aeqd" << " +lon_0=" << lon << " +lat_0=" << lat << " +ellps=WGS84 +type=crs"; //
120  setProjectionSrc(sstr.str());
121  };
122  */
123 
125  /*
126  * \param lon - longitude of the location, in degrees
127  * \param lat - longitude of the location, in degrees
128  */
129  inline
130  void setSiteLocationDeg(double lon, double lat){
131  std::stringstream s;
132  s << "+proj=aeqd" << " +lon_0=" << lon << " +lat_0=" << lat << " +ellps=WGS84 +type=crs"; // +type=crs
133  setProjectionSrc(s.str());
134  }
135 
137  /*
138  * \param lon - longitude of the location in radians
139  * \param lat - longitude of the location in degrees
140  */
141  inline
142  void setSiteLocationRad(double lon, double lat){
143  setSiteLocationDeg(lon*drain::RAD2DEG, lat*drain::RAD2DEG);
144  }
145 
147  inline
148  void getBoundingBox(double range, double & lonLL, double & latLL, double & lonUR, double & latUR) const {
149  projectFwd(5.0/4.0*M_PI, ::sqrt(2.0)*range, lonLL, latLL);
150  projectFwd(1.0/4.0*M_PI, ::sqrt(2.0)*range, lonUR, latUR);
151  }
152 
154  inline
155  void getBoundingBoxDeg(double range, double & lonLL, double & latLL, double & lonUR, double & latUR) const {
156  getBoundingBox(range, lonLL, latLL, lonUR, latUR);
157  lonLL *= drain::RAD2DEG;
158  latLL *= drain::RAD2DEG;
159  lonUR *= drain::RAD2DEG;
160  latUR *= drain::RAD2DEG;
161  }
162 
163 
164  inline
165  void setLatLonProjection(){
166  setProjectionDst("+proj=latlong +ellps=WGS84 +datum=WGS84 +no_defs");
167  }
168 
170  void determineBoundingBoxM(double range, double & xLL, double & yLL, double & xUR, double & yUR) const;
171 
173  inline
174  void determineBoundingBoxM(double range, drain::Rectangle<double> & bbox) const {
175  determineBoundingBoxM(range, bbox.lowerLeft.x, bbox.lowerLeft.y, bbox.upperRight.x, bbox.upperRight.y);
176  }
177 
179  //void determineBoundingBoxD(double range, double & xLL, double & yLL, double & xUR, double & yUR) const;
180 
181 
183  /*
184  inline
185  void determineBoundingBoxD(double range, drain::Rectangle<double> & bbox) const {
186  determineBoundingBoxD(range, bbox.lowerLeft.x, bbox.lowerLeft.y, bbox.upperRight.x, bbox.upperRight.y);
187  }
188  */
189 
190 
191 };
192 
193 
195 // DEPRECATED
221 } // ::rack
222 
223 #endif
224 
225 // Rack
Definition: Proj6.h:257
void setProjectionDst(const std::string &projDef, Projector::CRS_mode crs=Projector::FORCE_CRS)
Sets destination projection.
Definition: Proj6.h:286
void setProjectionSrc(const std::string &projDef, Projector::CRS_mode crs=Projector::FORCE_CRS)
Sets source projection.
Definition: Proj6.h:279
void projectFwd(double &x, double &y) const
Forward projection (in-place)
Definition: Proj6.h:359
Definition: RadarProj.h:53
void setLocation(double lon, double lat)
Sets location of the radar and the azimuthal equidistant (AEQD) projection accordingly.
Definition: RadarProj.h:72
void getBoundingBoxDeg(double range, double &lonLL, double &latLL, double &lonUR, double &latUR) const
Bounding box in degrees.
Definition: RadarProj.h:87
void getBoundingBox(double range, double &lonLL, double &latLL, double &lonUR, double &latUR) const
Bounding box in radians.
Definition: RadarProj.h:80
RadarProj4(double lon=0.0, double lat=0.0)
Sets location of the radar and the azimuthal equidistant (AEQD) projection accordingly.
Definition: RadarProj.h:62
Definition: RadarProj.h:99
RadarProj(double lonDeg=0.0, double latDeg=0.0)
Sets location of the radar and the azimuthal equidistant (AEQD) projection accordingly.
Definition: RadarProj.h:108
void getBoundingBoxDeg(double range, double &lonLL, double &latLL, double &lonUR, double &latUR) const
Bounding box in degrees.
Definition: RadarProj.h:155
void determineBoundingBoxM(double range, drain::Rectangle< double > &bbox) const
Given radar's range, returns the metric bounding box using the current projection.
Definition: RadarProj.h:174
void setSiteLocationDeg(double lon, double lat)
Sets location of the radar and the azimuthal equidistant (AEQD) projection accordingly.
Definition: RadarProj.h:130
void setSiteLocationRad(double lon, double lat)
Sets location of the radar and the azimuthal equidistant (AEQD) projection accordingly.
Definition: RadarProj.h:142
void determineBoundingBoxM(double range, double &xLL, double &yLL, double &xUR, double &yUR) const
Given radar's range, returns the metric bounding box using the current projection.
Definition: RadarProj.cpp:41
void getBoundingBox(double range, double &lonLL, double &latLL, double &lonUR, double &latUR) const
Bounding box in radians.
Definition: RadarProj.h:148
Definition: DataSelector.cpp:44