94 double equatorialRadius;
100 double inverseFlattening;
110 double eccentricitySqr;
155 EarthShape(
const string& earthShape =
"WGS84") { setEarthShape(earthShape); }
182 void setEarthShape(
const string& earthShape)
184 shapeName = earthShape;
186 if (earthShape ==
"SPHERE")
188 equatorialRadius = 6371;
189 inverseFlattening = 1e99;
190 constantRadius =
true;
192 else if (earthShape ==
"GRS80")
194 equatorialRadius = 6378.137;
195 inverseFlattening = 298.257222101;
196 constantRadius =
false;
198 else if (earthShape ==
"GRS80_RCONST")
200 equatorialRadius = 6371.;
201 inverseFlattening = 298.257222101;
202 constantRadius =
true;
204 else if (earthShape ==
"WGS84")
206 equatorialRadius = 6378.137;;
207 inverseFlattening = 298.257223563;
208 constantRadius =
false;
210 else if (earthShape ==
"WGS84_RCONST")
212 equatorialRadius = 6371.;
213 inverseFlattening = 298.257223563;
214 constantRadius =
true;
216 else if (earthShape ==
"IERS2003")
218 equatorialRadius = 6378.1366;
219 inverseFlattening = 298.25642;
220 constantRadius =
false;
222 else if (earthShape ==
"IERS2003_RCONST")
224 equatorialRadius = 6371.;
225 inverseFlattening = 298.25642;
226 constantRadius =
true;
231 os << endl <<
"ERROR in EarthShape::setEarthShape" << endl
232 << earthShape <<
" is not a recognized EarthShape" << endl
233 <<
"Valid EarthShapes include SPHERE, GRS80, GRS80_RCONST, WGS84, WGS84_RCONST, IERS2003 and IERS2003_RCONST" << endl;
237 sphere = shapeName ==
"SPHERE";
238 eccentricitySqr = (2.- 1./inverseFlattening)/inverseFlattening;
239 e1 = 1.-eccentricitySqr;
240 e2 = eccentricitySqr/(1.-eccentricitySqr);
254 static string class_name()
255 {
return "EarthShape"; }
261 virtual int class_size()
const
271 double getEarthRadius(
const double*
const v)
272 {
return constantRadius ? equatorialRadius : equatorialRadius / sqrt(1 + e2 * v[2] * v[2]); }
281 double getGeocentricLat(
const double& lat)
282 {
return sphere ? lat : atan(tan(lat) * e1); }
291 double getGeographicLat(
const double& lat)
292 {
return sphere ? lat : atan(tan(lat) / e1); }
301 double getGeocentricLatDegrees(
const double& lat)
302 {
return sphere ? lat : CPPUtils::toDegrees(atan(tan(CPPUtils::toRadians(lat)) * e1)); }
311 double getGeographicLatDegrees(
const double& lat)
312 {
return sphere ? lat : CPPUtils::toDegrees(atan(tan(CPPUtils::toRadians(lat)) / e1)); }
320 double getLat(
const double*
const v)
321 {
return getGeographicLat(asin(v[2])); }
329 double getLatDegrees(
const double*
const v)
330 {
return CPPUtils::toDegrees(getLat(v)); }
338 double getLon(
const double*
const v)
339 {
return atan2(v[1], v[0]); }
347 double getLonDegrees(
const double*
const v)
348 {
return CPPUtils::toDegrees(atan2(v[1], v[0])); }
360 void getVectorDegrees(
const double& lat,
const double& lon,
double* v)
361 { getVector(CPPUtils::toRadians(lat), CPPUtils::toRadians(lon), v); }
373 double* getVectorDegrees(
const double& lat,
const double& lon)
374 {
return getVector(CPPUtils::toRadians(lat), CPPUtils::toRadians(lon)); }
387 double* getVector(
const double& lat,
const double& lon)
389 double* v =
new double[3];
390 getVector(lat, lon, v);
404 double* getVector(
const double& lat,
const double& lon,
double* v)
407 double temp = getGeocentricLat(lat);
416 v[0] = temp * cos(lon);
417 v[1] = temp * sin(lon);
426 string getLatLonString(
const double*
const v)
429 string frmt(
"%9.5f %10.5f");
430 sprintf(s, frmt.c_str(), getLatDegrees(v), getLonDegrees(v));
451 #endif // EARTH_SHAPE_H