MeteoIODoc 20240429.aefd3c94
CoordsAlgorithms.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef COORDSALGORITHMS_H
20#define COORDSALGORITHMS_H
21
22#include <string>
23
24namespace mio {
36class CoordsAlgorithms {
37public:
51 NONE
52 };
53
54 //Handling of lat/lon
55 static double dms_to_decimal(const std::string& dms);
56 static std::string decimal_to_dms(const double& decimal);
57 static void parseLatLon(const std::string& coordinates, double& lat, double& lon);
58 static std::string printLatLon(const double& latitude, const double& longitude);
59 static double lat_degree_lenght(const double& latitude);
60 static double lon_degree_lenght(const double& latitude);
61
62 //EPSG helper methods
63 static bool isUTM(const int& epsg);
64 static short int str_to_EPSG(const std::string& coordsystem, const std::string& coordparam);
65 static void EPSG_to_str(const int& epsg, std::string& coordsystem, std::string& coordparam);
66
67 //handling of rotated coordinates and datum conversions
68 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);
69 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);
70 static void Molodensky(const double& lat_in, const double& lon_in, const double& alt_in, const ELLIPSOIDS_NAMES& ellipsoid_in,
71 double &lat_out, double &lon_out, double &alt_out, const ELLIPSOIDS_NAMES& ellipsoid_out,
72 const double& delta_x=0., const double& delta_y=0., const double& delta_z=0.);
73
74 //handling of distances on a sphere
75 static double cosineDistance(const double& lat1, const double& lon1, const double& lat2, const double& lon2, double& alpha);
76 static void cosineInverse(const double& lat_ref, const double& lon_ref, const double& distance, const double& bearing, double& lat, double& lon);
77 static double VincentyDistance(const double& lat1, const double& lon1, const double& lat2, const double& lon2, double& alpha);
78 static void VincentyInverse(const double& lat_ref, const double& lon_ref, const double& distance, const double& bearing, double& lat, double& lon);
79
80 //Coordinates conversions
81 static void WGS84_to_CH1903(const double& lat_in, const double& long_in, double& east_out, double& north_out);
82 static void CH1903_to_WGS84(const double& east_in, const double& north_in, double& lat_out, double& long_out);
83 static void WGS84_to_UTM(const double& lat_in, double long_in, const std::string& coordparam, double& east_out, double& north_out);
84 static void UTM_to_WGS84(double east_in, double north_in, const std::string& coordparam, double& lat_out, double& long_out);
85 static void WGS84_to_UPS(const double& lat_in, const double& long_in, const std::string& coordparam, double& east_out, double& north_out);
86 static void UPS_to_WGS84(const double& east_in, const double& north_in, const std::string& coordparam, double& lat_out, double& long_out);
87 static void WGS84_to_PROJ(const double& lat_in, const double& long_in, const std::string& coordparam, double& east_out, double& north_out);
88 static void PROJ_to_WGS84(const double& east_in, const double& north_in, const std::string& coordparam, double& lat_out, double& long_out);
89
90 static int getUTMZone(const double& latitude, const double& longitude, std::string& zone_out);
91 static void parseUTMZone(const std::string& zone_info, char& zoneLetter, short int& zoneNumber);
92
93 private:
94 struct ELLIPSOID {
95 double a;
96 double b;
97 };
98 static const struct ELLIPSOID ellipsoids[12];
99};
100} //end namespace
101
102#endif
double bearing(std::string bearing_str)
Converts a string bearing to a compass bearing.
Definition: IOUtils.cc:76
Definition: Config.cc:31
static void WGS84_to_PROJ(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 proj parameters.
Definition: CoordsAlgorithms.cc:820
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:1095
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,...
Definition: CoordsAlgorithms.cc:1023
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:143
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:990
ELLIPSOIDS_NAMES
Keywords for selecting an ellipsoid to use.
Definition: CoordsAlgorithms.h:39
@ E_KRASSOVSKY
Krassovsky 1940 ellipsoid, USSR, Russia, Romania.
Definition: CoordsAlgorithms.h:50
@ E_EVEREST1830
Everest1830 ellipsoid, used for India.
Definition: CoordsAlgorithms.h:48
@ E_GRS67
GRS67 ellispoid, good for South America.
Definition: CoordsAlgorithms.h:47
@ E_CLARKE1866
Clarke 1866, used for NAD27 (North America)
Definition: CoordsAlgorithms.h:46
@ E_INTL1924
International 1924 ellispoid, good for most of Europe.
Definition: CoordsAlgorithms.h:44
@ E_CLARKE1880
Clarke 1880, Africa and France.
Definition: CoordsAlgorithms.h:45
@ E_AIRY
Airy ellispoid, UK.
Definition: CoordsAlgorithms.h:43
@ E_WGS72
USA/DoD.
Definition: CoordsAlgorithms.h:41
@ NONE
spherical earth
Definition: CoordsAlgorithms.h:51
@ E_GRS80
GRS80 ellispoid, equivalent to WGS84 but used by America and Australia (NAD83)
Definition: CoordsAlgorithms.h:42
@ E_IERS2003
IERS2003 ellipsoid.
Definition: CoordsAlgorithms.h:49
@ E_WGS84
Globally usable WGS84 ellipsoid.
Definition: CoordsAlgorithms.h:40
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:234
static void parseUTMZone(const std::string &zone_info, char &zoneLetter, short int &zoneNumber)
Definition: CoordsAlgorithms.cc:792
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:79
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:703
static int getUTMZone(const double &latitude, const double &longitude, std::string &zone_out)
Definition: CoordsAlgorithms.cc:510
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:376
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: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 https://www.swisstopo....
Definition: CoordsAlgorithms.cc:443
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 https://www.swisstopo....
Definition: CoordsAlgorithms.cc:479
static void Molodensky(const double &lat_in, const double &lon_in, const double &alt_in, const ELLIPSOIDS_NAMES &ellipsoid_in, double &lat_out, double &lon_out, double &alt_out, const ELLIPSOIDS_NAMES &ellipsoid_out, const double &delta_x=0., const double &delta_y=0., const double &delta_z=0.)
Molodensky datum transformation. This converts lat/lon from one datum to another (for example,...
Definition: CoordsAlgorithms.cc:272
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. For more, see http://www.oc....
Definition: CoordsAlgorithms.cc:573
static std::string printLatLon(const double &latitude, const double &longitude)
Print a nicely formatted lat/lon in degrees, minutes, seconds.
Definition: CoordsAlgorithms.cc:57
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:163
static bool isUTM(const int &epsg)
Does a given epsg code describe UTM coordinates?
Definition: CoordsAlgorithms.cc:361
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:117
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. For more, see http://www.oc....
Definition: CoordsAlgorithms.cc:637
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:315
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:202
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:958
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:179
static void PROJ_to_WGS84(const double &east_in, const double &north_in, const std::string &coordparam, double &lat_out, double &long_out)
Coordinate conversion: from proj parameters to WGS84 Lat/Long.
Definition: CoordsAlgorithms.cc:888