00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qstring.h>
00021
00022 #include "geolocation.h"
00023 #include "timezonerule.h"
00024
00025 GeoLocation::GeoLocation(){
00026 GeoLocation( 0.0, 0.0 );
00027 TZrule = NULL;
00028 }
00029
00030 GeoLocation::GeoLocation( const GeoLocation &g ) {
00031 Longitude = g.Longitude;
00032 Latitude = g.Latitude;
00033 Name = g.Name;
00034 Province = g.Province;
00035 Country = g.Country;
00036 TimeZone = g.TimeZone;
00037 TZrule = g.TZrule;
00038 Height = g.Height;
00039 indexEllipsoid = g.indexEllipsoid;
00040 setEllipsoid ( indexEllipsoid );
00041 geodToCart();
00042 }
00043
00044 GeoLocation::GeoLocation( GeoLocation *g ) {
00045 Longitude = g->Longitude;
00046 Latitude = g->Latitude;
00047 Name = g->Name;
00048 Province = g->Province;
00049 Country = g->Country;
00050 TimeZone = g->TimeZone;
00051 TZrule = g->TZrule;
00052 Height = g->Height;
00053 indexEllipsoid = g->indexEllipsoid;
00054 setEllipsoid ( indexEllipsoid );
00055 geodToCart();
00056 }
00057
00058 GeoLocation::GeoLocation( dms lng, dms lat,
00059 QString name, QString province, QString country, double tz, TimeZoneRule *tzrule, int iEllips, double hght ) {
00060 Longitude = lng;
00061 Latitude = lat;
00062 Name = name;
00063 Province = province;
00064 Country = country;
00065 TimeZone = tz;
00066 TZrule = tzrule;
00067 Height = hght;
00068 indexEllipsoid = iEllips;
00069 setEllipsoid ( indexEllipsoid );
00070 geodToCart();
00071 }
00072
00073 GeoLocation::GeoLocation( double lng, double lat,
00074 QString name, QString province, QString country, double tz, TimeZoneRule *tzrule, int iEllips, double hght ) {
00075 Longitude.set( lng );
00076 Latitude.set( lat );
00077 Name = name;
00078 Province = province;
00079 Country = country;
00080 TimeZone = tz;
00081 TZrule = tzrule;
00082 Height = hght;
00083 indexEllipsoid = iEllips;
00084 setEllipsoid ( indexEllipsoid );
00085 geodToCart();
00086 }
00087
00088 GeoLocation::GeoLocation( double x, double y, double z, QString name, QString province, QString country, double TZ, TimeZoneRule *tzrule, int iEllips ) {
00089 PosCartX = x;
00090 PosCartY = y;
00091 PosCartZ = z;
00092 Name = name;
00093 Province = province;
00094 Country = country;
00095 TimeZone = TZ;
00096 TZrule = tzrule;
00097 indexEllipsoid = iEllips;
00098 setEllipsoid ( indexEllipsoid );
00099 cartToGeod();
00100 }
00101
00102 QString GeoLocation::fullName() const {
00103 QString s;
00104 if ( province().isEmpty() ) {
00105 s = translatedName() + ", " + translatedCountry();
00106 } else {
00107 s = translatedName() + ", " + translatedProvince() + ", " + translatedCountry();
00108 }
00109
00110 return s;
00111 }
00112
00113 void GeoLocation::reset( GeoLocation *g ) {
00114 indexEllipsoid = g->ellipsoid();
00115 setEllipsoid ( indexEllipsoid );
00116 setLong( g->lng()->Degrees() );
00117 setLat( g->lat()->Degrees() );
00118 Name = g->name();
00119 Province = g->province();
00120 Country = g->country();
00121 TimeZone = g->TZ();
00122 TZrule = g->tzrule();
00123 Height = g->height();
00124 }
00125
00126
00127 void GeoLocation::setEllipsoid(int index) {
00128 static const double A[] = { 6378140.0, 6378137.0, 6378137.0, 6378137.0, 6378136.0 };
00129 static const double F[] = { 0.0033528131779, 0.0033528106812, 0.0033528131779, 0.00335281066474, 0.0033528131779 };
00130
00131 axis = A[index];
00132 flattening = F[index];
00133 }
00134
00135 void GeoLocation::changeEllipsoid(int index) {
00136
00137 setEllipsoid(index);
00138 cartToGeod();
00139
00140 }
00141
00142 void GeoLocation::cartToGeod(void)
00143 {
00144 static const double RIT = 2.7778e-6;
00145 double e2, rpro, lat1, xn, s1, sqrtP2, latd, sinl;
00146
00147 e2 = 2*flattening-flattening*flattening;
00148
00149 sqrtP2 = sqrt(PosCartX*PosCartX+PosCartY*PosCartY);
00150
00151 rpro = PosCartZ/sqrtP2;
00152 latd = atan(rpro/(1-e2));
00153 lat1 = 0.;
00154
00155 while ( fabs( latd-lat1 ) > RIT ) {
00156 lat1 = latd;
00157 s1 = sin(lat1);
00158 xn = axis/(sqrt(1-e2*s1*s1));
00159 latd = atan( rpro*(1+e2*xn*s1/PosCartZ) );
00160 }
00161
00162 sinl = sin(latd);
00163 xn = axis/( sqrt(1-e2*sinl*sinl) );
00164
00165 Height = sqrtP2/cos(latd)-xn;
00166 Longitude.setRadians( atan2(PosCartY,PosCartX) );
00167 Latitude.setRadians(latd);
00168 }
00169
00170 void GeoLocation::geodToCart (void) {
00171 double e2, xn;
00172 double sinLong, cosLong, sinLat, cosLat;
00173
00174 e2 = 2*flattening-flattening*flattening;
00175
00176 Longitude.SinCos(sinLong,cosLong);
00177 Latitude.SinCos(sinLat,cosLat);
00178
00179 xn = axis/( sqrt(1-e2*sinLat*sinLat) );
00180 PosCartX = (xn+Height)*cosLat*cosLong;
00181 PosCartY = (xn+Height)*cosLat*sinLong;
00182 PosCartZ = (xn*(1-e2)+Height)*sinLat;
00183 }
00184
00185 void GeoLocation::TopocentricVelocity(double vtopo[], dms gst) {
00186
00187 double Wearth = 7.29211510e-5;
00188 dms angularVEarth;
00189
00190 dms time= GSTtoLST(gst);
00191
00192 double se, ce;
00193
00194 time.SinCos(se,ce);
00195
00196 double d0 = sqrt(PosCartX*PosCartX+PosCartY*PosCartY);
00197
00198 vtopo[0] = - d0 * Wearth * se /1000.;
00199 vtopo[1] = d0 * Wearth * ce /1000.;
00200 vtopo[2] = 0.;
00201 }