vpgl_lvcs.h
Go to the documentation of this file.
1 #ifndef vpgl_lvcs_h_
2 #define vpgl_lvcs_h_
3 //-----------------------------------------------------------------------------
4 //:
5 // \file
6 // \brief A geographic coordinate system
7 // \author J. L. Mundy
8 // \date December 31, 2005
9 //
10 // lvcs is used to convert between a local vertical coordinate system
11 // any of the many Earth global coordinate systems. In the full
12 // constructor the user can establish the geographic coordinates of
13 // the origin and define which standard geo-coordinate system is to
14 // be used, e.g. wgs84. The full constructor allows the specification
15 // of latitude and longitude scale factors in radians/meter. If these
16 // scale factors are set to 0, then they will be computed using the
17 // location of the origin on the Earth's surface and the geoid
18 // specification.
19 //
20 // original authors (c. 1992)
21 // Rajiv Gupta and Bill Hoffman
22 // with modifications by Rupert Curwen (1996)
23 // GE Corporate Research and Development
24 //
25 //
26 // \verbatim
27 // Modifications
28 // Ozge C. Ozcanli July 28 2012: added option to use UTM projection planes as local coordinate system
29 // origin point is still given in wgs84,
30 // but it is converted to utm origin during local to global transformations and vice versa
31 // all the global coords are still either in wgs84, nad27n or wgs72
32 // if a utm zone is crossed
33 // Yi Dong July 31, 2013: fix the local_to_global method to correctly transfer the local cooridinates to global wgs84 coords
34 // for points located in southern hemisphere. Note that the input point needs to be at the same hemisphere
35 // as the lvcs origin
36 //
37 // \endverbatim
38 /////////////////////////////////////////////////////////////////////////////
39 #include <iostream>
40 #ifdef _MSC_VER
41 # include <vcl_msvc_warnings.h>
42 #endif
43 #include <vsl/vsl_binary_io.h>
44 #include <vbl/vbl_ref_count.h>
45 //#include <vpgl/vpgl_dll.h>
46 #include <vpgl/vpgl_export.h>
47 
48 class vpgl_lvcs : public vbl_ref_count
49 {
50  // PUBLIC INTERFACE----------------------------------------------------------
51 
52  public:
53  enum LenUnits {FEET, METERS};
54  enum AngUnits {RADIANS, DEG};
56  static VPGL_EXPORT const char* cs_name_strings[];
57  static vpgl_lvcs::cs_names str_to_enum(const char*);
58  // Constructors/Initializers/Destructors-------------------------------------
59  vpgl_lvcs(double orig_lat=0, //!< latitude of LVCS orig in radians.
60  double orig_lon=0, //!< longitude of LVCS orig in radians.
61  double orig_elev=0, //!< elev of orig LVCS in radians.
62  cs_names cs_name=wgs84, //!< nad27n, wgs84, wgs72 or utm
63  double lat_scale=0, //!< radians/meter along lat (custom geoid)
64  double lon_scale=0, //!< radians/meter along lon (custom geoid)
65  AngUnits ang_unit = DEG, //!< angle units
66  LenUnits len_unit=METERS, //!< input in LVCS in these length units.
67  double lox=0, //!< Origin in local co-ordinates.
68  double loy=0, //!< Origin in local co-ordinates.
69  double theta=0); //!< Radians from y axis to north in local co-ordinates.
70 
71  vpgl_lvcs(double orig_lat,
72  double orig_lon,
73  double orig_elev, //!< simplified interface
74  cs_names cs_name,
75  AngUnits ang_unit = DEG,
76  LenUnits len_unit=METERS);
77 
78  vpgl_lvcs(double lat_low, double lon_low, //!< lower corner bounding geo_rectangle
79  double lat_high, double lon_high,//!< upper corner bounding geo_rectangle
80  double elev, //!< elevation of all rectangle corners
81  cs_names cs_name=wgs84,
82  AngUnits ang_unit=DEG, LenUnits elev_unit=METERS);
83 
84  vpgl_lvcs(const vpgl_lvcs&);
85  vpgl_lvcs& operator=(const vpgl_lvcs&);
86 
87 
88  // Utility Methods-----------------------------------------------------------
89  void local_to_global(const double lx, const double ly, const double lz,
90  cs_names cs_name, // this is output global cs
91  double& lon, double& lat, double& gz,
92  AngUnits output_ang_unit=DEG,
93  LenUnits output_len_unit=METERS);
94 
95  void global_to_local(const double lon, const double lat, const double gz,
96  cs_names cs_name, // this is input global cs
97  double& lx, double& ly, double& lz,
98  AngUnits output_ang_unit=DEG,
99  LenUnits output_len_unit=METERS);
100 
101  void radians_to_degrees(double& lon, double& lat, double& z);
102  double radians_to_degrees(const double val);
103  void degrees_to_dms(double, int& degrees, int& minutes, double& seconds);
104  void radians_to_dms(double, int& degrees, int& minutes, double& seconds);
105  // uses the units defined for *this lvcs, e.g. deg and meters. computes cartesian vector (p1 - p0)
106  void angle_diff_to_cartesian_vector(const double lon0, const double lat0, const double lon1, const double lat1,
107  double& cart_dx, double& cart_dy) {
108  double l0x, l0y, l0z, l1x, l1y, l1z;
109  this->global_to_local(lon0, lat0, 0.0, local_cs_name_, l0x, l0y, l0z);
110  this->global_to_local(lon1, lat1, 0.0, local_cs_name_, l1x, l1y, l1z);
111  cart_dx = l1x-l0x;
112  cart_dy = l1y-l0y;
113 }
114 
115  // accessors
116  void get_origin(double& lat, double& lon, double& elev) const;
117  void get_scale(double& lat, double& lon) const;
118  void get_transform(double& lox, double& loy, double& theta) const;
119  void set_transform(const double lox, const double loy, const double theta);
120  void set_origin(const double lon, const double lat, const double elev);
121  cs_names get_cs_name() const;
122  inline LenUnits local_length_unit() const{return this->localXYZUnit_;}
123  inline AngUnits geo_angle_unit() const {return this->geo_angle_unit_;}
124  void print(std::ostream&) const;
125  bool save(std::string fname) { std::ofstream of(fname.c_str()); if (of) { print(of); return true; } return false; }
126  void read(std::istream& strm);
127  void write(std::ostream& strm); // write just "read" would read
128  friend std::ostream& operator << (std::ostream& os, const vpgl_lvcs& local_coord_sys);
129  friend std::istream& operator >> (std::istream& os, vpgl_lvcs& local_coord_sys);
130  bool operator==(vpgl_lvcs const& r) const;
131 
132  void get_utm_origin(double& x, double& y, double& elev, int& zone) const;
133 
134  //: Binary save self to stream.
135  void b_write(vsl_b_ostream &os) const;
136 
137  //: Binary load self from stream.
138  void b_read(vsl_b_istream &is);
139 
140  //: Return IO version number;
141  short version() const { return 1; }
142 
143 
144  // INTERNALS-----------------------------------------------------------------
145 
146  protected:
147  void compute_scale();
148  void local_transform(double& x, double& y);
149  void inverse_local_transform(double& x, double& y);
150  void set_angle_conversions(AngUnits ang_unit, double& to_radians,
151  double& to_degrees);
152  void set_length_conversions(LenUnits len_unit, double& to_meters,
153  double& to_feet);
154  private:
155 
156  // Data Members--------------------------------------------------------------
157 
158  protected:
159  cs_names local_cs_name_; //!< Name of local frame's coord system ("nad27n", "wgs84" etc.)
160  double localCSOriginLat_; //!< Lat (in geo_angle_unit_) of the origin
161  double localCSOriginLon_; //!< Lon (in geo_angle_unit_) of the origin
162  double localCSOriginElev_; //!< Elev (in localXYZUnit_) of the origin
163  double lat_scale_; //!< radians/meter along lat at the origin)
164  double lon_scale_; //!< radians/meter along lon at the origin)
165  AngUnits geo_angle_unit_; //!< lat lon angle unit (degrees or radians)
166  LenUnits localXYZUnit_; //!< Input (x,y,z) unit (meters or feet) in local CS
167  double lox_; //!< Origin in local co-ordinates.
168  double loy_; //!< Origin in local co-ordinates.
169  double theta_; //!< Direction of north in radians.
170 
171  double localUTMOrigin_X_East_; // in meters
172  double localUTMOrigin_Y_North_; // in meters
174 };
175 
176 //: return the scale for lat lon and elevation
177 inline void vpgl_lvcs::get_scale(double& lat, double& lon) const
178 {
179  lat = lat_scale_;
180  lon = lon_scale_;
181 }
182 
183 //: return the coordinate system
185 { return local_cs_name_; }
186 
187 
188 //: return the origin of the local system
189 inline void vpgl_lvcs::get_origin(double& lat, double& lon, double& elev) const
190 {
191  lat = localCSOriginLat_;
192  lon = localCSOriginLon_;
193  elev = localCSOriginElev_;
194 }
195 
196 inline void vpgl_lvcs::get_utm_origin(double& x, double& y, double& elev, int& zone) const
197 {
200  zone = localUTMOrigin_Zone_;
201  elev = localCSOriginElev_;
202 }
203 
204 //------------------------------------------------------------
205 //: Return the compass alignment transform.
206 inline void vpgl_lvcs::get_transform(double& lox, double& loy, double& theta) const
207 {
208  lox = lox_;
209  loy = loy_;
210  theta = theta_;
211 }
212 
213 //------------------------------------------------------------
214 //: Set the compass alignment transform.
215 inline void vpgl_lvcs::set_transform(const double lox, const double loy,
216  const double theta)
217 {
218  lox_ = lox;
219  loy_ = loy;
220  theta_ = theta;
221 }
222 
223 //------------------------------------------------------------
224 //: Set the origin of the local system
225 inline void vpgl_lvcs::set_origin(const double lon, const double lat, const double elev)
226 {
227  localCSOriginLon_ = lon;
228  localCSOriginLat_ = lat;
229  localCSOriginElev_ = elev;
230 }
231 
232 inline void vpgl_lvcs::radians_to_dms(double rad, int& degrees, int& minutes, double& seconds)
233 {
234  degrees_to_dms(radians_to_degrees(rad), degrees, minutes, seconds);
235 }
236 #endif // vpgl_lvcs_h_
double localCSOriginLon_
Lon (in geo_angle_unit_) of the origin.
Definition: vpgl_lvcs.h:161
short version() const
Return IO version number;.
Definition: vpgl_lvcs.h:141
double localCSOriginElev_
Elev (in localXYZUnit_) of the origin.
Definition: vpgl_lvcs.h:162
AngUnits geo_angle_unit() const
Definition: vpgl_lvcs.h:123
void write(std::ostream &strm)
Definition: vpgl_lvcs.cxx:858
void radians_to_degrees(double &lon, double &lat, double &z)
Definition: vpgl_lvcs.cxx:201
void radians_to_dms(double, int &degrees, int &minutes, double &seconds)
Definition: vpgl_lvcs.h:232
void set_origin(const double lon, const double lat, const double elev)
Set the origin of the local system.
Definition: vpgl_lvcs.h:225
LenUnits local_length_unit() const
Definition: vpgl_lvcs.h:122
void local_to_global(const double lx, const double ly, const double lz, cs_names cs_name, double &lon, double &lat, double &gz, AngUnits output_ang_unit=DEG, LenUnits output_len_unit=METERS)
Converts pointin, given in local vertical coord system, to pointout in the global coord system given ...
Definition: vpgl_lvcs.cxx:350
double localUTMOrigin_Y_North_
Definition: vpgl_lvcs.h:172
void print(std::ostream &) const
Print internals on strm.
Definition: vpgl_lvcs.cxx:786
double localUTMOrigin_X_East_
Definition: vpgl_lvcs.h:171
void global_to_local(const double lon, const double lat, const double gz, cs_names cs_name, double &lx, double &ly, double &lz, AngUnits output_ang_unit=DEG, LenUnits output_len_unit=METERS)
Converts pointin, given in a global coord system described by global_cs_name, to pointout in the loca...
Definition: vpgl_lvcs.cxx:555
double theta_
Direction of north in radians.
Definition: vpgl_lvcs.h:169
void degrees_to_dms(double, int &degrees, int &minutes, double &seconds)
Definition: vpgl_lvcs.cxx:208
double loy_
Origin in local co-ordinates.
Definition: vpgl_lvcs.h:168
void set_length_conversions(LenUnits len_unit, double &to_meters, double &to_feet)
Definition: vpgl_lvcs.cxx:37
void b_write(vsl_b_ostream &os) const
Binary save self to stream.
Definition: vpgl_lvcs.cxx:974
bool save(std::string fname)
Definition: vpgl_lvcs.h:125
friend std::ostream & operator<<(std::ostream &os, const vpgl_lvcs &local_coord_sys)
Definition: vpgl_lvcs.cxx:944
double lox_
Origin in local co-ordinates.
Definition: vpgl_lvcs.h:167
void local_transform(double &x, double &y)
Transform from local co-ordinates to north=y,east=x.
Definition: vpgl_lvcs.cxx:890
LenUnits localXYZUnit_
Input (x,y,z) unit (meters or feet) in local CS.
Definition: vpgl_lvcs.h:166
friend std::istream & operator >>(std::istream &os, vpgl_lvcs &local_coord_sys)
Definition: vpgl_lvcs.cxx:950
void b_read(vsl_b_istream &is)
Binary load self from stream.
Definition: vpgl_lvcs.cxx:995
static vpgl_lvcs::cs_names str_to_enum(const char *)
Definition: vpgl_lvcs.cxx:18
double localCSOriginLat_
Lat (in geo_angle_unit_) of the origin.
Definition: vpgl_lvcs.h:160
void angle_diff_to_cartesian_vector(const double lon0, const double lat0, const double lon1, const double lat1, double &cart_dx, double &cart_dy)
Definition: vpgl_lvcs.h:106
vpgl_lvcs(double orig_lat=0, double orig_lon=0, double orig_elev=0, cs_names cs_name=wgs84, double lat_scale=0, double lon_scale=0, AngUnits ang_unit=DEG, LenUnits len_unit=METERS, double lox=0, double loy=0, double theta=0)
Radians from y axis to north in local co-ordinates.
Definition: vpgl_lvcs.cxx:91
void read(std::istream &strm)
Read internals from strm.
Definition: vpgl_lvcs.cxx:805
AngUnits geo_angle_unit_
lat lon angle unit (degrees or radians)
Definition: vpgl_lvcs.h:165
bool operator==(vpgl_lvcs const &r) const
Definition: vpgl_lvcs.cxx:956
double lat_scale_
radians/meter along lat at the origin)
Definition: vpgl_lvcs.h:163
void inverse_local_transform(double &x, double &y)
Transform from north=y,east=x aligned axes to local co-ordinates.
Definition: vpgl_lvcs.cxx:918
void get_scale(double &lat, double &lon) const
return the scale for lat lon and elevation.
Definition: vpgl_lvcs.h:177
cs_names local_cs_name_
Name of local frame's coord system ("nad27n", "wgs84" etc.)
Definition: vpgl_lvcs.h:159
vpgl_lvcs & operator=(const vpgl_lvcs &)
Definition: vpgl_lvcs.cxx:70
void set_angle_conversions(AngUnits ang_unit, double &to_radians, double &to_degrees)
Definition: vpgl_lvcs.cxx:26
void set_transform(const double lox, const double loy, const double theta)
Set the compass alignment transform.
Definition: vpgl_lvcs.h:215
double lon_scale_
radians/meter along lon at the origin)
Definition: vpgl_lvcs.h:164
void get_origin(double &lat, double &lon, double &elev) const
return the origin of the local system.
Definition: vpgl_lvcs.h:189
void get_utm_origin(double &x, double &y, double &elev, int &zone) const
Definition: vpgl_lvcs.h:196
void compute_scale()
Definition: vpgl_lvcs.cxx:220
void get_transform(double &lox, double &loy, double &theta) const
Return the compass alignment transform.
Definition: vpgl_lvcs.h:206
int localUTMOrigin_Zone_
Definition: vpgl_lvcs.h:173
static VPGL_EXPORT const char * cs_name_strings[]
Definition: vpgl_lvcs.h:56
cs_names get_cs_name() const
return the coordinate system.
Definition: vpgl_lvcs.h:184