MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoordsAlgorithms.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 COORDSALGORITHMS_H
19 #define COORDSALGORITHMS_H
20 
21 #include <string>
22 
23 namespace mio {
35 class CoordsAlgorithms {
36 public:
37  //Handling of lat/lon
38  static double dms_to_decimal(const std::string& dms);
39  static std::string decimal_to_dms(const double& decimal);
40  static void parseLatLon(const std::string& coordinates, double& lat, double& lon);
41  static std::string printLatLon(const double& latitude, const double& longitude);
42  static double lat_degree_lenght(const double& latitude);
43  static double lon_degree_lenght(const double& latitude);
44 
45  //EPSG helper methods
46  static short int str_to_EPSG(const std::string& coordsystem, const std::string& coordparam);
47  static void EPSG_to_str(const int& epsg, std::string& coordsystem, std::string& coordparam);
48 
49  //handling of rotated coordinates
50  static void rotatedToTrueLatLon(const double& lat_N, const double& lon_N, const double& lat_rot, const double& lon_rot, double &lat_true, double &lon_true);
51  static void trueLatLonToRotated(const double& lat_N, const double& lon_N, const double& lat_true, const double& lon_true, double &lat_rot, double &lon_rot);
52 
53  //handling of distances on a sphere
54  static double cosineDistance(const double& lat1, const double& lon1, const double& lat2, const double& lon2, double& alpha);
55  static void cosineInverse(const double& lat_ref, const double& lon_ref, const double& distance, const double& bearing, double& lat, double& lon);
56  static double VincentyDistance(const double& lat1, const double& lon1, const double& lat2, const double& lon2, double& alpha);
57  static void VincentyInverse(const double& lat_ref, const double& lon_ref, const double& distance, const double& bearing, double& lat, double& lon);
58 
59  //Coordinates conversions
60  static void WGS84_to_CH1903(const double& lat_in, const double& long_in, double& east_out, double& north_out);
61  static void CH1903_to_WGS84(const double& east_in, const double& north_in, double& lat_out, double& long_out);
62  static void WGS84_to_UTM(const double& lat_in, double long_in, const std::string& coordparam, double& east_out, double& north_out);
63  static void UTM_to_WGS84(double east_in, double north_in, const std::string& coordparam, double& lat_out, double& long_out);
64  static void WGS84_to_UPS(const double& lat_in, const double& long_in, const std::string& coordparam, double& east_out, double& north_out);
65  static void UPS_to_WGS84(const double& east_in, const double& north_in, const std::string& coordparam, double& lat_out, double& long_out);
66  static void WGS84_to_PROJ4(const double& lat_in, const double& long_in, const std::string& coordparam, double& east_out, double& north_out);
67  static void PROJ4_to_WGS84(const double& east_in, const double& north_in, const std::string& coordparam, double& lat_out, double& long_out);
68 
69  private:
70  static int getUTMZone(const double& latitude, const double& longitude, std::string& zone_out);
71  static void parseUTMZone(const std::string& zone_info, char& zoneLetter, short int& zoneNumber);
72 
73  private:
75  enum ELLIPSOIDS_NAMES {
76  E_WGS84,
77  E_GRS80,
78  E_AIRY,
79  E_INTL1924,
80  E_CLARKE1880,
81  E_GRS67
82  };
83  struct ELLIPSOID {
84  double a;
85  double b;
86  };
87  static const struct ELLIPSOID ellipsoids[6];
88 };
89 } //end namespace
90 
91 #endif
static void parseLatLon(const std::string &coordinates, double &lat, double &lon)
Parse a latitude-longitude pair It can be formatted as any of the following examples: ...
Definition: CoordsAlgorithms.cc:111
static void WGS84_to_PROJ4(const double &lat_in, const double &long_in, const std::string &coordparam, double &east_out, double &north_out)
Coordinate conversion: from WGS84 Lat/Long to proj4 parameters.
Definition: CoordsAlgorithms.cc:738
static void WGS84_to_CH1903(const double &lat_in, const double &long_in, double &east_out, double &north_out)
Coordinate conversion: from WGS84 Lat/Long to Swiss grid See http://geomatics.ladetto.ch/ch1903_wgs84_de.pdf for more.
Definition: CoordsAlgorithms.cc:360
static void CH1903_to_WGS84(const double &east_in, const double &north_in, double &lat_out, double &long_out)
Coordinate conversion: from Swiss grid to WGS84 Lat/Long See http://geomatics.ladetto.ch/ch1903_wgs84_de.pdf for more.
Definition: CoordsAlgorithms.cc:396
static void EPSG_to_str(const int &epsg, std::string &coordsystem, std::string &coordparam)
Build the string representation for a given EPSG code.
Definition: CoordsAlgorithms.cc:302
static double lat_degree_lenght(const double &latitude)
Lenght of one degree of latitude This returns the lenght in meters of one degree of latitude around t...
Definition: CoordsAlgorithms.cc:157
static short int str_to_EPSG(const std::string &coordsystem, const std::string &coordparam)
returns the epsg code matching a provided string representation For example, when given "CH1903" with...
Definition: CoordsAlgorithms.cc:255
static double dms_to_decimal(const std::string &dms)
Parse a latitude or longitude It can be formatted as any of the following examples: ...
Definition: CoordsAlgorithms.cc:70
static void UTM_to_WGS84(double east_in, double north_in, const std::string &coordparam, double &lat_out, double &long_out)
Coordinate conversion: from UTM grid to WGS84 Lat/Long See http://www.oc.nps.edu/oc2902w/maps/utmups...
Definition: CoordsAlgorithms.cc:553
static void PROJ4_to_WGS84(const double &east_in, const double &north_in, const std::string &coordparam, double &lat_out, double &long_out)
Coordinate conversion: from proj4 parameters to WGS84 Lat/Long.
Definition: CoordsAlgorithms.cc:784
static void cosineInverse(const double &lat_ref, const double &lon_ref, const double &distance, const double &bearing, double &lat, double &lon)
Spherical law of cosine Distance calculation between points in WGS84 (decimal Lat/Long) See http://ww...
Definition: CoordsAlgorithms.cc:832
static void UPS_to_WGS84(const double &east_in, const double &north_in, const std::string &coordparam, double &lat_out, double &long_out)
Coordinate conversion: from Universal Polar Stereographic grid to WGS84 Lat/Long see J...
Definition: CoordsAlgorithms.cc:656
static double lon_degree_lenght(const double &latitude)
Lenght of one degree of longitude This returns the lenght in meters of one degree of longitude around...
Definition: CoordsAlgorithms.cc:173
static void rotatedToTrueLatLon(const double &lat_N, const double &lon_N, const double &lat_rot, const double &lon_rot, double &lat_true, double &lon_true)
Convert rotated lat/lon into geographic lat/lon Rotated coordinates are created by moving the North p...
Definition: CoordsAlgorithms.cc:196
static std::string decimal_to_dms(const double &decimal)
Converts a decimal latitude or longitude to degrees, minutes, seconds It formats its arguments as in ...
Definition: CoordsAlgorithms.cc:137
static void WGS84_to_UTM(const double &lat_in, double long_in, const std::string &coordparam, double &east_out, double &north_out)
Coordinate conversion: from WGS84 Lat/Long to UTM grid See http://www.oc.nps.edu/oc2902w/maps/utmups...
Definition: CoordsAlgorithms.cc:488
static void trueLatLonToRotated(const double &lat_N, const double &lon_N, const double &lat_true, const double &lon_true, double &lat_rot, double &lon_rot)
Convert geographic lat/lon into rotated lat/lon Rotated coordinates are created by moving the North p...
Definition: CoordsAlgorithms.cc:228
double bearing(std::string bearing_str)
Converts a string bearing to a compass bearing.
Definition: IOUtils.cc:70
static std::string printLatLon(const double &latitude, const double &longitude)
Print a nicely formatted lat/lon in degrees, minutes, seconds.
Definition: CoordsAlgorithms.cc:48
static void VincentyInverse(const double &lat_ref, const double &lon_ref, const double &distance, const double &bearing, double &lat, double &lon)
Vincenty Inverse calculation giving WGS84 (decimal Lat/Long) position given a start location (lat...
Definition: CoordsAlgorithms.cc:969
static void WGS84_to_UPS(const double &lat_in, const double &long_in, const std::string &coordparam, double &east_out, double &north_out)
Coordinate conversion: from WGS84 Lat/Long to Universal Polar Stereographic grid see J...
Definition: CoordsAlgorithms.cc:622
static double VincentyDistance(const double &lat1, const double &lon1, const double &lat2, const double &lon2, double &alpha)
Vincenty Distance calculation between points in WGS84 (decimal Lat/Long) See T. Vincenty, "Closed formulas for the direct and reverse geodetic problems", Journal of Geodesy, 51, 3, 1977, DOI:10.1007/BF02521599, see http://www.springerlink.com/content/y7108u6862473583 for more.
Definition: CoordsAlgorithms.cc:897
static double cosineDistance(const double &lat1, const double &lon1, const double &lat2, const double &lon2, double &alpha)
Spherical law of cosine Distance calculation between points in WGS84 (decimal Lat/Long) See http://ww...
Definition: CoordsAlgorithms.cc:864