Skip to content

Commit

Permalink
update output points
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Mar 22, 2024
1 parent 0e96078 commit 36f8ba4
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 93 deletions.
36 changes: 10 additions & 26 deletions agrolib/outputPoints/dbOutputPointsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,7 @@ Crit3DOutputPointsDbHandler::~Crit3DOutputPointsDbHandler()
}


bool Crit3DOutputPointsDbHandler::isOpen()
{
return _db.isOpen();
}

QString Crit3DOutputPointsDbHandler::getDbName()
{
return _db.databaseName();
}

QString Crit3DOutputPointsDbHandler::getErrorString()
{
return errorString;
}


bool Crit3DOutputPointsDbHandler::createTable(QString tableName, QString& errorStr)
bool Crit3DOutputPointsDbHandler::createTable(const QString& tableName, QString& errorStr)
{
QString queryString = "CREATE TABLE IF NOT EXISTS '" + tableName + "'";
queryString += " (DATE_TIME TEXT, PRIMARY KEY(DATE_TIME))";
Expand All @@ -69,7 +53,7 @@ bool Crit3DOutputPointsDbHandler::createTable(QString tableName, QString& errorS
}


bool Crit3DOutputPointsDbHandler::addColumn(QString tableName, meteoVariable myVar, QString& errorStr)
bool Crit3DOutputPointsDbHandler::addColumn(const QString &tableName, meteoVariable myVar, QString& errorStr)
{
// column name
QString newField = QString::fromStdString(getMeteoVarName(myVar));
Expand Down Expand Up @@ -117,7 +101,7 @@ bool Crit3DOutputPointsDbHandler::addCriteria3DColumn(const QString &tableName,

// column exists already
QList<QString> fieldList = getFields(&_db, tableName);
if (fieldList.contains(newField))
if ( fieldList.contains(newField) )
{
return true;
}
Expand All @@ -137,10 +121,10 @@ bool Crit3DOutputPointsDbHandler::addCriteria3DColumn(const QString &tableName,
}


bool Crit3DOutputPointsDbHandler::saveHourlyMeteoData(QString tableName, const QDateTime& myTime,
const std::vector<meteoVariable>& varList,
const std::vector<float>& values,
QString& errorStr)
bool Crit3DOutputPointsDbHandler::saveHourlyMeteoData(const QString &tableName, const QDateTime &myTime,
const std::vector<meteoVariable> &varList,
const std::vector<float> &values,
QString &errorStr)
{
if (varList.size() != values.size())
{
Expand Down Expand Up @@ -195,11 +179,11 @@ bool Crit3DOutputPointsDbHandler::saveHourlyMeteoData(QString tableName, const Q


// layerDepth [m]
bool Crit3DOutputPointsDbHandler::saveHourlyCriteria3D_Data(QString tableName, const QDateTime& myTime,
bool Crit3DOutputPointsDbHandler::saveHourlyCriteria3D_Data(const QString &tableName, const QDateTime& myTime,
const std::vector<criteria3DVariable>& varList,
const std::vector<float>& values,
const std::vector <double>& layerDepth,
QString& errorStr)
QString &errorStr)
{
int nrSoilLayers = int(layerDepth.size()) - 1;
if (nrSoilLayers <= 0)
Expand All @@ -208,7 +192,7 @@ bool Crit3DOutputPointsDbHandler::saveHourlyCriteria3D_Data(QString tableName, c
return false;
}

int nrValues = varList.size() * nrSoilLayers;
int nrValues = int(varList.size()) * nrSoilLayers;
if (nrValues != values.size())
{
errorStr = "Error saving values: number of values is not as expected.";
Expand Down
43 changes: 23 additions & 20 deletions agrolib/outputPoints/dbOutputPointsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,31 @@
explicit Crit3DOutputPointsDbHandler(QString dbname_);
~Crit3DOutputPointsDbHandler();

void closeDatabase();
QSqlDatabase getDb() const;
QString getDbName();
QString getErrorString();
bool isOpen();

bool createTable(QString tableName, QString &errorStr);
bool addColumn(QString tableName, meteoVariable myVar, QString &errorString);
bool addCriteria3DColumn(const QString &tableName, criteria3DVariable myVar, int depth, QString& errorStr);

bool saveHourlyMeteoData(QString tableName, const QDateTime &myTime,
const std::vector<meteoVariable> &varList,
const std::vector<float> &values, QString& errorStr);

bool saveHourlyCriteria3D_Data(QString tableName, const QDateTime& myTime,
const std::vector<criteria3DVariable>& varList,
const std::vector<float>& values,
const std::vector <double>& layerDepth,
QString& errorStr);
QString getDbName() {
return _db.databaseName(); }

private:
QString getErrorString() {
return errorString; }

bool isOpen() {
return _db.isOpen(); }

bool createTable(const QString &tableName, QString &errorStr);

bool addColumn(const QString &tableName, meteoVariable myVar, QString &errorString);

bool addCriteria3DColumn(const QString &tableName, criteria3DVariable myVar, int depth, QString &errorStr);

bool saveHourlyMeteoData(const QString &tableName, const QDateTime &myTime,
const std::vector<meteoVariable> &varList,
const std::vector<float> &values, QString &errorStr);

bool saveHourlyCriteria3D_Data(const QString &tableName, const QDateTime &myTime,
const std::vector<criteria3DVariable> &varList,
const std::vector<float> &values,
const std::vector <double> &layerDepth, QString &errorStr);

private:
QSqlDatabase _db;
QString errorString;
};
Expand Down
32 changes: 6 additions & 26 deletions agrolib/outputPoints/dialogNewPoint.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "dialogNewPoint.h"
#include "basicMath.h"


DialogNewPoint::DialogNewPoint(const QList<QString>& _idList, const gis::Crit3DGisSettings& _gisSettings, gis::Crit3DRasterGrid* _DEMptr)
:idList(_idList), gisSettings(_gisSettings), DEMpointer(_DEMptr)
{

setWindowTitle("New point");
this->resize(300, 180);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
Expand Down Expand Up @@ -101,11 +102,9 @@ DialogNewPoint::~DialogNewPoint()
void DialogNewPoint::computeUTM()
{
if (utmx.text().isEmpty() || utmy.text().isEmpty())
{
return;
}
double myLat;
double myLon;

double myLat, myLon;
gis::getLatLonFromUtm(gisSettings, utmx.text().toDouble(), utmy.text().toDouble(), &myLat, &myLon);
lat.setText(QString::number(myLat));
lon.setText(QString::number(myLon));
Expand All @@ -121,6 +120,7 @@ void DialogNewPoint::getFromDEM()
QMessageBox::information(nullptr, "DEM not loaded", "Load DEM");
return;
}

float demValue;
if (utmx.text().isEmpty() || utmy.text().isEmpty())
{
Expand All @@ -139,7 +139,7 @@ void DialogNewPoint::getFromDEM()
demValue = gis::getValueFromXY(*DEMpointer, utmx.text().toDouble(), utmy.text().toDouble());
}

if (demValue != DEMpointer->header->flag)
if (! isEqual(demValue, DEMpointer->header->flag))
{
height.setText(QString::number(demValue));
}
Expand Down Expand Up @@ -225,23 +225,3 @@ void DialogNewPoint::done(int res)
return;
}
}

QString DialogNewPoint::getId()
{
return id.text();
}

double DialogNewPoint::getLat()
{
return lat.text().toDouble();
}

double DialogNewPoint::getLon()
{
return lon.text().toDouble();
}

double DialogNewPoint::getHeight()
{
return height.text().toDouble();
}
22 changes: 11 additions & 11 deletions agrolib/outputPoints/dialogNewPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ class DialogNewPoint : public QDialog
DialogNewPoint(const QList<QString>& _idList, const gis::Crit3DGisSettings& _gisSettings, gis::Crit3DRasterGrid* _DEMptr);
~DialogNewPoint();

void done(int res);
QString getId() { return id.text(); }
double getLat() { return lat.text().toDouble(); }
double getLon() { return lon.text().toDouble(); }
double getHeight() { return height.text().toDouble(); }

void setDEM();
void computeUTM();
void getFromDEM();
QString getId();
double getLat();
double getLon();
double getHeight();

void done(int res);

private:
QList<QString> idList;

gis::Crit3DGisSettings gisSettings;
gis::Crit3DRasterGrid* DEMpointer;
QLineEdit id;
QLineEdit utmx;
QLineEdit utmy;
QLineEdit lat;
QLineEdit lon;
QLineEdit height;

QLineEdit id, utmx, utmy;
QLineEdit lat, lon, height;

QPushButton computeUTMButton;
QPushButton getFromDEMButton;
};
Expand Down
13 changes: 7 additions & 6 deletions agrolib/outputPoints/outputPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@



bool loadOutputPointListCsv(QString csvFileName, std::vector<gis::Crit3DOutputPoint> &outputPointList,
int utmZone, QString &errorString)
bool loadOutputPointListCsv(const QString &csvFileName, std::vector<gis::Crit3DOutputPoint> &outputPointList,
int utmZone, QString &errorString)
{
QList<QList<QString>> data;
if (!importOutputPointsCsv(csvFileName, data, errorString))
if (! importPointPropertiesCsv(csvFileName, data, errorString))
return false;

for (int i = 0; i < data.size(); i++)
Expand All @@ -32,7 +32,7 @@ bool loadOutputPointListCsv(QString csvFileName, std::vector<gis::Crit3DOutputPo
}


bool writeOutputPointListCsv(QString csvFileName, std::vector<gis::Crit3DOutputPoint> &outputPointList, QString &errorString)
bool writeOutputPointListCsv(const QString &csvFileName, std::vector<gis::Crit3DOutputPoint> &outputPointList, QString &errorString)
{
errorString.clear();
if (csvFileName == "")
Expand Down Expand Up @@ -84,7 +84,7 @@ bool writeOutputPointListCsv(QString csvFileName, std::vector<gis::Crit3DOutputP
}


bool importOutputPointsCsv(QString csvFileName, QList<QList<QString>> &data, QString &errorString)
bool importPointPropertiesCsv(const QString &csvFileName, QList<QList<QString>> &pointsProperties, QString &errorString)
{
errorString.clear();
if (csvFileName == "")
Expand Down Expand Up @@ -178,7 +178,8 @@ bool importOutputPointsCsv(QString csvFileName, QList<QList<QString>> &data, QSt
myFile.close();
return false;
}
data.append(line);

pointsProperties.append(line);
}
myFile.close();

Expand Down
10 changes: 6 additions & 4 deletions agrolib/outputPoints/outputPoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#endif
#include <QString>

bool importOutputPointsCsv(QString csvFileName, QList<QList<QString>> &data, QString &errorString);
bool importPointPropertiesCsv(const QString &csvFileName, QList<QList<QString>> &pointsProperties,
QString &errorString);

bool loadOutputPointListCsv(QString csvFileName, std::vector<gis::Crit3DOutputPoint> &outputPointList,
int utmZone, QString &errorString);
bool loadOutputPointListCsv(const QString &csvFileName, std::vector<gis::Crit3DOutputPoint> &outputPointList,
int utmZone, QString &errorString);

bool writeOutputPointListCsv(QString csvFileName, std::vector<gis::Crit3DOutputPoint> &outputPointList, QString &errorString);
bool writeOutputPointListCsv(const QString &csvFileName, std::vector<gis::Crit3DOutputPoint> &outputPointList,
QString &errorString);


#endif // OUTPUTPOINTS_H

0 comments on commit 36f8ba4

Please sign in to comment.