76 double equatorialRadius;
82 double inverseFlattening;
92 double eccentricitySqr;
137 EarthShape(
const string& earthShape =
"WGS84") { setEarthShape(earthShape); }
164 void setEarthShape(
const string& earthShape)
166 shapeName = earthShape;
168 if (earthShape ==
"SPHERE")
170 equatorialRadius = 6371;
171 inverseFlattening = 1e99;
172 constantRadius =
true;
174 else if (earthShape ==
"GRS80")
176 equatorialRadius = 6378.137;
177 inverseFlattening = 298.257222101;
178 constantRadius =
false;
180 else if (earthShape ==
"GRS80_RCONST")
182 equatorialRadius = 6371.;
183 inverseFlattening = 298.257222101;
184 constantRadius =
true;
186 else if (earthShape ==
"WGS84")
188 equatorialRadius = 6378.137;;
189 inverseFlattening = 298.257223563;
190 constantRadius =
false;
192 else if (earthShape ==
"WGS84_RCONST")
194 equatorialRadius = 6371.;
195 inverseFlattening = 298.257223563;
196 constantRadius =
true;
198 else if (earthShape ==
"IERS2003")
200 equatorialRadius = 6378.1366;
201 inverseFlattening = 298.25642;
202 constantRadius =
false;
204 else if (earthShape ==
"IERS2003_RCONST")
206 equatorialRadius = 6371.;
207 inverseFlattening = 298.25642;
208 constantRadius =
true;
213 os << endl <<
"ERROR in EarthShape::setEarthShape" << endl
214 << earthShape <<
" is not a recognized EarthShape" << endl
215 <<
"Valid EarthShapes include SPHERE, GRS80, GRS80_RCONST, WGS84, WGS84_RCONST, IERS2003 and IERS2003_RCONST" << endl;
219 sphere = shapeName ==
"SPHERE";
220 eccentricitySqr = (2.- 1./inverseFlattening)/inverseFlattening;
221 e1 = 1.-eccentricitySqr;
222 e2 = eccentricitySqr/(1.-eccentricitySqr);
236 static string class_name()
237 {
return "EarthShape"; }
243 virtual int class_size()
const
253 double getEarthRadius(
const double*
const v)
255 return constantRadius ? equatorialRadius
256 : equatorialRadius / sqrt(1 + e2 * v[2] * v[2]);
266 double getGeoCentricLatitude(
const double& lat)
269 return sphere ? lat : atan(tan(lat) * e1);
279 double getGeoGraphicLatitude(
const double& lat)
281 return sphere ? lat : atan(tan(lat) / e1);
291 double getLat(
const double*
const v)
293 return getGeoGraphicLatitude(asin(v[2]));
302 double getLatDegrees(
const double*
const v)
304 return CPPUtils::toDegrees(getLat(v));
313 double getLon(
const double*
const v)
315 return atan2(v[1], v[0]);
324 double getLonDegrees(
const double*
const v)
326 return CPPUtils::toDegrees(atan2(v[1], v[0]));
340 double* getVectorDegrees(
const double& lat,
343 return getVector(CPPUtils::toRadians(lat), CPPUtils::toRadians(lon));
356 double* getVectorDegrees(
const double& lat,
357 const double& lon,
double* v)
359 return getVector(CPPUtils::toRadians(lat), CPPUtils::toRadians(lon), v);
373 double* getVector(
const double& lat,
const double& lon)
375 double* v =
new double[3];
376 getVector(lat, lon, v);
390 double* getVector(
const double& lat,
const double& lon,
double* v)
393 double temp = getGeoCentricLatitude(lat);
402 v[0] = temp * cos(lon);
403 v[1] = temp * sin(lon);
412 string getLatLonString(
const double*
const v)
415 string frmt(
"%9.5f %10.5f");
416 sprintf(s, frmt.c_str(), getLatDegrees(v), getLonDegrees(v));
437 #endif // EARTH_SHAPE_H