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 #include <istream>
28 #include <ostream>
29 
30 namespace ns3
31 {
32 
42 {
43  public:
44  typedef enum
45  {
48  GRS80
50 
60  GeoCoordinate(double latitude,
61  double longitude,
62  double altitude,
63  bool correctIfInvalid = false);
64 
74  GeoCoordinate(double latitude,
75  double longitude,
76  double altitude,
77  ReferenceEllipsoid_t refEllipsoid,
78  bool correctIfInvalid = false);
79 
85  GeoCoordinate(Vector vector);
86 
93  GeoCoordinate(Vector vector, ReferenceEllipsoid_t refEllipsoid);
94 
99  GeoCoordinate();
100 
107  {
108  return m_refEllipsoid;
109  }
110 
116  double GetLongitude() const;
122  double GetLatitude() const;
128  double GetAltitude() const;
134  void SetLongitude(double longitude);
140  void SetLatitude(double latitude);
146  void SetAltitude(double altitude);
151  Vector ToVector() const;
152 
153  // Definitions for reference Earth Ellipsoid parameters.
154  // Sphere, WGS84 and GRS80 reference ellipsoides supported.
155 
156  // length (in meters) for semi-minor axis A. (same for all reference ellipsoides)
157  static constexpr double equatorRadius = 6378137.0;
158 
159  // length (in meters) for semi-minor axis B
160  static constexpr double polarRadius_sphere = 6378137.0; // Sphere
161  static constexpr double polarRadius_wgs84 = 6356752.314245; // WGS84 ellipsoide
162  static constexpr double polarRadius_grs80 = 6356752.314103; // GRS80 ellipsoide
163 
164  private:
170  double GetRadiusCurvature(double latitude) const;
171 
178  static inline bool IsValidLongitude(double longitude)
179  {
180  return (longitude >= -180 && longitude <= 180);
181  }
182 
189  static inline bool IsValidLatitude(double latitude)
190  {
191  return (latitude >= -90 && latitude <= 90);
192  }
193 
201  static inline bool IsValidAltitude(double altitude, ReferenceEllipsoid_t refEllipsoide);
207  void ConstructFromVector(const Vector& vector);
208 
225  void Construct(double latitude, double longitude, double altitude, bool correctIfInvalid);
226 
231  void Initialize();
232 
236  double m_latitude;
240  double m_longitude;
244  double m_altitude;
245 
246  ReferenceEllipsoid_t m_refEllipsoid; // reference ellipsoid
247  double m_e2Param; // First eccentricity squared
248  double m_equatorRadius; // Semi-major axis A, meters
249  double m_polarRadius; // Semi-major axis B, meters
250 };
251 
257 
258 std::ostream& operator<<(std::ostream& os, const GeoCoordinate& coordinate);
259 std::istream& operator>>(std::istream& is, GeoCoordinate& coordinate);
260 
261 Ptr<const AttributeChecker> MakeGeoCoordinateChecker(void);
262 
263 } // namespace ns3
264 
265 #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)