Skip to content

Commit

Permalink
Merge commit '8b545a5a9de3fe0e7b2eba20dfb6f9f092a0f527'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Aug 13, 2024
2 parents 7ea3d80 + 8b545a5 commit 9237886
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 45 deletions.
2 changes: 1 addition & 1 deletion agrolib/dbMeteoGrid/dbMeteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4126,7 +4126,7 @@ bool Crit3DMeteoGridDbHandler::MeteoGridToRasterFlt(double cellSize, const gis::
{
myGrid.getXY(row, col, utmx, utmy);
gis::getLatLonFromUtm(gisSettings, utmx, utmy, &lat, &lon);
gis::getGridRowColFromLonLat (latlonHeader, lon, lat, &dataGridRow, &dataGridCol);
gis::getRowColFromLonLat (latlonHeader, lon, lat, &dataGridRow, &dataGridCol);
if (dataGridRow < 0 || dataGridRow >= latlonHeader.nrRows || dataGridCol < 0 || dataGridCol >= latlonHeader.nrCols)
{
myValue = NODATA;
Expand Down
1 change: 1 addition & 0 deletions agrolib/dbMeteoGrid/dbMeteoGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
std::vector<float> loadGridHourlyVar(QString *errorStr, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB);
std::vector<float> loadGridHourlyVarFixedFields(QString *errorStr, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB);
std::vector<float> exportAllDataVar(QString *errorStr, frequencyType freq, meteoVariable variable, QString id, QDateTime myFirstTime, QDateTime myLastTime, std::vector<QString> &dateStr);

bool getYearList(QString *errorStr, QString meteoPoint, QList<QString>* yearList);
bool idDailyList(QString *errorStr, QList<QString>* idMeteoList);

Expand Down
40 changes: 24 additions & 16 deletions agrolib/dbMeteoPoints/dbArkimet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,28 @@ QList<int> DbArkimet::getHourlyVar()



void DbArkimet::initStationsDailyTables(QDate startDate, QDate endDate, QList<QString> stations, QList<QString> idVar)
void DbArkimet::initStationsDailyTables(const QDate &startDate, const QDate &endDate,
const QList<QString> &stationList, const QList<QString> &idVarList)
{

for (short i=0; i<idVar.size(); i++)
QList<QString> varList;
for (int i=0; i < idVarList.size(); i++)
{
idVar[i].insert(0,"'");
idVar[i].insert(idVar[i].size(),"'");
varList.append("'" + idVarList[i] + "'");
}

for (int i = 0; i < stations.size(); i++)
for (int i = 0; i < stationList.size(); i++)
{
QString statement = QString("CREATE TABLE IF NOT EXISTS `%1_D` "
"(date_time TEXT, id_variable INTEGER, value REAL, PRIMARY KEY(date_time,id_variable))").arg(stations[i]);
"(date_time TEXT, id_variable INTEGER, value REAL, "
"PRIMARY KEY(date_time,id_variable))").arg(stationList[i]);

QSqlQuery qry(statement, _db);
qry.exec();

statement = QString("DELETE FROM `%1_D` WHERE date_time >= DATE('%2') AND date_time < DATE('%3', '+1 day') AND id_variable IN (%4)")
.arg(stations[i]).arg(startDate.toString("yyyy-MM-dd")).arg(endDate.toString("yyyy-MM-dd")).arg(idVar.join(","));
statement = QString("DELETE FROM `%1_D` WHERE date_time >= DATE('%2') "
"AND date_time < DATE('%3', '+1 day') AND id_variable IN (%4)")
.arg(stationList[i], startDate.toString("yyyy-MM-dd"), endDate.toString("yyyy-MM-dd"), varList.join(","));

qry = QSqlQuery(statement, _db);
qry.exec();
Expand All @@ -171,29 +174,34 @@ void DbArkimet::initStationsDailyTables(QDate startDate, QDate endDate, QList<QS
}


void DbArkimet::initStationsHourlyTables(QDate startDate, QDate endDate, QList<QString> stations, QList<QString> idVar)
void DbArkimet::initStationsHourlyTables(const QDate &startDate, const QDate &endDate,
const QList<QString> &stationList, const QList<QString> &idVarList)
{
// start from 01:00
QDateTime startTime(startDate, QTime(1,0,0), Qt::UTC);

QDateTime endTime(endDate, QTime(0,0,0), Qt::UTC);
endTime = endTime.addSecs(3600 * 24);

for (short i=0; i<idVar.size(); i++)
QList<QString> varList;
for (int i=0; i < idVarList.size(); i++)
{
idVar[i].insert(0,"'");
idVar[i].insert(idVar[i].size(),"'");
varList.append("'" + idVarList[i] + "'");
}

for (int i = 0; i < stations.size(); i++)
for (int i = 0; i < stationList.size(); i++)
{
QString statement = QString("CREATE TABLE IF NOT EXISTS `%1_H` (date_time TEXT, id_variable INTEGER, value REAL, PRIMARY KEY(date_time,id_variable))").arg(stations[i]);
QString statement = QString("CREATE TABLE IF NOT EXISTS `%1_H` "
"(date_time TEXT, id_variable INTEGER, value REAL, "
"PRIMARY KEY(date_time,id_variable))").arg(stationList[i]);

QSqlQuery qry(statement, _db);
qry.exec();

statement = QString("DELETE FROM `%1_H` WHERE date_time >= DATETIME('%2') AND date_time <= DATETIME('%3') AND id_variable IN (%4)")
.arg(stations[i]).arg(startTime.toString("yyyy-MM-dd hh:mm:ss")).arg(endTime.toString("yyyy-MM-dd hh:mm:ss")).arg(idVar.join(","));
statement = QString("DELETE FROM `%1_H` WHERE date_time >= DATETIME('%2') "
"AND date_time <= DATETIME('%3') AND id_variable IN (%4)")
.arg(stationList[i], startTime.toString("yyyy-MM-dd hh:mm:ss"),
endTime.toString("yyyy-MM-dd hh:mm:ss"), varList.join(","));

qry = QSqlQuery(statement, _db);
qry.exec();
Expand Down
6 changes: 4 additions & 2 deletions agrolib/dbMeteoPoints/dbArkimet.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
QList<int> getId(QString VarName);
QList<VariablesList> getVariableProperties(QList<int> id);

void initStationsDailyTables(QDate startDate, QDate endDate, QList<QString> stations, QList<QString> idVar);
void initStationsHourlyTables(QDate startDate, QDate endDate, QList<QString> stations, QList<QString> idVar);
void initStationsDailyTables(const QDate &startDate, const QDate &endDate,
const QList<QString> &stationList, const QList<QString> &idVarList);
void initStationsHourlyTables(const QDate &startDate, const QDate &endDate,
const QList<QString> &stationList, const QList<QString> &idVarList);

void createTmpTableHourly();
void deleteTmpTableHourly();
Expand Down
20 changes: 10 additions & 10 deletions agrolib/dbMeteoPoints/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,9 @@ bool Download::downloadDailyData(const QDate &startDate, const QDate &endDate, c


bool Download::downloadHourlyData(const QDate &startDate, const QDate &endDate, const QString &dataset,
QList<QString> &stations, QList<int> &variables, QString &errorString)
const QList<QString> &stationList, const QList<int> &varList, QString &errorString)
{
QList<VariablesList> variableList = _dbMeteo->getVariableProperties(variables);
QList<VariablesList> variableList = _dbMeteo->getVariableProperties(varList);
if (variableList.size() == 0)
return false;

Expand All @@ -557,13 +557,13 @@ bool Download::downloadHourlyData(const QDate &startDate, const QDate &endDate,
idVar.append(QString::number(variableList[i].id()));

// create station tables
_dbMeteo->initStationsHourlyTables(startDate, endDate, stations, idVar);
_dbMeteo->initStationsHourlyTables(startDate, endDate, stationList, idVar);

QString product = QString(";product: VM2,%1").arg(variables[0]);
QString product = QString(";product: VM2,%1").arg(varList[0]);

for (int i = 1; i < variables.size(); i++)
for (int i = 1; i < varList.size(); i++)
{
product = product % QString(" or VM2,%1").arg(variables[i]);
product = product % QString(" or VM2,%1").arg(varList[i]);
}

// start from 01:00
Expand All @@ -584,17 +584,17 @@ bool Download::downloadHourlyData(const QDate &startDate, const QDate &endDate,
QNetworkRequest request;
int countStation = 0;

while (countStation < stations.size())
while (countStation < stationList.size())
{
if (j == 0)
{
area = QString(";area: VM2,%1").arg(stations[countStation]);
area = QString(";area: VM2,%1").arg(stationList[countStation]);
j = j+1;
countStation = countStation+1;
}
while (countStation < stations.size() && j < maxStationSize)
while (countStation < stationList.size() && j < maxStationSize)
{
area = area % QString(" or VM2,%1").arg(stations[countStation]);
area = area % QString(" or VM2,%1").arg(stationList[countStation]);
countStation = countStation+1;
j = j+1;
}
Expand Down
2 changes: 1 addition & 1 deletion agrolib/dbMeteoPoints/download.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
QList<QString> &stations, QList<int> &variables, bool prec0024, QString &errorString);

bool downloadHourlyData(const QDate &startDate, const QDate &endDate, const QString &dataset,
QList<QString> &stations, QList<int> &variables, QString &errorString);
const QList<QString> &stationList, const QList<int> &varList, QString &errorString);

DbArkimet* getDbArkimet();

Expand Down
6 changes: 3 additions & 3 deletions agrolib/gis/gis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,10 @@ namespace gis
v->col = int(floor((p.x - myHeader.llCorner.x) / myHeader.cellSize));
}

void getGridRowColFromLonLat(const Crit3DLatLonHeader& myHeader, double myX, double myY, int *row, int *col)
void getRowColFromLonLat(const Crit3DLatLonHeader& myHeader, double lon, double lat, int *row, int *col)
{
*row = int(floor((myY - myHeader.llCorner.latitude) / myHeader.dy));
*col = int(floor((myX - myHeader.llCorner.longitude) / myHeader.dx));
*row = int(floor((lat - myHeader.llCorner.latitude) / myHeader.dy));
*col = int(floor((lon - myHeader.llCorner.longitude) / myHeader.dx));
}

void getRowColFromLatLon(const Crit3DLatLonHeader& latLonHeader, const Crit3DGeoPoint& p, int* row, int* col)
Expand Down
2 changes: 1 addition & 1 deletion agrolib/gis/gis.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
void getRowColFromXY(const Crit3DRasterHeader& myHeader, double myX, double myY, int *row, int *col);
void getRowColFromXY(const Crit3DRasterHeader& myHeader, const Crit3DUtmPoint& p, int *row, int *col);
void getRowColFromXY(const Crit3DRasterHeader& myHeader, const Crit3DUtmPoint& p, Crit3DRasterCell* v);
void getGridRowColFromLonLat(const Crit3DLatLonHeader& myHeader, double myX, double myY, int *row, int *col);
void getRowColFromLonLat(const Crit3DLatLonHeader& myHeader, double lon, double lat, int *row, int *col);

void getRowColFromLatLon(const Crit3DLatLonHeader &latLonHeader, const Crit3DGeoPoint& p, int *myRow, int *myCol);
bool isOutOfGridRowCol(int myRow, int myCol, const Crit3DRasterGrid &rasterGrid);
Expand Down
4 changes: 2 additions & 2 deletions agrolib/graphics/mapGraphicsRasterObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ bool RasterObject::getRowCol(gis::Crit3DGeoPoint geoPoint, int* row, int* col)
if (! this->isGrid)
return false;

gis::getGridRowColFromLonLat(this->latLonHeader, geoPoint.longitude, geoPoint.latitude, row, col);
gis::getRowColFromLonLat(this->latLonHeader, geoPoint.longitude, geoPoint.latitude, row, col);

// check out of grid
// check boundary
if (gis::isOutOfGridRowCol(*row, *col, this->latLonHeader))
{
return false;
Expand Down
8 changes: 4 additions & 4 deletions agrolib/meteo/meteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,19 +976,19 @@ void Crit3DMeteoGrid::saveRowColfromZone(gis::Crit3DRasterGrid* zoneGrid, std::v
int myRow, myCol;
for (int row = 0; row < zoneGrid->header->nrRows; row++)
{

for (int col = 0; col < zoneGrid->header->nrCols; col++)
{
value = zoneGrid->value[row][col];
if (value != zoneGrid->header->flag)
{
zoneGrid->getXY(row, col, x, y);
if (!_gridStructure.isUTM())
if (! _gridStructure.isUTM())
{
double utmX = x;
double utmY = y;
gis::getLatLonFromUtm(_gisSettings, utmX, utmY, &y, &x);
gis::getGridRowColFromLonLat(_gridStructure.header(), x, y, &myRow, &myCol);
double lat, lon;
gis::getLatLonFromUtm(_gisSettings, utmX, utmY, &lat, &lon);
gis::getRowColFromLonLat(_gridStructure.header(), lon, lat, &myRow, &myCol);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion agrolib/project/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3700,7 +3700,7 @@ void Project::showLocalProxyGraph(gis::Crit3DGeoPoint myPoint, gis::Crit3DRaster
}
if (this->meteoGridLoaded && !this->meteoGridDbHandler->meteoGrid()->dataMeteoGrid.singleCell.empty())
{
gis::getGridRowColFromLonLat(meteoGridDbHandler->meteoGrid()->gridStructure().header(), myPoint.longitude, myPoint.latitude, &row, &col);
gis::getRowColFromLonLat(meteoGridDbHandler->meteoGrid()->gridStructure().header(), myPoint.longitude, myPoint.latitude, &row, &col);
parameters = meteoGridDbHandler->meteoGrid()->dataMeteoGrid.getParametersFromRowCol(row, col);
}

Expand Down
6 changes: 3 additions & 3 deletions agrolib/snow/snow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void Crit3DSnow::initialize()
}


void Crit3DSnow::setInputData(double temp, double prec, double relHum, double windInt, double globalRad,
void Crit3DSnow::setSnowInputData(double temp, double prec, double relHum, double windInt, double globalRad,
double beamRad, double transmissivity, double clearSkyTransmissivity, double waterContent)
{
_airT = temp;
Expand All @@ -100,7 +100,7 @@ void Crit3DSnow::setInputData(double temp, double prec, double relHum, double wi
_beamRadiation = beamRad;
_transmissivity = transmissivity;
_clearSkyTransmissivity = clearSkyTransmissivity;
_surfaceWaterContent = std::max(waterContent, 0.0);
_surfaceWaterContent = std::max(waterContent, 0.0); // [mm]
}


Expand Down Expand Up @@ -328,7 +328,7 @@ void Crit3DSnow::computeSnowBrooksModel()
QPrecipS = (HEAT_CAPACITY_SNOW / 1000.) * (_precSnow / 1000.) * (std::min(0., _airT) - prevSurfaceTemp);
QPrecip = QPrecipW + QPrecipS;

// temperatura dell'acqua: almeno 1 grado
// temperatura dell'acqua superficiale: almeno 1 grado
QWaterHeat = (HEAT_CAPACITY_WATER / 1000.) * (_surfaceWaterContent / 1000.)
* (std::max(1., (prevSurfaceTemp + _airT) / 2.) - prevSurfaceTemp);

Expand Down
2 changes: 1 addition & 1 deletion agrolib/snow/snow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

void initialize();

void setInputData(double temp, double prec, double relHum, double windInt, double globalRad,
void setSnowInputData(double temp, double prec, double relHum, double windInt, double globalRad,
double beamRad, double transmissivity, double clearSkyTransmissivity, double waterContent);

bool checkValidPoint();
Expand Down

0 comments on commit 9237886

Please sign in to comment.