GeoTessCPP 2.6.1 Software to facilitate storage and retrieval of 3D information about the Earth.

Loading...
Searching...
No Matches
EarthShape.h
Go to the documentation of this file.
1//- ****************************************************************************
2//-
3//- Copyright 2009 Sandia Corporation. Under the terms of Contract
4//- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5//- retains certain rights in this software.
6//-
7//- BSD Open Source License.
8//- All rights reserved.
9//-
10//- Redistribution and use in source and binary forms, with or without
11//- modification, are permitted provided that the following conditions are met:
12//-
13//- * Redistributions of source code must retain the above copyright notice,
14//- this list of conditions and the following disclaimer.
15//- * Redistributions in binary form must reproduce the above copyright
16//- notice, this list of conditions and the following disclaimer in the
17//- documentation and/or other materials provided with the distribution.
18//- * Neither the name of Sandia National Laboratories nor the names of its
19//- contributors may be used to endorse or promote products derived from
20//- this software without specific prior written permission.
21//-
22//- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23//- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24//- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25//- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26//- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27//- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28//- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29//- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30//- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31//- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32//- POSSIBILITY OF SUCH DAMAGE.
33//-
34//- ****************************************************************************
35
36#ifndef EARTH_SHAPE_H
37#define EARTH_SHAPE_H
38
39// **** _SYSTEM INCLUDES_ ******************************************************
40
41#include <iostream>
42#include <string>
43
44// use standard library objects
45 using namespace std;
46
47// **** _LOCAL INCLUDES_ *******************************************************
48
49#include "CPPUtils.h"
50#include "GeoTessException.h"
51
52// **** _BEGIN GEOTESS NAMESPACE_ **********************************************
53
54 namespace geotess
55{
56
57// **** _FORWARD REFERENCES_ ***************************************************
58
59// **** _CLASS DEFINITION_ *****************************************************
60
85 class GEOTESS_EXP_IMP EarthShape
86{
87 private:
88
92 string shapeName;
93
97 double equatorialRadius;
98
103 double inverseFlattening;
104
113 double eccentricitySqr;
114
118 double e1;
119
123 double e2;
124
129 bool constantRadius;
130
134 bool sphere;
135
136 public:
137
158 EarthShape(const string& earthShape = "WGS84") { setEarthShape(earthShape); }
159
185 void setEarthShape(const string& earthShape)
186 {
187 shapeName = earthShape;
188
189 if (earthShape == "SPHERE")
190 {
191 equatorialRadius = 6371;
192 inverseFlattening = 1e99;
193 constantRadius = true;
194 }
195 else if (earthShape == "GRS80")
196 {
197 equatorialRadius = 6378.137;
198 inverseFlattening = 298.257222101;
199 constantRadius = false;
200 }
201 else if (earthShape == "GRS80_RCONST")
202 {
203 equatorialRadius = 6371.;
204 inverseFlattening = 298.257222101;
205 constantRadius = true;
206 }
207 else if (earthShape == "WGS84")
208 {
209 equatorialRadius = 6378.137;;
210 inverseFlattening = 298.257223563;
211 constantRadius = false;
212 }
213 else if (earthShape == "WGS84_RCONST")
214 {
215 equatorialRadius = 6371.;
216 inverseFlattening = 298.257223563;
217 constantRadius = true;
218 }
219 else if (earthShape == "IERS2003")
220 {
221 equatorialRadius = 6378.1366;
222 inverseFlattening = 298.25642;
223 constantRadius = false;
224 }
225 else if (earthShape == "IERS2003_RCONST")
226 {
227 equatorialRadius = 6371.;
228 inverseFlattening = 298.25642;
229 constantRadius = true;
230 }
231 else
232 {
233 ostringstream os;
234 os << endl << "ERROR in EarthShape::setEarthShape" << endl
235 << earthShape << " is not a recognized EarthShape" << endl
236 << "Valid EarthShapes include SPHERE, GRS80, GRS80_RCONST, WGS84, WGS84_RCONST, IERS2003 and IERS2003_RCONST" << endl;
237 throw GeoTessException(os, __FILE__, __LINE__, 9001);
238 }
239
240 sphere = shapeName == "SPHERE";
241 eccentricitySqr = (2.- 1./inverseFlattening)/inverseFlattening;
242 e1 = 1.-eccentricitySqr;
243 e2 = eccentricitySqr/(1.-eccentricitySqr);
244 }
245
249 virtual ~EarthShape()
250 {
251 }
252
257 static string class_name()
258 { return "EarthShape"; }
259
264 virtual int class_size() const
265 { return (int) sizeof(EarthShape); }
266
274 double getEarthRadius(const double* const v)
275 { return constantRadius ? equatorialRadius : equatorialRadius / sqrt(1 + e2 * v[2] * v[2]); }
276
284 double getGeocentricLat(const double& lat)
285 { return sphere ? lat : atan(tan(lat) * e1); }
286
294 double getGeographicLat(const double& lat)
295 { return sphere ? lat : atan(tan(lat) / e1); }
296
304 double getGeocentricLatDegrees(const double& lat)
305 { return sphere ? lat : CPPUtils::toDegrees(atan(tan(CPPUtils::toRadians(lat)) * e1)); }
306
314 double getGeographicLatDegrees(const double& lat)
315 { return sphere ? lat : CPPUtils::toDegrees(atan(tan(CPPUtils::toRadians(lat)) / e1)); }
316
323 double getLat(const double* const v)
324 { return getGeographicLat(asin(v[2])); }
325
332 double getLatDegrees(const double* const v)
333 { return CPPUtils::toDegrees(getLat(v)); }
334
341 double getLon(const double* const v)
342 { return atan2(v[1], v[0]); }
343
350 double getLonDegrees(const double* const v)
351 { return CPPUtils::toDegrees(atan2(v[1], v[0])); }
352
363 void getVectorDegrees(const double& lat, const double& lon, double* v)
364 { getVector(CPPUtils::toRadians(lat), CPPUtils::toRadians(lon), v); }
365
375 double* getVectorDegrees(const double& lat, const double& lon)
376 { return getVector(CPPUtils::toRadians(lat), CPPUtils::toRadians(lon)); }
377
389 double* getVector(const double& lat, const double& lon)
390 {
391 double* v = new double[3];
392 getVector(lat, lon, v);
393 return v;
394 }
395
406 double* getVector(const double& lat, const double& lon, double* v)
407 {
408 // convert lat from geographic to geocentric latitude.
409 double temp = getGeocentricLat(lat);
410
411 // z component of v is sin of geocentric latitude.
412 v[2] = sin(temp);
413
414 // set lat = to cos of geocentric latitude
415 temp = cos(temp);
416
417 // compute x and y components of v
418 v[0] = temp * cos(lon);
419 v[1] = temp * sin(lon);
420
421 return v;
422 }
423
428 string getLatLonString(const double* const v)
429 {
430 char s[300];
431 string frmt("%9.5f %10.5f");
432 snprintf(s, sizeof(s), frmt.c_str(), getLatDegrees(v), getLonDegrees(v));
433 return s;
434 }
435
436 bool isConstantRadius() const { return constantRadius; }
437
438 double getEccentricitySqr() const { return eccentricitySqr; }
439
440 double getEquatorialRadius() const { return equatorialRadius; }
441
442 double getInverseFlattening() const { return inverseFlattening; }
443
444 bool isSphere() const { return sphere; }
445
446 const string& getShapeName() const { return shapeName; }
447
448};
449// end class EarthShape
450
451} // end namespace geotess
452
453#endif // EARTH_SHAPE_H
GEOTESS_EXP_IMP
#define GEOTESS_EXP_IMP
Definition CPPGlobals.h:71
CPPUtils.h
GeoTessException.h
geotess::CPPUtils::toDegrees
static double toDegrees(double a)
Definition CPPUtils.h:392
geotess::CPPUtils::toRadians
static double toRadians(double a)
Definition CPPUtils.h:402
geotess::EarthShape::isSphere
bool isSphere() const
Definition EarthShape.h:444
geotess::EarthShape::isConstantRadius
bool isConstantRadius() const
Definition EarthShape.h:436
geotess::EarthShape::getLat
double getLat(const double *const v)
Definition EarthShape.h:323
geotess::EarthShape::getGeographicLatDegrees
double getGeographicLatDegrees(const double &lat)
Definition EarthShape.h:314
geotess::EarthShape::~EarthShape
virtual ~EarthShape()
Definition EarthShape.h:249
geotess::EarthShape::getInverseFlattening
double getInverseFlattening() const
Definition EarthShape.h:442
geotess::EarthShape::getGeocentricLatDegrees
double getGeocentricLatDegrees(const double &lat)
Definition EarthShape.h:304
geotess::EarthShape::getLatDegrees
double getLatDegrees(const double *const v)
Definition EarthShape.h:332
geotess::EarthShape::getEccentricitySqr
double getEccentricitySqr() const
Definition EarthShape.h:438
geotess::EarthShape::getVectorDegrees
double * getVectorDegrees(const double &lat, const double &lon)
Definition EarthShape.h:375
geotess::EarthShape::getLonDegrees
double getLonDegrees(const double *const v)
Definition EarthShape.h:350
geotess::EarthShape::getLon
double getLon(const double *const v)
Definition EarthShape.h:341
geotess::EarthShape::getGeocentricLat
double getGeocentricLat(const double &lat)
Definition EarthShape.h:284
geotess::EarthShape::getVectorDegrees
void getVectorDegrees(const double &lat, const double &lon, double *v)
Definition EarthShape.h:363
geotess::EarthShape::EarthShape
EarthShape(const string &earthShape="WGS84")
Definition EarthShape.h:158
geotess::EarthShape::getEquatorialRadius
double getEquatorialRadius() const
Definition EarthShape.h:440
geotess::EarthShape::getEarthRadius
double getEarthRadius(const double *const v)
Definition EarthShape.h:274
geotess::EarthShape::getGeographicLat
double getGeographicLat(const double &lat)
Definition EarthShape.h:294
geotess::EarthShape::getVector
double * getVector(const double &lat, const double &lon, double *v)
Definition EarthShape.h:406
geotess::EarthShape::getLatLonString
string getLatLonString(const double *const v)
Definition EarthShape.h:428
geotess::EarthShape::class_name
static string class_name()
Definition EarthShape.h:257
geotess::EarthShape::class_size
virtual int class_size() const
Definition EarthShape.h:264
geotess::EarthShape::setEarthShape
void setEarthShape(const string &earthShape)
Definition EarthShape.h:185
geotess::EarthShape::getVector
double * getVector(const double &lat, const double &lon)
Definition EarthShape.h:389
geotess::EarthShape::getShapeName
const string & getShapeName() const
Definition EarthShape.h:446
geotess::GeoTessException
An exception class for all GeoTess objects.
Definition GeoTessException.h:66
geotess
Definition ArrayReuse.h:55