summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/geolocation.h
blob: c3b6524ed69c6b909ccb17c8b72532e32f70c886 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/***************************************************************************
                          geolocation.h  -  K Desktop Planetarium
                             -------------------
    begin                : Sun Feb 11 2001
    copyright            : (C) 2001-2005 by Jason Harris
    email                : jharris@30doradus.org
    copyright            : (C) 2003-2005 by Pablo de Vicente
    email                : p.devicente@wanadoo.es
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef GEOLOCATION_H
#define GEOLOCATION_H

#include <klocale.h>

#include "dms.h"
#include "timezonerule.h"
#include "kstarsdatetime.h"

/**@class GeoLocation
	*Contains all relevant information for specifying a location 
	*on Earth: City Name, State/Province name, Country Name,
	*Longitude, Latitude, Elevation, Time Zone, and Daylight Savings 
	*Time rule.
	*@short Relevant data about an observing location on Earth.
	*@author Jason Harris
	*@version 1.0
	*/

class GeoLocation {
public: 
/**
	*Default constructor; sets coordinates to zero.	
	*/
	GeoLocation();

/**Copy Constructor
	*@param g the GeoLocation to duplicate
	*/
	GeoLocation( const GeoLocation &g );

/**Copy Constructor.  Differs from the above function only in argument type.
	*@param g pointer to the GeoLocation to duplicate
	*/
	GeoLocation( GeoLocation *g );

/**Constructor using dms objects to specify longitude and latitude.
	*@param lng the longitude
	*@param lat the latitude
	*@param name the name of the city/town/location
	*@param province the name of the province/US state
	*@param country the name of the country
	*@param TZ the base time zone offset from Greenwich, UK
	*@param TZrule pointer to the daylight savings time rule
	*@param iEllips type of geodetic ellipsoid model
	*@param hght the elevation above sea level (in meters?)
	*/
	GeoLocation( dms lng, dms lat, TQString name="Nowhere", TQString province="Nowhere", TQString country="Nowhere", double TZ=0, TimeZoneRule *TZrule=NULL, int iEllips=4, double hght=-10 );

/**Constructor using doubles to specify longitude and latitude.
	*@param lng the longitude
	*@param lat the latitude
	*@param name the name of the city/town/location
	*@param province the name of the province/US state
	*@param country the name of the country
	*@param TZ the base time zone offset from Greenwich, UK
	*@param TZrule pointer to the daylight savings time rule
	*@param iEllips type of geodetic ellipsoid model
	*@param hght the elevation above sea level (in meters?)
	*/
	GeoLocation( double lng, double lat, TQString name="Nowhere", TQString province="Nowhere", TQString country="Nowhere", double TZ=0, TimeZoneRule *TZrule=NULL, int iEllips=4, double hght=-10 );

/**Constructor using doubles to specify X, Y and Z referred to the center of the Earth.
	*@param x the x-position, in m
	*@param y the y-position, in m
	*@param z the z-position, in m
	*@param name the name of the city/town/location
	*@param province the name of the province/US state
	*@param country the name of the country
	*@param TZ the base time zone offset from Greenwich, UK
	*@param TZrule pointer to the daylight savings time rule
	*@param iEllips type of geodetic ellipsoid model
	*/
	GeoLocation( double x, double y, double z, TQString name="Nowhere", TQString province="Nowhere", TQString country="Nowhere", double TZ=0, TimeZoneRule *TZrule=NULL, int iEllips=4 );


/**Destructor (empty)
	*/
	~GeoLocation() {}

/**@return pointer to the longitude dms object
	*/
	const dms* lng() const { return &Longitude; }
/**@return pointer to the latitude dms object
	*/
	const dms* lat() const { return &Latitude; }
/**@return elevation above seal level (meters)
	*/
	double height() const { return Height; }
/**@return X position in m
	*/
	double xPos() const { return PosCartX; }
/**@return Y position in m
	*/
	double yPos() const { return PosCartY; }
/**@return Z position in m
	*/
	double zPos() const { return PosCartZ; }
/**@return index identifying the geodetic ellipsoid model
	*/
	int ellipsoid() const { return indexEllipsoid; }

/**@return untranslated City name
	*/
	TQString name() const { return Name; }
/**@return translated City name
	*/
	TQString translatedName() const { return i18n("City name (optional, probably does not need a translation)", Name.utf8().data()); }
/**@return untranslated Province name
	*/
	TQString province() const { return Province; }
/**@return translated Province name
	*/
	TQString translatedProvince() const { return i18n("Region/state name (optional, rarely needs a translation)", Province.utf8().data()); }
/**@return untranslated Country name
	*/
	TQString country() const { return Country; }
/**@return translated Country name
 */
	TQString translatedCountry() const { return i18n("Country name (optional, but should be translated)", Country.utf8().data()); }

/**@return comma-separated city, province, country names (each localized)
 */
	TQString fullName() const;

/**@return time zone without DST correction
	*/
	double TZ0() const { return TimeZone; }

/**@return time zone, including any DST correction.
	*/
	double TZ() const { return TimeZone + TZrule->deltaTZ(); }

/**@return pointer to time zone rule object
	*/
	TimeZoneRule* tzrule() const { return TZrule; }

/**Set longitude according to dms argument.
	*@param l the new longitude
	*/
	void setLong( dms l ) { 
		Longitude = l; 
		geodToCart();
	}
/**Set longitude according to argument.
	*Differs from above function only in argument type.
	*@param l the new longitude
	*/
	void setLong( double l ) { 
		Longitude.setD( l ); 
		geodToCart();
	}

/**Set latitude according to dms argument.
	*@param l the new latitude
	*/
	void setLat( dms l ) { 
		Latitude  = l; 
		geodToCart();
	}
	
/**Set latitude according to argument.
	*Differs from above function only in argument type.
	*@param l the new latitude
	*/
	void setLat( double l ) { 
		Latitude.setD( l ); 
		geodToCart();
	}

/**Set elevation above sea level
	*@param hg the new elevation (meters)
	*/
	void setHeight( double hg ) { 
		Height  = hg; 
		geodToCart();
	}

/**Set X 
	*@param x the new x-position (meters)
	*/
	void setXPos( double x ) { 
		PosCartX  = x; 
		cartToGeod();
	}
/**Set Y 
	*@param y the new y-position (meters)
	*/
	void setYPos( double y ) { 
		PosCartY  = y; 
		cartToGeod();
	}
/**Set Z 
	*@param z the new z-position (meters)
	*/
	void setZPos( double z ) { 
		PosCartZ  = z; 
		cartToGeod();
	}
	
/**Update Latitude, Longitude and Height according to new ellipsoid. These are
	*computed from XYZ which do NOT change on changing the ellipsoid.
	*@p i = index to identify the ellipsoid
	*/
	void changeEllipsoid( int i );
	
/**Set City name according to argument.
	*@p n new city name
	*/
	void setName( const TQString &n ) { Name = n; }

/**Set Province name according to argument.
	*@p n new province name
	*/
	void setProvince( const TQString &n ) { Province = n; }

/**Set Country name according to argument.
	*@p n new country name
	*/
	void setCountry( const TQString &n ) { Country = n; }

/**Sets Time Zone according to argument.
	*@p tz new timezone offset
	*/
	void setTZ( double tz ) { TimeZone = tz; }

/**Sets DST rule pointer according to argument.
	*@p txr pointer to the new DST rule
	*/
	void setTZrule( TimeZoneRule *tzr ) { TZrule = tzr; }

/**Set location data to that of the GeoLocation pointed to by argument.
	*Similar to copy constructor.
	*@param g pointer to the GeoLocation which should be duplicated.
	*/
	void reset( GeoLocation *g );

/**Converts from cartesian coordinates in meters to longitude, 
	*latitude and height on a standard geoid for the Earth. The 
	*geoid is characterized by two parameters: the semimajor axis
	*and the flattening.
	*
	*@note The astronomical zenith is defined as the perpendicular to 
	*the real geoid. The geodetic zenith is the perpendicular to the 
	*standard geoid. Both zeniths differ due to local gravitational 
	*anomalies.
	*
	* Algorithm is from "GPS Satellite Surveying", A. Leick, page 184.
	*/
	void cartToGeod(void);

/**Converts from longitude, latitude and height on a standard 
	*geoid of the Earth to cartesian coordinates in meters. The geoid
	*is characterized by two parameters: the semimajor axis and the 
	*flattening.
	*
	*@note The astronomical zenith is defined as the perpendicular to 
	*the real geoid. The geodetic zenith is the perpendicular to the 
	*standard geoid. Both zeniths differ due to local gravitational 
	*anomalies.
	*
	*Algorithm is from "GPS Satellite Surveying", A. Leick, page 184.
	*/
	void geodToCart (void);

/**The geoid is an elliposid which fits the shape of the Earth. It is
	*characterized by two parameters: the semimajor axis and the
	*flattening.
	*
	*@p index is the index which allows to identify the parameters for the
	*chosen elliposid. 1="IAU76", 2="GRS80", 3="MERIT83", 4="WGS84", 
	*5="IERS89"};
	*/
	void setEllipsoid( int i );

