geo-coordinate.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 #ifndef GEO_COORDINATE_H
21 #define GEO_COORDINATE_H
22 
23 #include <ns3/attribute-helper.h>
24 #include <ns3/attribute.h>
25 #include <ns3/vector.h>
26 
27 namespace ns3
28 {
29 
39 {
40  public:
41  typedef enum
42  {
45  GRS80
47 
57  GeoCoordinate(double latitude,
58  double longitude,
59  double altitude,
60  bool correctIfInvalid = false);
61 
71  GeoCoordinate(double latitude,
72  double longitude,
73  double altitude,
74  ReferenceEllipsoid_t refEllipsoid,
75  bool correctIfInvalid = false);
76 
82  GeoCoordinate(Vector vector);
83 
90  GeoCoordinate(Vector vector, ReferenceEllipsoid_t refEllipsoid);
91 
96  GeoCoordinate();
97 
104  {
105  return m_refEllipsoid;
106  }
107 
113  double GetLongitude() const;
119  double GetLatitude() const;
125  double GetAltitude() const;
131  void SetLongitude(double longitude);
137  void SetLatitude(double latitude);
143  void SetAltitude(double altitude);
148  Vector ToVector() const;
149 
150  // Definitions for reference Earth Ellipsoid parameters.
151  // Sphere, WGS84 and GRS80 reference ellipsoides supported.
152 
153  // length (in meters) for semi-minor axis A. (same for all reference ellipsoides)
154  static constexpr double equatorRadius = 6378137.0;
155 
156  // length (in meters) for semi-minor axis B
157  static constexpr double polarRadius_sphere = 6378137.0; // Sphere
158  static constexpr double polarRadius_wgs84 = 6356752.314245; // WGS84 ellipsoide
159  static constexpr double polarRadius_grs80 = 6356752.314103; // GRS80 ellipsoide
160 
161  private:
167  double GetRadiusCurvature(double latitude) const;
168 
175  static inline bool IsValidLongitude(double longitude)
176  {
177  return (longitude >= -180 && longitude <= 180);
178  }
179 
186  static inline bool IsValidLatitude(double latitude)
187  {
188  return (latitude >= -90 && latitude <= 90);
189  }
190 
198  static inline bool IsValidAltitude(double altitude, ReferenceEllipsoid_t refEllipsoide);
204  void ConstructFromVector(const Vector& vector);
205 
222  void Construct(double latitude, double longitude, double altitude, bool correctIfInvalid);
223 
228  void Initialize();
229 
233  double m_latitude;
237  double m_longitude;
241  double m_altitude;
242 
243  ReferenceEllipsoid_t m_refEllipsoid; // reference ellipsoid
244  double m_e2Param; // First eccentricity squared
245  double m_equatorRadius; // Semi-major axis A, meters
246  double m_polarRadius; // Semi-major axis B, meters
247 };
248 
254 
255 std::ostream& operator<<(std::ostream& os, const GeoCoordinate& coordinate);
256 std::istream& operator>>(std::istream& is, GeoCoordinate& coordinate);
257 
258 Ptr<const AttributeChecker> MakeGeoCoordinateChecker(void);
259 
260 } // namespace ns3
261 
262 #endif /* GEO_COORDINATE_H */
GeoCoordinate class is used to store and operate with geodetic coordinates.
static constexpr double polarRadius_grs80
void SetAltitude(double altitude)
Sets altitude value of coordinate.
ReferenceEllipsoid_t m_refEllipsoid
void SetLatitude(double latitude)
Sets latitude value of coordinate.
static constexpr double polarRadius_wgs84
static bool IsValidAltitude(double altitude, ReferenceEllipsoid_t refEllipsoide)
Checks if altitude is in valid range.
double m_altitude
altitude of coordinate
double GetAltitude() const
Gets altitude value of coordinate.
void SetLongitude(double longitude)
Sets longitude value of coordinate.
double GetLatitude() const
Gets latitude value of coordinate.
void Initialize()
This method is called to initialize needed parameters according to used reference ellipsoide.
ReferenceEllipsoid_t GetRefEllipsoid()
Gets reference ellipsoid used by GeoCoordinate object.
GeoCoordinate()
Create GeoCoordinate with zero values of longitude, latitude and altitude.
static bool IsValidLongitude(double longitude)
Checks if longitude is in valid range.
double GetLongitude() const
Gets longitude value of coordinate.
static bool IsValidLatitude(double latitude)
Checks if latitude is in valid range.
Vector ToVector() const
Converts Geodetic coordinates to Cartesian coordinates.
void ConstructFromVector(const Vector &vector)
Creates Geodetic coordinates from given Cartesian coordinates.
double m_latitude
latitude of coordinate
double GetRadiusCurvature(double latitude) const
Gets the radius of curvature in the prime vertical.
static constexpr double equatorRadius
double m_longitude
longitude of coordinate
void Construct(double latitude, double longitude, double altitude, bool correctIfInvalid)
static constexpr double polarRadius_sphere
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
std::istream & operator>>(std::istream &is, GeoCoordinate &coordinate)
std::ostream & operator<<(std::ostream &os, const GeoCoordinate &coordinate)
ATTRIBUTE_HELPER_HEADER(GeoCoordinate)
Ptr< const AttributeChecker > MakeGeoCoordinateChecker(void)