Kstars

geolocation.h
1 /*
2  SPDX-FileCopyrightText: 2001-2005 Jason Harris <[email protected]>
3  SPDX-FileCopyrightText: 2003-2005 Pablo de Vicente <[email protected]>
4 
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #pragma once
9 
10 #include <KLocalizedString>
11 
12 #include "cachingdms.h"
13 #include "timezonerule.h"
14 #include "kstarsdatetime.h"
15 
16 /**
17  * @class GeoLocation
18  * Contains all relevant information for specifying a location
19  * on Earth: City Name, State/Province name, Country Name,
20  * Longitude, Latitude, Elevation, Time Zone, and Daylight Savings
21  * Time rule.
22  *
23  * @short Relevant data about an observing location on Earth.
24  * @author Jason Harris
25  * @version 1.0
26  */
28 {
29  public:
30  /** Constructor using dms objects to specify longitude and latitude.
31  * @param lng the longitude
32  * @param lat the latitude
33  * @param name the name of the city/town/location
34  * @param province the name of the province/US state
35  * @param country the name of the country
36  * @param TZ the base time zone offset from Greenwich, UK
37  * @param TZrule pointer to the daylight savings time rule
38  * @param elevation the elevation above sea level (in meters)
39  * @param readOnly whether the location is read only or updatable.
40  * @param iEllips type of geodetic ellipsoid model
41  */
42  GeoLocation(const dms &lng, const dms &lat, const QString &name = "Nowhere", const QString &province = "Nowhere",
43  const QString &country = "Nowhere", double TZ = 0, TimeZoneRule *TZrule = nullptr,
44  double elevation = -10, bool readOnly = false, int iEllips = 4);
45 
46  /** Constructor using doubles to specify X, Y and Z referred to the center of the Earth.
47  * @param x the x-position, in m
48  * @param y the y-position, in m
49  * @param z the z-position, in m
50  * @param name the name of the city/town/location
51  * @param province the name of the province/US state
52  * @param country the name of the country
53  * @param TZ the base time zone offset from Greenwich, UK
54  * @param TZrule pointer to the daylight savings time rule
55  * @param elevation the elevation above sea level (in meters)
56  * @param readOnly whether the location is read only or updatable.
57  * @param iEllips type of geodetic ellipsoid model
58  */
59  GeoLocation(double x, double y, double z, const QString &name = "Nowhere", const QString &province = "Nowhere",
60  const QString &country = "Nowhere", double TZ = 0, TimeZoneRule *TZrule = nullptr,
61  double elevation = -10, bool readOnly = false, int iEllips = 4);
62 
63  /** @return pointer to the longitude dms object */
64  const CachingDms *lng() const
65  {
66  return &Longitude;
67  }
68 
69  /** @return pointer to the latitude dms object */
70  const CachingDms *lat() const
71  {
72  return &Latitude;
73  }
74 
75  /** @return elevation above seal level (meters) */
76  double elevation() const
77  {
78  return Elevation;
79  }
80 
81  /** @return X position in m */
82  double xPos() const
83  {
84  return PosCartX;
85  }
86 
87  /** @return Y position in m */
88  double yPos() const
89  {
90  return PosCartY;
91  }
92 
93  /** @return Z position in m */
94  double zPos() const
95  {
96  return PosCartZ;
97  }
98 
99  /** @return index identifying the geodetic ellipsoid model */
100  int ellipsoid() const
101  {
102  return indexEllipsoid;
103  }
104 
105  /** @return untranslated City name */
106  QString name() const
107  {
108  return Name;
109  }
110 
111  /** @return translated City name */
112  QString translatedName() const;
113 
114  /** @return untranslated Province name */
116  {
117  return Province;
118  }
119 
120  /** @return translated Province name */
121  QString translatedProvince() const;
122 
123  /** @return untranslated Country name */
124  QString country() const
125  {
126  return Country;
127  }
128 
129  /** @return translated Country name */
130  QString translatedCountry() const;
131 
132  /** @return comma-separated city, province, country names (each localized) */
133  QString fullName() const;
134 
135  /** @return time zone without DST correction */
136  double TZ0() const
137  {
138  return TimeZone;
139  }
140 
141  /** @return time zone, including any DST correction. */
142  double TZ() const
143  {
144  if (TZrule)
145  return TimeZone + TZrule->deltaTZ();
146  return TimeZone;
147  }
148 
149  /** @return pointer to time zone rule object */
151  {
152  return TZrule;
153  }
154 
155  /** Set Time zone.
156  * @param value the new time zone */
157  void setTZ0(double value)
158  {
159  TimeZone = value;
160  }
161 
162  /** Set Time zone rule.
163  * @param value pointer to the new time zone rule */
164  void setTZRule(TimeZoneRule *value)
165  {
166  TZrule = value;
167  }
168 
169  /** Set longitude according to dms argument.
170  * @param l the new longitude */
171  void setLong(const dms &l)
172  {
173  Longitude = l;
174  geodToCart();
175  }
176 
177  /** Set latitude according to dms argument.
178  * @param l the new latitude
179  */
180  void setLat(const dms &l)
181  {
182  Latitude = l;
183  geodToCart();
184  }
185 
186  /** Set elevation above sea level
187  * @param hg the new elevation (meters)
188  */
189  void setElevation(double hg)
190  {
191  Elevation = hg;
192  geodToCart();
193  }
194 
195  /** Set X
196  * @param x the new x-position (meters)
197  */
198  void setXPos(double x)
199  {
200  PosCartX = x;
201  cartToGeod();
202  }
203  /** Set Y
204  * @param y the new y-position (meters)
205  */
206  void setYPos(double y)
207  {
208  PosCartY = y;
209  cartToGeod();
210  }
211  /** Set Z
212  * @param z the new z-position (meters)
213  */
214  void setZPos(double z)
215  {
216  PosCartZ = z;
217  cartToGeod();
218  }
219 
220  /** Update Latitude, Longitude and Height according to new ellipsoid. These are
221  * computed from XYZ which do NOT change on changing the ellipsoid.
222  * @param i index to identify the ellipsoid
223  */
224  void changeEllipsoid(int i);
225 
226  /** Set City name according to argument.
227  * @param n new city name
228  */
229  void setName(const QString &n)
230  {
231  Name = n;
232  }
233 
234  /** Set Province name according to argument.
235  * @param n new province name
236  */
237  void setProvince(const QString &n)
238  {
239  Province = n;
240  }
241 
242  /** Set Country name according to argument.
243  * @param n new country name
244  */
245  void setCountry(const QString &n)
246  {
247  Country = n;
248  }
249 
250  /** Converts from cartesian coordinates in meters to longitude,
251  * latitude and height on a standard geoid for the Earth. The
252  * geoid is characterized by two parameters: the semimajor axis
253  * and the flattening.
254  *
255  * @note The astronomical zenith is defined as the perpendicular to
256  * the real geoid. The geodetic zenith is the perpendicular to the
257  * standard geoid. Both zeniths differ due to local gravitational
258  * anomalies.
259  *
260  * Algorithm is from "GPS Satellite Surveying", A. Leick, page 184.
261  */
262  void cartToGeod();
263 
264  /** Converts from longitude, latitude and height on a standard
265  * geoid of the Earth to cartesian coordinates in meters. The geoid
266  * is characterized by two parameters: the semimajor axis and the
267  * flattening.
268  *
269  * @note The astronomical zenith is defined as the perpendicular to
270  * the real geoid. The geodetic zenith is the perpendicular to the
271  * standard geoid. Both zeniths differ due to local gravitational
272  * anomalies.
273  *
274  * Algorithm is from "GPS Satellite Surveying", A. Leick, page 184.
275  */
276  void geodToCart();
277 
278  /** The geoid is an elliposid which fits the shape of the Earth. It is
279  * characterized by two parameters: the semimajor axis and the
280  * flattening.
281  *
282  * @param i is the index which allows to identify the parameters for the
283  * chosen elliposid. 1="IAU76", 2="GRS80", 3="MERIT83", 4="WGS84",
284  * 5="IERS89".
285  */
286  void setEllipsoid(int i);
287 
288  /**
289  * @brief distanceTo Return the distance in km from this location to the given longitude and latitude
290  * @param longitude Target site longitude
291  * @param latitude Target site latitude
292  * @return distance in kilometers between this site and the target site.
293  */
294  double distanceTo(const dms &longitude, const dms &latitude);
295 
296  dms GSTtoLST(const dms &gst) const
297  {
298  return dms(gst.Degrees() + Longitude.Degrees());
299  }
300  dms LSTtoGST(const dms &lst) const
301  {
302  return dms(lst.Degrees() - Longitude.Degrees());
303  }
304 
305  KStarsDateTime UTtoLT(const KStarsDateTime &ut) const;
306  KStarsDateTime LTtoUT(const KStarsDateTime &lt) const;
307 
308  /** Computes the velocity in km/s of an observer on the surface of the Earth
309  * referred to a system whose origin is the center of the Earth. The X and
310  * Y axis are contained in the equator and the X axis is towards the nodes
311  * line. The Z axis is along the poles.
312  *
313  * @param vtopo[] Topocentric velocity. The resultant velocity is available
314  * in this array.
315  * @param gt Greenwich sideral time for which we want to compute the topocentric velocity.
316  */
317  void TopocentricVelocity(double vtopo[], const dms &gt);
318 
319  /** @return Local Mean Sidereal Time.
320  * @param jd Julian date
321  */
322  double LMST(double jd);
323 
324  bool isReadOnly() const;
325  void setReadOnly(bool value);
326 
327  private:
328  CachingDms Longitude, Latitude;
329  QString Name, Province, Country;
330  TimeZoneRule *TZrule;
331  double TimeZone, Elevation;
332  double axis, flattening;
333  long double PosCartX, PosCartY, PosCartZ;
334  int indexEllipsoid;
335  bool ReadOnly;
336 };
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
void setTZ0(double value)
Set Time zone.
Definition: geolocation.h:157
double distanceTo(const dms &longitude, const dms &latitude)
distanceTo Return the distance in km from this location to the given longitude and latitude
QString fullName() const
Definition: geolocation.cpp:46
void setCountry(const QString &n)
Set Country name according to argument.
Definition: geolocation.h:245
void changeEllipsoid(int i)
Update Latitude, Longitude and Height according to new ellipsoid.
Definition: geolocation.cpp:70
a dms subclass that caches its sine and cosine values every time the angle is changed.
Definition: cachingdms.h:18
double TZ0() const
Definition: geolocation.h:136
const CachingDms * lng() const
Definition: geolocation.h:64
void setYPos(double y)
Set Y.
Definition: geolocation.h:206
void geodToCart()
Converts from longitude, latitude and height on a standard geoid of the Earth to cartesian coordinate...
double TZ() const
Definition: geolocation.h:142
void setZPos(double z)
Set Z.
Definition: geolocation.h:214
TimeZoneRule * tzrule()
Definition: geolocation.h:150
int ellipsoid() const
Definition: geolocation.h:100
void setName(const QString &n)
Set City name according to argument.
Definition: geolocation.h:229
GeoLocation(const dms &lng, const dms &lat, const QString &name="Nowhere", const QString &province="Nowhere", const QString &country="Nowhere", double TZ=0, TimeZoneRule *TZrule=nullptr, double elevation=-10, bool readOnly=false, int iEllips=4)
Constructor using dms objects to specify longitude and latitude.
Definition: geolocation.cpp:12
QString country() const
Definition: geolocation.h:124
const CachingDms * lat() const
Definition: geolocation.h:70
double elevation() const
Definition: geolocation.h:76
QString translatedName() const
Definition: geolocation.cpp:76
double LMST(double jd)
QString translatedCountry() const
Definition: geolocation.cpp:97
QString translatedProvince() const
Definition: geolocation.cpp:90
double xPos() const
Definition: geolocation.h:82
void setTZRule(TimeZoneRule *value)
Set Time zone rule.
Definition: geolocation.h:164
QString name() const
Definition: geolocation.h:106
double yPos() const
Definition: geolocation.h:88
QString province() const
Definition: geolocation.h:115
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
void setProvince(const QString &n)
Set Province name according to argument.
Definition: geolocation.h:237
const double & Degrees() const
Definition: dms.h:141
void cartToGeod()
Converts from cartesian coordinates in meters to longitude, latitude and height on a standard geoid f...
void setLong(const dms &l)
Set longitude according to dms argument.
Definition: geolocation.h:171
double zPos() const
Definition: geolocation.h:94
void setXPos(double x)
Set X.
Definition: geolocation.h:198
void setEllipsoid(int i)
The geoid is an elliposid which fits the shape of the Earth.
Definition: geolocation.cpp:60
double deltaTZ() const
Definition: timezonerule.h:80
void TopocentricVelocity(double vtopo[], const dms &gt)
Computes the velocity in km/s of an observer on the surface of the Earth referred to a system whose o...
void setLat(const dms &l)
Set latitude according to dms argument.
Definition: geolocation.h:180
Relevant data about an observing location on Earth.
Definition: geolocation.h:27
void setElevation(double hg)
Set elevation above sea level.
Definition: geolocation.h:189
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 16 2022 04:00:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.