	dms GSTtoLST( const dms &gst ) const { return dms( gst.Degrees() + Longitude.Degrees() ); }
	dms LSTtoGST( const dms &lst ) const { return dms( lst.Degrees() - Longitude.Degrees() ); }

	KStarsDateTime UTtoLT( const KStarsDateTime &ut ) const { return ut.addSecs( int( 3600.*TZ() ) ); }
	KStarsDateTime LTtoUT( const KStarsDateTime &lt ) const { return lt.addSecs( int( -3600.*TZ() ) ); }


	/* Computes the velocity in km/s of an observer on the surface of the Earth 
	 * referred to a system whose origin is the center of the Earth. The X and 
	 * Y axis are contained in the equator and the X axis is towards the nodes
	 * line. The Z axis is along the poles.
	 *
	 * @param vtopo[] Topocentric velocity. The resultant velocity is available 
	 *        in this array.
	 * @param gt. Greenwich sideral time for which we want to compute the topocentric velocity.
	 */
	void TopocentricVelocity(double vtopo[], dms gt);

private:
	dms Longitude, Latitude;
	TQString Name, Province, Country;
	TimeZoneRule *TZrule;
	double TimeZone, Height;
	double axis, flattening;
	long double PosCartX, PosCartY, PosCartZ;
	int indexEllipsoid;
};

#endif