WSL/SLF GitLab Repository

Commit 5a2bcf9b authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Add a few string formats options to Coords for easier use in error messages;...

Add a few string formats options to Coords for easier use in error messages; minor code cleanup in Date; add a new argument to gridify() in order to be able to retrieve the list of rejected coordinates.
parent 7b8b6be5
......@@ -222,20 +222,31 @@ void Coords::merge(const Coords& coord2) {
* @brief Print the content of the Coords object (usefull for debugging)
* The Coords is bound by "<Coords>" and "</Coords>" on separate lines
*/
const std::string Coords::toString() const {
const std::string Coords::toString(const FORMATS& type) const
{
std::ostringstream os;
os << "<Coords>\n";
os << "Altitude\t" << altitude << "\n";
os << "Lat/Long\t" << printLatLon() << "\n";
std::streamsize p = os.precision();
os << "Lat/Long\t" <<std::fixed << std::setprecision(6) << "(" << getLat() << " , " << getLon() << ")" << "\n";
os << "X/Y_coords\t" << std::fixed << std::setprecision(0) << "(" << getEasting() << " , " << getNorthing() << ")" << "\n";
os << std::resetiosflags(std::ios_base::fixed|std::ios_base::floatfield);
os.precision(p);
os << "I/J_indices\t" << "(" << getGridI() << " , " << getGridJ() << ")" << "\n";
os << "Projection\t" << coordsystem << " " << coordparam << "\n";
os << "EPSG\t\t" << getEPSG() << "\n";
os << "</Coords>\n";
if (type==DEBUG) {
os << "<Coords>\n";
os << "Altitude\t" << altitude << "\n";
os << "Lat/Long\t" << printLatLon() << "\n";
std::streamsize p = os.precision();
os << "Lat/Long\t" <<std::fixed << std::setprecision(6) << "(" << getLat() << " , " << getLon() << ")" << "\n";
os << "X/Y_coords\t" << std::fixed << std::setprecision(0) << "(" << getEasting() << " , " << getNorthing() << ")" << "\n";
os << std::resetiosflags(std::ios_base::fixed|std::ios_base::floatfield);
os.precision(p);
os << "I/J_indices\t" << "(" << getGridI() << " , " << getGridJ() << ")" << "\n";
os << "Projection\t" << coordsystem << " " << coordparam << "\n";
os << "EPSG\t\t" << getEPSG() << "\n";
os << "</Coords>\n";
} else if (type==FULL) {
os << altitude << " a.s.l.;\t";
os << "WGS84: (" << getLat() << "," << getLon() << ");\t";
os << "EPSG " << getEPSG() << ": (" << getEasting() << "," << getNorthing() << ");\t";
os << "grid: (" << getGridI() << "," << getGridJ() << ")";
}else if (type==CARTESIAN) {
os << altitude << "; (" << getEasting() << "," << getNorthing() << "); (" << getGridI() << "," << getGridJ() << ")";
} else
throw InvalidArgumentException("Selected output type is not supported!", AT);
return os.str();
}
......
......@@ -89,6 +89,13 @@ public:
GEO_COSINE, ///< Spherical law of cosine (See http://www.movable-type.co.uk/scripts/latlong.html)
GEO_VINCENTY ///< Vincenty ellispoid formula (See T. Vincenty, "Closed formulas for the direct and reverse geodetic problems", Journal of Geodesy, 51, 3, 1977, DOI:10.1007/BF02521599, or http://www.springerlink.com/content/y7108u6862473583 for more)
} geo_distances;
///Keywords for selecting the toString formats
typedef enum {
DEBUG, ///< As much information as possible, useful for debugging
FULL, ///< Provide all the usually necessary information
CARTESIAN ///< Compact representation only containing the X/Y and I/J coordinates
} FORMATS;
//Constructors
Coords();
......@@ -121,7 +128,7 @@ public:
std::string printLatLon() const;
short int getEPSG() const;
const std::string toString() const;
const std::string toString(const FORMATS& type = DEBUG) const;
friend std::iostream& operator<<(std::iostream& os, const Coords& coord);
friend std::iostream& operator>>(std::iostream& is, Coords& coord);
......
......@@ -1068,7 +1068,7 @@ std::string Date::printFractionalDay(const double& fractional) {
* @param gmt convert returned value to GMT? (default: false)
* @return formatted time in a string
*/
const string Date::toString(FORMATS type, const bool& gmt) const
const string Date::toString(const FORMATS& type, const bool& gmt) const
{//the date are displayed in LOCAL timezone (more user friendly)
int year_out, month_out, day_out, hour_out, minute_out, second_out;
double julian_out;
......
......@@ -138,7 +138,7 @@ class Date {
static double parseTimeZone(const std::string& timezone_iso);
static std::string printFractionalDay(const double& fractional);
const std::string toString(FORMATS type, const bool& gmt=false) const;
const std::string toString(const FORMATS& type, const bool& gmt=false) const;
const std::string toString() const;
friend std::iostream& operator<<(std::iostream& os, const Date& date);
friend std::iostream& operator>>(std::iostream& is, Date& date);
......
......@@ -183,12 +183,15 @@ Grid2DObject::Grid2DObject(const Grid2DObject& i_grid2Dobj, const size_t& i_nx,
}
}
bool Grid2DObject::gridify(std::vector<Coords>& vec_points) const {
bool Grid2DObject::gridify(std::vector<Coords>& vec_points, std::vector<Coords>& vec_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);
status=false;
} else {
......@@ -199,6 +202,12 @@ bool Grid2DObject::gridify(std::vector<Coords>& vec_points) const {
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,8 +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
* @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;
/**
......
......@@ -186,13 +186,16 @@ Grid3DObject::Grid3DObject(const double& i_cellsize, const Coords& i_llcorner, c
: grid3D(i_grid3D), z(), llcorner(i_llcorner),
cellsize(i_cellsize), z_is_absolute(true) {}
bool Grid3DObject::gridify(std::vector<Coords>& vec_points) const
bool Grid3DObject::gridify(std::vector<Coords>& vec_points, std::vector<Coords>& vec_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);
status=false;
} else {
......@@ -203,6 +206,12 @@ bool Grid3DObject::gridify(std::vector<Coords>& vec_points) const
return status;
}
bool Grid3DObject::gridify(std::vector<Coords>& vec_points) const
{
std::vector<Coords> vec_invalid;
return gridify(vec_points, vec_invalid);
}
bool Grid3DObject::gridify(Coords& point) const
{
std::string proj_type, proj_args;
......
......@@ -135,8 +135,10 @@ class Grid3DObject{
* grid indices. This method will calculate the missing ones (so that (i,j) match with (lat,lon)
* and (east,north)). Any point that is either invalid or outside the grid is removed from the vector.
* @param vec_points vector containing the coordinates to convert
* @param vec_invalid vector containing the rejected coordinates
* @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;
/**
......
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