MeteoIODoc 20251207.a703fe45
Environmental timeseries pre-processing
Loading...
Searching...
No Matches
Coords.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 COORDS_H
20#define COORDS_H
21
22#include <string>
23#include <iostream>
24#include <set>
25
26namespace mio {
83class Coords {
84 public:
86 typedef enum GEO_DISTANCES {
91
100
101 //Constructors
102 Coords();
103 Coords(const std::string& in_coordinatesystem, const std::string& in_parameters="");
104 Coords(const std::string& in_coordinatesystem, const std::string& in_parameters, std::string coord_spec);
105 Coords(const double& in_lat_ref, const double& in_long_ref);
106 Coords(const Coords& c);
107
108 //Operators
109 Coords& operator=(const Coords&);
110 bool operator==(const Coords&) const;
111 bool operator!=(const Coords&) const;
112 bool isNodata() const;
113 void moveByXY(const double& x_displacement, const double& y_displacement);
114 void moveByBearing(const double& i_bearing, const double& i_distance);
115
116 static Coords merge(const Coords& coord1, const Coords& coord2);
117 void merge(const Coords& coord2);
118
119 //Getter methods
120 double getEasting() const {return easting;}
121 double getNorthing() const {return northing;}
122 double getLat() const {return latitude;}
123 double getLon() const {return longitude;}
124 double getAltitude() const {return altitude;}
125 int getGridI() const {return grid_i;}
126 int getGridJ() const {return grid_j;}
127 int getGridK() const {return grid_k;}
128 bool indexIsValid() const {return validIndex;}
129 void getProj(std::string& proj_type, std::string& proj_args) const;
130 short int getEPSG() const;
131
132 const std::string toString(const FORMATS& type = DEBUG) const;
133 friend std::ostream& operator<<(std::ostream& os, const Coords& coord);
134 friend std::istream& operator>>(std::istream& is, Coords& coord);
135 bool operator<(const Coords& in) const;
136
137 //Setter methods
138 void setLatLon(const double in_latitude, const double in_longitude, const double in_altitude, const bool in_update=true);
139 void setLatLon(const std::string& in_coordinates, const double in_altitude, const bool in_update=true);
140 void setXY(const double in_easting, const double in_northing, const double in_altitude, const bool in_update=true);
141 void setPoint(const double in_x_or_lat, const double in_y_or_lon, const double in_altitude);
142 void setPoint(const double in_x_or_lat, const double in_y_or_lon, const double in_altitude, const int epsg);
143 void setGridIndex(const int in_grid_i, const int in_grid_j, const int in_grid_k, const bool setValid=false);
144 void setAltitude(const double in_altitude, const bool in_update=true);
145 void setProj(const std::string& in_coordinatesystem, const std::string& in_parameters="");
146 void setLocalRef(const double in_ref_latitude, const double in_ref_longitude);
147 void setLocalRef(const std::string in_coordparam);
148 void setDistances(const geo_distances in_algo);
149 void setEPSG(const int& epsg);
150
151 void check(const std::string& pre_msg="");
152 double distance(const Coords& destination) const;
153 bool isSameProj(const Coords& target) const;
154 void copyProj(const Coords& source, const bool i_update=true);
155
156 private:
157 //Coordinates conversions
158 void convert_to_WGS84(double i_easting, double i_northing, double& o_latitude, double& o_longitude) const;
159 void convert_from_WGS84(double i_latitude, double i_longitude, double& o_easting, double& o_northing) const;
160
161 void WGS84_to_local(double lat_in, double long_in, double& east_out, double& north_out) const;
162 void local_to_WGS84(double east_in, double north_in, double& lat_out, double& long_out) const;
163 void WGS84_to_NULL(double lat_in, double long_in, double& east_out, double& north_out) const;
164 void NULL_to_WGS84(double east_in, double north_in, double& lat_out, double& long_out) const;
165
166 //Distances calculations
167 void distance(const Coords& destination, double& o_distance, double& o_bearing) const;
168
169 private:
170 void clearCoordinates();
171 void setDefaultValues();
172 bool isConsistent() const;
173
174 private:
175 double ref_latitude, ref_longitude;
176 double altitude;
177 double latitude, longitude;
178 double easting, northing;
179 int grid_i, grid_j, grid_k;
180 bool validIndex;
181
182 std::string coordsystem, coordparam;
183 geo_distances distance_algo;
184
185 public:
186 static const std::set<int> latlon_epsgs;
187
188};
189} //end namespace
190
191#endif
A class to handle geographic coordinate systems. This class offers an easy way to transparently conve...
Definition Coords.h:83
int getGridI() const
Definition Coords.h:125
geo_distances
Keywords for selecting the algorithm for computing geodesic distances.
Definition Coords.h:86
@ GEO_VINCENTY
Vincenty ellispoid formula (See T. Vincenty, "Closed formulas for the direct and reverse geodetic pro...
Definition Coords.h:89
@ GEO_COSINE
Spherical law of cosine (See http://www.movable-type.co.uk/scripts/latlong.html)
Definition Coords.h:88
@ NONE
Not initialized.
Definition Coords.h:87
const std::string toString(const FORMATS &type=DEBUG) const
Print the content of the Coords object (useful for debugging) The Coords is bound by "<Coords>" and "...
Definition Coords.cc:254
static const std::set< int > latlon_epsgs
Definition Coords.h:186
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:702
void moveByBearing(const double &i_bearing, const double &i_distance)
Definition Coords.cc:175
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:658
Coords & operator=(const Coords &)
Assignement operator.
Definition Coords.cc:138
int getGridJ() const
Definition Coords.h:126
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:626
bool indexIsValid() const
Returns true if the (i,j,k) index are valid.
Definition Coords.h:128
bool operator<(const Coords &in) const
Comparison operator for sorting (as required by std::set)
Definition Coords.cc:122
double getLon() const
Definition Coords.h:123
double distance(const Coords &destination) const
Calculate the distance between two points.
Definition Coords.cc:807
short int getEPSG() const
returns the epsg code of the current projection
Definition Coords.cc:858
friend std::istream & operator>>(std::istream &is, Coords &coord)
Definition Coords.cc:322
FORMATS
Keywords for selecting the toString formats.
Definition Coords.h:93
@ DEBUG
As much information as possible, useful for debugging.
Definition Coords.h:94
@ FULL
Provide all the usually necessary information.
Definition Coords.h:95
@ CARTESIAN
Compact representation only containing the X/Y and I/J coordinates.
Definition Coords.h:98
@ XY
Simplified cartesian, only easting/northing.
Definition Coords.h:97
@ LATLON
Simplified, lat/lon only.
Definition Coords.h:96
double getAltitude() const
Definition Coords.h:124
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:560
bool isNodata() const
move the point by the specified distance (in m) along easting and northing
Definition Coords.cc:158
void setPoint(const double in_x_or_lat, const double in_y_or_lon, const double in_altitude)
Set coordinates based on the previously defined EPSG code If the EPSG code is 4326 (which represents ...
Definition Coords.cc:582
bool operator==(const Coords &) const
Operator that tests for equality.
Definition Coords.cc:80
friend std::ostream & operator<<(std::ostream &os, const Coords &coord)
Definition Coords.cc:298
void moveByXY(const double &x_displacement, const double &y_displacement)
move the point by the specified bearing and distance (in m)
Definition Coords.cc:170
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:731
void getProj(std::string &proj_type, std::string &proj_args) const
Returns the projection parameters.
Definition Coords.cc:494
bool isSameProj(const Coords &target) const
Check if two Coords object are using the same projection.
Definition Coords.cc:818
void check(const std::string &pre_msg="")
Check consistency of coordinates.
Definition Coords.cc:747
double getNorthing() const
Definition Coords.h:121
void setEPSG(const int &epsg)
set the current projection to a given EPSG-defined projection
Definition Coords.cc:867
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,...
Definition Coords.cc:644
void copyProj(const Coords &source, const bool i_update=true)
Copy the projection parameters of another Coords object.
Definition Coords.cc:831
double getLat() const
Definition Coords.h:122
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:202
bool operator!=(const Coords &) const
Operator that tests for inequality.
Definition Coords.cc:113
double getEasting() const
Definition Coords.h:120
int getGridK() const
Definition Coords.h:127
Coords()
Default constructor This constructor builds a dummy object that performs no conversions but can be us...
Definition Coords.cc:352
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:530
Definition Config.cc:34