WSL/SLF GitLab Repository

Commit a4c59fac authored by Mathias Bavay's avatar Mathias Bavay
Browse files

When calling Coords::setProj(), if only x/y were known, the lat/long were not...

When calling Coords::setProj(), if only x/y were known, the lat/long were not calculated (but this was done for lat/long known and x/y missing). This has been fixed.

The slope angle normalization between 0-90 degrees has been done.

A merge method has been implemented for Coords and StationData. This simply replaces nodata fields from one object by the matching field from another object (priority given to the current object or the first object in the static method). This is quite a primitive merge strategy, but I doubt anything better could ever be done...
parent 84ac25ef
......@@ -141,6 +141,55 @@ Coords& Coords::operator=(const Coords& source) {
return *this;
}
/**
* @brief Simple merge strategy.
* If some fields of the first argument are empty, they will be filled by the macthing field from the
* second argument.
* @param coord1 first Coords to merge, highest priority
* @param coord2 second Coords to merge, lowest priority
* @return new Coords object
*/
Coords Coords::merge(const Coords& coord1, const Coords& coord2) {
Coords tmp(coord1);
tmp.merge(coord2);
}
/**
* @brief Simple merge strategy.
* If some fields of the current object are empty, they will be filled by the macthing field from the
* provided argument.
* @param coord2 extra Coords to merge, lowest priority
*/
void Coords::merge(const Coords& coord2) {
if(altitude==IOUtils::nodata) altitude=coord2.altitude;
if(latitude==IOUtils::nodata) latitude=coord2.latitude;
if(longitude==IOUtils::nodata) longitude=coord2.longitude;
if(easting==IOUtils::nodata) easting=coord2.easting;
if(northing==IOUtils::nodata) northing=coord2.northing;
if(grid_i==IOUtils::nodata) grid_i=coord2.grid_i;
if(grid_j==IOUtils::nodata) grid_j=coord2.grid_j;
if(grid_k==IOUtils::nodata) grid_k=coord2.grid_k;
if(ref_latitude==IOUtils::nodata) ref_latitude=coord2.ref_latitude;
if(ref_longitude==IOUtils::nodata) ref_longitude=coord2.ref_longitude;
if(coordsystem=="NULL") coordsystem=coord2.coordsystem;
if(coordparam=="NULL") coordparam=coord2.coordparam;
if(distance_algo==IOUtils::nodata) distance_algo=coord2.distance_algo;
//refresh pointers list, recalculate what could be calculated, etc
setFunctionPointers();
//in LOCAL projection, the check for the existence of the ref point will be done in the projection functions
if(latitude!=IOUtils::nodata && coordsystem!="NULL") {
convert_from_WGS84(latitude, longitude, easting, northing);
}
if(latitude==IOUtils::nodata && coordsystem!="NULL") {
convert_to_WGS84(easting, northing, latitude, longitude);
}
}
/**
* @brief Print the content of the Coords object (usefull for debugging)
* The Coords is bound by "<Coords>" and "</Coords>" on separate lines
......@@ -422,6 +471,12 @@ void Coords::setProj(const std::string& in_coordinatesystem, const std::string&
if(latitude!=IOUtils::nodata && longitude!=IOUtils::nodata) {
convert_from_WGS84(latitude, longitude, easting, northing);
}
//if we only had x/y but not even a coord system, we could not compute lat/long. We now do it
if( (latitude==IOUtils::nodata || longitude==IOUtils::nodata) &&
(easting!=IOUtils::nodata && northing!=IOUtils::nodata) &&
(coordsystem != "NULL") ) {
convert_to_WGS84(easting, northing, latitude, longitude);
}
}
/**
......
......@@ -68,6 +68,9 @@ class Coords {
bool operator==(const Coords&) const; ///<Operator that tests for equality
bool operator!=(const Coords&) const; ///<Operator that tests for inequality
static Coords merge(const Coords& coord1, const Coords& coord2);
void merge(const Coords& coord2);
//Getter methods
double getEasting() const;
double getNorthing() const;
......
......@@ -109,7 +109,7 @@ class IOManager {
* @param vecMeteo The actual data being pushed into the IOManager object
*/
void push_meteo_data(const ProcessingLevel& level, const Date& date_start, const Date& date_end,
const std::vector< METEO_TIMESERIE >& vecMeteo);
const std::vector< METEO_TIMESERIE >& vecMeteo);
#ifdef _POPC_ //HACK popc
void interpolate(/*const*/ Date& date, /*const*/ DEMObject& dem, /*const*/ MeteoData::Parameters meteoparam,
......
......@@ -28,7 +28,7 @@ StationData::StationData() : position("NULL", "NULL"), stationID(""), stationNam
StationData::StationData(const Coords& _position, const std::string& _id, const std::string& _name)
{
setStationData(_position, _id, _name);
setStationSlope(IOUtils::nodata, IOUtils::nodata);
setSlope(IOUtils::nodata, IOUtils::nodata);
}
void StationData::setStationData(const Coords& _position, const std::string& _id, const std::string& _name)
......@@ -38,10 +38,14 @@ void StationData::setStationData(const Coords& _position, const std::string& _id
stationName = _name;
}
void StationData::setStationSlope(const double& in_slope_angle, const double& in_azimuth)
void StationData::setSlope(const double& in_slope_angle, const double& in_azimuth)
{
if(in_slope_angle!=IOUtils::nodata) {
slope = fmod(in_slope_angle, 360.);
//normalizing the slope between 0 and 90
if(slope>90. && slope <=180.) slope = 180. - slope;
if(slope>180. && slope <=270.) slope = slope - 180.;
if(slope>270. && slope <=360.) slope = 360. - slope;
} else
slope = IOUtils::nodata;
......@@ -61,6 +65,20 @@ bool StationData::operator!=(const StationData& in) const {
return !(*this==in);
}
StationData StationData::merge(const StationData& sd1, const StationData& sd2) {
StationData tmp(sd1);
tmp.merge(sd2);
}
void StationData::merge(const StationData& sd2) {
if(stationID=="") stationID=sd2.stationID;
if(stationName=="") stationName=sd2.stationName;
if(slope==IOUtils::nodata) slope=sd2.slope;
if(azi==IOUtils::nodata) azi=sd2.azi;
position.merge(sd2.position);
}
//Specific Getter Functions for stationName, stationID and position
Coords StationData::getPosition() const {
return position;
......
......@@ -89,7 +89,7 @@ class StationData {
* @param in_slope_angle angle of the local slope (in degrees, between 0 and 90 degrees)
* @param in_azimuth azimuth of the local slope expressed as a bearing (0 is North, in degrees, clockwise)
*/
void setStationSlope(const double& in_slope_angle, const double& in_azimuth);
void setSlope(const double& in_slope_angle, const double& in_azimuth);
friend std::ostream& operator<<(std::ostream& os, const StationData& station);
......@@ -102,6 +102,24 @@ class StationData {
bool operator==(const StationData&) const;
bool operator!=(const StationData&) const; ///<Operator that tests for inequality
/**
* @brief Simple merge strategy.
* If some fields of the first argument are empty, they will be filled by the macthing field from the
* second argument.
* @param sd1 first StationData to merge, highest priority
* @param sd2 second StationData to merge, lowest priority
* @return new StationData object
*/
static StationData merge(const StationData& sd1, const StationData& sd2);
/**
* @brief Simple merge strategy.
* If some fields of the current object are empty, they will be filled by the macthing field from the
* provided argument.
* @param sd2 extra StationData to merge, lowest priority
*/
void merge(const StationData& sd2);
public:
Coords position;
std::string stationID; ///<ID of the Station, typically a short string
......
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