MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Coords.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
3 /***********************************************************************************/
4 /* This file is part of MeteoIO.
5  MeteoIO is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  MeteoIO is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef COORDS_H
19 #define COORDS_H
20 
21 #include <string>
22 #include <iostream>
23 
24 namespace mio {
81 class Coords {
82 public:
84  typedef enum GEO_DISTANCES {
87  } geo_distances;
88 
90  typedef enum {
92  FULL,
95  } FORMATS;
96 
97  //Constructors
98  Coords();
99  Coords(const std::string& in_coordinatesystem, const std::string& in_parameters="");
100  Coords(const std::string& in_coordinatesystem, const std::string& in_parameters, const std::string& coord_spec);
101  Coords(const double& in_lat_ref, const double& in_long_ref);
102  Coords(const Coords& c);
103 
104  //Operators
105  Coords& operator=(const Coords&);
106  bool operator==(const Coords&) const;
107  bool operator!=(const Coords&) const;
108  bool isNodata() const;
109  void moveByXY(const double& x_displacement, const double& y_displacement);
110  void moveByBearing(const double& i_bearing, const double& i_distance);
111 
112  static Coords merge(const Coords& coord1, const Coords& coord2);
113  void merge(const Coords& coord2);
114 
115  //Getter methods
116  double getEasting() const;
117  double getNorthing() const;
118  double getLat() const;
119  double getLon() const;
120  double getAltitude() const;
121  int getGridI() const;
122  int getGridJ() const;
123  int getGridK() const;
124  bool indexIsValid() const;
125  void getProj(std::string& proj_type, std::string& proj_args) const;
126  short int getEPSG() const;
127 
128  const std::string toString(const FORMATS& type = DEBUG) const;
129  friend std::iostream& operator<<(std::iostream& os, const Coords& coord);
130  friend std::iostream& operator>>(std::iostream& is, Coords& coord);
131 
132  //Setter methods
133  void setLatLon(const double in_latitude, const double in_longitude, const double in_altitude, const bool in_update=true);
134  void setLatLon(const std::string& in_coordinates, const double in_altitude, const bool in_update=true);
135  void setXY(const double in_easting, const double in_northing, const double in_altitude, const bool in_update=true);
136  void setGridIndex(const int in_grid_i, const int in_grid_j, const int in_grid_k, const bool setValid=false);
137  void setAltitude(const double in_altitude, const bool in_update=true);
138  void setProj(const std::string& in_coordinatesystem, const std::string& in_parameters="");
139  void setLocalRef(const double in_ref_latitude, const double in_ref_longitude);
140  void setLocalRef(const std::string in_coordparam);
141  void setDistances(const geo_distances in_algo);
142  void setEPSG(const int& epsg);
143 
144  void check();
145  double distance(const Coords& destination) const;
146  bool isSameProj(const Coords& target) const;
147  void copyProj(const Coords& source, const bool i_update=true);
148 
149  private:
150  //Coordinates conversions
151  void convert_to_WGS84(double i_easting, double i_northing, double& o_latitude, double& o_longitude) const;
152  void convert_from_WGS84(double i_latitude, double i_longitude, double& o_easting, double& o_northing) const;
153 
154  void WGS84_to_local(double lat_in, double long_in, double& east_out, double& north_out) const;
155  void local_to_WGS84(double east_in, double north_in, double& lat_out, double& long_out) const;
156  void WGS84_to_NULL(double lat_in, double long_in, double& east_out, double& north_out) const;
157  void NULL_to_WGS84(double east_in, double north_in, double& lat_out, double& long_out) const;
158 
159  //Distances calculations
160  void distance(const Coords& destination, double& o_distance, double& o_bearing) const;
161 
162  private:
163  void clearCoordinates();
164  void setDefaultValues();
165 
166  private:
167  double ref_latitude, ref_longitude;
168  double altitude;
169  double latitude;
170  double longitude;
171  double easting;
172  double northing;
173  int grid_i;
174  int grid_j;
175  int grid_k;
176  bool validIndex;
177 
178  std::string coordsystem;
179  std::string coordparam;
180  geo_distances distance_algo;
181 };
182 } //end namespace
183 
184 #endif
int getGridJ() const
Returns the grid index along the Y axis.
Definition: Coords.cc:450
void setXY(const double in_easting, const double in_northing, const double in_altitude, const bool in_update=true)
Set easting and northing The automatic update of the latitude/longitude can be turned off so that bot...
Definition: Coords.cc:541
bool operator==(const Coords &) const
Operator that tests for equality.
Definition: Coords.cc:78
FORMATS
Keywords for selecting the toString formats.
Definition: Coords.h:90
bool isSameProj(const Coords &target) const
Check if two Coords object are using the same projection.
Definition: Coords.cc:731
Simplified, lat/lon only.
Definition: Coords.h:93
double getLat() const
Returns the Latitude in the configured projection system.
Definition: Coords.cc:418
As much information as possible, useful for debugging.
Definition: Coords.h:91
static Coords merge(const Coords &coord1, const Coords &coord2)
Simple merge strategy. If some fields of the first argument are empty, they will be filled by the mat...
Definition: Coords.cc:177
double getAltitude() const
Returns the Altitude. This is currently independent of the configured projection system.
Definition: Coords.cc:434
Coords()
Default constructor This constructor builds a dummy object that performs no conversions but can be us...
Definition: Coords.cc:317
void setLocalRef(const double in_ref_latitude, const double in_ref_longitude)
Set the local projection reference coordinates This projection will be used for converting between la...
Definition: Coords.cc:645
A class to handle geographic coordinate systems. This class offers an easy way to transparently conve...
Definition: Coords.h:81
int getGridK() const
Returns the grid index along the Z axis.
Definition: Coords.cc:458
void setGridIndex(const int in_grid_i, const int in_grid_j, const int in_grid_k, const bool setValid=false)
Set grid indices This index represent the position in a cartesian grid. It can not be automatically m...
Definition: Coords.cc:572
const std::string toString(const FORMATS &type=DEBUG) const
Print the content of the Coords object (usefull for debugging) The Coords is bound by "<Coords>" and ...
Definition: Coords.cc:225
Spherical law of cosine (See http://www.movable-type.co.uk/scripts/latlong.html)
Definition: Coords.h:85
void setProj(const std::string &in_coordinatesystem, const std::string &in_parameters="")
Set projection to use This projection will be used for converting between lat/lon and East/North (see...
Definition: Coords.cc:604
Compact representation only containing the X/Y and I/J coordinates.
Definition: Coords.h:94
double getLon() const
Returns the Latitude in the configured projection system.
Definition: Coords.cc:426
int getGridI() const
Returns the grid index along the X axis.
Definition: Coords.cc:442
void check()
Check consistency of coordinates When both latitude/longitude and easting/northing are given...
Definition: Coords.cc:689
friend std::iostream & operator<<(std::iostream &os, const Coords &coord)
Definition: Coords.cc:263
void setDistances(const geo_distances in_algo)
Set the algorithm to use to compute distances Various algorithm exist that offer various precision/co...
Definition: Coords.cc:674
void setLatLon(const double in_latitude, const double in_longitude, const double in_altitude, const bool in_update=true)
Set latitude and longitude The automatic update of the easting/northing can be turned off so that bot...
Definition: Coords.cc:511
void setAltitude(const double in_altitude, const bool in_update=true)
Set altitude at a given value. If the i,j,k indices were set, reset them to inodata, except if specified otherwise with in_update=false.
Definition: Coords.cc:590
bool isNodata() const
move the point by the specified distance (in m) along easting and northing
Definition: Coords.cc:135
double getNorthing() const
Returns the North coordinate in the configured projection system.
Definition: Coords.cc:410
void moveByXY(const double &x_displacement, const double &y_displacement)
move the point by the specified bearing and distance (in m)
Definition: Coords.cc:147
bool indexIsValid() const
Returns true if the (i,j,k) index are valid.
Definition: Coords.cc:466
friend std::iostream & operator>>(std::iostream &is, Coords &coord)
Definition: Coords.cc:287
void setEPSG(const int &epsg)
set the current projection to a given EPSG-defined projection
Definition: Coords.cc:780
double getEasting() const
Returns the East coordinate in the configured projection system.
Definition: Coords.cc:402
geo_distances
Keywords for selecting the algorithm for computing geodesic distances.
Definition: Coords.h:84
Coords & operator=(const Coords &)
Assignement operator.
Definition: Coords.cc:115
Vincenty ellispoid formula (See T. Vincenty, "Closed formulas for the direct and reverse geodetic pro...
Definition: Coords.h:86
double distance(const Coords &destination) const
Calculate the distance between two points.
Definition: Coords.cc:720
void moveByBearing(const double &i_bearing, const double &i_distance)
Definition: Coords.cc:152
void getProj(std::string &proj_type, std::string &proj_args) const
Returns the projection parameters.
Definition: Coords.cc:475
bool operator!=(const Coords &) const
Operator that tests for inequality.
Definition: Coords.cc:111
Provide all the usually necessary information.
Definition: Coords.h:92
short int getEPSG() const
returns the epsg code of the current projection
Definition: Coords.cc:771
void copyProj(const Coords &source, const bool i_update=true)
Copy the projection parameters of another Coords object.
Definition: Coords.cc:744