WSL/SLF GitLab Repository

Commit 461b49bc authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Big cleanup on the Coords: all the coordinate systems support methods have...

Big cleanup on the Coords: all the coordinate systems support methods have been moved to a new CoordsAlgorithms static class. The "printlatlon()" method has been replaced by toString(Coords::LATLON).
parent 5a2bcf9b
......@@ -24,6 +24,7 @@
#include <meteoio/MathOptim.h>
#include <meteoio/Config.h> // to avoid forward declaration hell
#include <meteoio/dataClasses/MeteoData.h> // to avoid forward declaration hell
#include <meteoio/dataClasses/CoordsAlgorithms.h>
namespace mio {
......@@ -542,7 +543,7 @@ template<> bool convertString<Coords>(Coords& t, const std::string& str, std::io
(void)f;
double lat, lon;
try {
Coords::parseLatLon(s, lat, lon);
CoordsAlgorithms::parseLatLon(s, lat, lon);
} catch(const IOException&) {
return false;
}
......
......@@ -114,7 +114,7 @@ void Meteo2DInterpolator::interpolate(const Date& date, const DEMObject& dem, co
//Get grid from buffer if it exists
std::ostringstream grid_hash;
grid_hash << dem.llcorner.printLatLon() << " " << dem.getNx() << "x" << dem.getNy() << " @" << dem.cellsize << " " << date.toString(Date::ISO) << " " << param_name;
grid_hash << dem.llcorner.toString(Coords::LATLON) << " " << dem.getNx() << "x" << dem.getNy() << " @" << dem.cellsize << " " << date.toString(Date::ISO) << " " << param_name;
if (grid_buffer.get(result, grid_hash.str(), InfoString))
return;
......
......@@ -5,6 +5,7 @@ SET(dataClasses_sources
dataClasses/Grid2DObject.cc
dataClasses/Grid3DObject.cc
dataClasses/Date.cc
dataClasses/CoordsAlgorithms.cc
dataClasses/Coords.cc
dataClasses/DEMObject.cc
dataClasses/StationData.cc
......
This diff is collapsed.
......@@ -94,6 +94,7 @@ public:
typedef enum {
DEBUG, ///< As much information as possible, useful for debugging
FULL, ///< Provide all the usually necessary information
LATLON, ///< Simplified, lat/lon only
CARTESIAN ///< Compact representation only containing the X/Y and I/J coordinates
} FORMATS;
......@@ -125,7 +126,6 @@ public:
int getGridJ() const;
int getGridK() const;
void getProj(std::string& proj_type, std::string& proj_args) const;
std::string printLatLon() const;
short int getEPSG() const;
const std::string toString(const FORMATS& type = DEBUG) const;
......@@ -142,56 +142,29 @@ public:
void setLocalRef(const double in_ref_latitude, const double in_ref_longitude);
void setLocalRef(const std::string in_coordparam);
void setDistances(const geo_distances in_algo);
void setEPSG(const int epsg);
void setEPSG(const int& epsg);
void check();
double distance(const Coords& destination) const;
bool isSameProj(const Coords& target) const;
void copyProj(const Coords& source, const bool i_update=true);
//Static helper methods
static double dms_to_decimal(const std::string& dms);
static std::string decimal_to_dms(const double& decimal);
static void parseLatLon(const std::string& coordinates, double& lat, double& lon);
static double lat_degree_lenght(const double& latitude);
static double lon_degree_lenght(const double& latitude);
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);
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);
static double cosineDistance(const double& lat1, const double& lon1, const double& lat2, const double& lon2, double& alpha);
static void cosineInverse(const double& lat_ref, const double& lon_ref, const double& distance, const double& bearing, double& lat, double& lon);
static double VincentyDistance(const double& lat1, const double& lon1, const double& lat2, const double& lon2, double& alpha);
static void VincentyInverse(const double& lat_ref, const double& lon_ref, const double& distance, const double& bearing, double& lat, double& lon);
private:
//Coordinates conversions
void convert_to_WGS84(double i_easting, double i_northing, double& o_latitude, double& o_longitude) const;
void convert_from_WGS84(double i_latitude, double i_longitude, double& o_easting, double& o_northing) const;
void WGS84_to_CH1903(double lat_in, double long_in, double& east_out, double& north_out) const;
void CH1903_to_WGS84(double east_in, double north_in, double& lat_out, double& long_out) const;
void WGS84_to_UTM(double lat_in, double long_in, double& east_out, double& north_out) const;
void UTM_to_WGS84(double east_in, double north_in, double& lat_out, double& long_out) const;
void WGS84_to_UPS(double lat_in, double long_in, double& east_out, double& north_out) const;
void UPS_to_WGS84(double east_in, double north_in, double& lat_out, double& long_out) const;
void WGS84_to_PROJ4(double lat_in, double long_in, double& east_out, double& north_out) const;
void PROJ4_to_WGS84(double east_in, double north_in, double& lat_out, double& long_out) const;
void WGS84_to_local(double lat_in, double long_in, double& east_out, double& north_out) const;
void local_to_WGS84(double east_in, double north_in, double& lat_out, double& long_out) const;
void WGS84_to_NULL(double lat_in, double long_in, double& east_out, double& north_out) const;
void NULL_to_WGS84(double east_in, double north_in, double& lat_out, double& long_out) const;
void parseUTMZone(const std::string& zone_info, char& zoneLetter, short int& zoneNumber) const;
//Distances calculations
void distance(const Coords& destination, double& o_distance, double& o_bearing) const;
private:
void clearCoordinates();
void setDefaultValues();
int getUTMZone(const double latitude, const double longitude, std::string& zone_out) const;
private:
double ref_latitude, ref_longitude;
......@@ -207,21 +180,6 @@ public:
std::string coordsystem;
std::string coordparam;
geo_distances distance_algo;
///Keywords for selecting an ellipsoid to use
enum ELLIPSOIDS_NAMES {
E_WGS84, ///<Globally useable WGS84 ellipsoid
E_GRS80, ///<GRS80 ellispoid, equivalent to WGS84 but used by America and Australia
E_AIRY, ///<Airy ellispoid, good fit for the UK
E_INTL1924, ///<International 1924 ellispoid, good for most of Europe
E_CLARKE1880, ///<Clarke 1880, good for Africa
E_GRS67 ///<GRS67 ellispoid, good for South America
};
struct ELLIPSOID {
double a;
double b;
};
static const struct ELLIPSOID ellipsoids[6];
};
} //end namespace
......
This diff is collapsed.
/***********************************************************************************/
/* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
/***********************************************************************************/
/* This file is part of MeteoIO.
MeteoIO is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MeteoIO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __COORDSALGORITHMS_H__
#define __COORDSALGORITHMS_H__
#include <string>
namespace mio {
/**
* @class CoordsAlgorithms
* @brief A static class to handle geographic algorithms.
* This class offers methods to handle lat/lon coordinates, to transform lat/lon coordinates, to compute distances on a sphere or
* to convert between coordinate systems.
*
* @ingroup data_str
* @author Mathias Bavay
* @date 2015-09-22
*/
class CoordsAlgorithms {
public:
//Handling of lat/lon
static double dms_to_decimal(const std::string& dms);
static std::string decimal_to_dms(const double& decimal);
static void parseLatLon(const std::string& coordinates, double& lat, double& lon);
static std::string printLatLon(const double& latitude, const double& longitude);
static double lat_degree_lenght(const double& latitude);
static double lon_degree_lenght(const double& latitude);
//EPSG helper methods
static short int str_to_EPSG(const std::string& coordsystem, const std::string& coordparam);
static void EPSG_to_str(const int& epsg, std::string& coordsystem, std::string& coordparam);
//handling of rotated coordinates
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);
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);
//handling of distances on a sphere
static double cosineDistance(const double& lat1, const double& lon1, const double& lat2, const double& lon2, double& alpha);
static void cosineInverse(const double& lat_ref, const double& lon_ref, const double& distance, const double& bearing, double& lat, double& lon);
static double VincentyDistance(const double& lat1, const double& lon1, const double& lat2, const double& lon2, double& alpha);
static void VincentyInverse(const double& lat_ref, const double& lon_ref, const double& distance, const double& bearing, double& lat, double& lon);
//Coordinates conversions
static void WGS84_to_CH1903(const double& lat_in, const double& long_in, double& east_out, double& north_out);
static void CH1903_to_WGS84(const double& east_in, const double& north_in, double& lat_out, double& long_out);
static void WGS84_to_UTM(const double& lat_in, double long_in, const std::string& coordparam, double& east_out, double& north_out);
static void UTM_to_WGS84(double east_in, double north_in, const std::string& coordparam, double& lat_out, double& long_out);
static void WGS84_to_UPS(const double& lat_in, const double& long_in, const std::string& coordparam, double& east_out, double& north_out);
static void UPS_to_WGS84(const double& east_in, const double& north_in, const std::string& coordparam, double& lat_out, double& long_out);
static void WGS84_to_PROJ4(const double& lat_in, const double& long_in, const std::string& coordparam, double& east_out, double& north_out);
static void PROJ4_to_WGS84(const double& east_in, const double& north_in, const std::string& coordparam, double& lat_out, double& long_out);
private:
static int getUTMZone(const double& latitude, const double& longitude, std::string& zone_out);
static void parseUTMZone(const std::string& zone_info, char& zoneLetter, short int& zoneNumber);
private:
///Keywords for selecting an ellipsoid to use
enum ELLIPSOIDS_NAMES {
E_WGS84, ///<Globally useable WGS84 ellipsoid
E_GRS80, ///<GRS80 ellispoid, equivalent to WGS84 but used by America and Australia
E_AIRY, ///<Airy ellispoid, good fit for the UK
E_INTL1924, ///<International 1924 ellispoid, good for most of Europe
E_CLARKE1880, ///<Clarke 1880, good for Africa
E_GRS67 ///<GRS67 ellispoid, good for South America
};
struct ELLIPSOID {
double a;
double b;
};
static const struct ELLIPSOID ellipsoids[6];
};
} //end namespace
#endif
......@@ -183,16 +183,14 @@ Grid2DObject::Grid2DObject(const Grid2DObject& i_grid2Dobj, const size_t& i_nx,
}
}
bool Grid2DObject::gridify(std::vector<Coords>& vec_points, std::vector<Coords>& vec_invalid) const
bool Grid2DObject::gridify(std::vector<Coords>& vec_points, const bool& keep_invalid) const
{
bool status=true;
vec_invalid.clear();
std::vector<Coords>::iterator v_Itr = vec_points.begin();
while ( v_Itr != vec_points.end() ) {
if( gridify(*v_Itr)==false ) {
vec_invalid.push_back( *v_Itr );
v_Itr = vec_points.erase(v_Itr);
if (!keep_invalid) v_Itr = vec_points.erase(v_Itr);
status=false;
} else {
++v_Itr;
......@@ -202,12 +200,6 @@ bool Grid2DObject::gridify(std::vector<Coords>& vec_points, std::vector<Coords>&
return status;
}
bool Grid2DObject::gridify(std::vector<Coords>& vec_points) const
{
std::vector<Coords> vec_invalid;
return gridify(vec_points, vec_invalid);
}
bool Grid2DObject::gridify(Coords& point) const {
std::string proj_type, proj_args;
point.getProj(proj_type, proj_args);
......
......@@ -99,11 +99,10 @@ class Grid2DObject {
* and (east,north)). Any point that is either invalid or outside the grid is removed from the vector.
* If the given point had a "NULL" projection, it will be set to the grid's.
* @param vec_points vector containing the coordinates to convert
* @param vec_invalid vector containing the rejected coordinates
* @param keep_invalid keep invalid coordinates? (default: false)
* @return false if invalid or external points had to be removed
*/
bool gridify(std::vector<Coords>& vec_points, std::vector<Coords>& vec_invalid) const;
bool gridify(std::vector<Coords>& vec_points) const;
bool gridify(std::vector<Coords>& vec_points, const bool& keep_invalid=false) const;
/**
* @brief Set all variables in one go.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment