diff --git a/agrolib/pragaProject/dialogMeteoComputation.cpp b/agrolib/pragaProject/dialogMeteoComputation.cpp index 2c7474591..23ace396e 100644 --- a/agrolib/pragaProject/dialogMeteoComputation.cpp +++ b/agrolib/pragaProject/dialogMeteoComputation.cpp @@ -492,16 +492,13 @@ DialogMeteoComputation::DialogMeteoComputation(QSettings *settings, bool isMeteo } } - show(); exec(); - } void DialogMeteoComputation::done(bool res) { - if(res) // ok was pressed { if ( (!saveClima && !checkValidData()) || (saveClima && saveClimaLayout.getList().empty()) ) @@ -714,14 +711,12 @@ void DialogMeteoComputation::done(bool res) QDialog::done(QDialog::Accepted); return; } - } else // cancel, close or exc was pressed { QDialog::done(QDialog::Rejected); return; } - } @@ -741,7 +736,6 @@ void DialogMeteoComputation::checkYears() void DialogMeteoComputation::displayPeriod(const QString value) { - if (value == "Daily") { elaborationList.setCurrentText("No elaboration available"); @@ -936,12 +930,10 @@ void DialogMeteoComputation::displayPeriod(const QString value) nrYear.setText("0"); nrYear.setEnabled(true); } - } - - } + void DialogMeteoComputation::listElaboration(const QString value) { @@ -994,9 +986,9 @@ void DialogMeteoComputation::listElaboration(const QString value) { anomaly.AnomalySetVariableElab(variableList.currentText()); } - } + void DialogMeteoComputation::listSecondElab(const QString value) { @@ -1069,25 +1061,23 @@ void DialogMeteoComputation::listSecondElab(const QString value) } settings->endArray(); settings->endGroup(); - - } + void DialogMeteoComputation::activeSecondParameter(const QString value) { - - if ( MapElabWithParam.find(value.toStdString()) == MapElabWithParam.end()) - { - elab2Parameter.clear(); - elab2Parameter.setReadOnly(true); - } - else - { - elab2Parameter.setReadOnly(false); - } - + if ( MapElabWithParam.find(value.toStdString()) == MapElabWithParam.end()) + { + elab2Parameter.clear(); + elab2Parameter.setReadOnly(true); + } + else + { + elab2Parameter.setReadOnly(false); + } } + void DialogMeteoComputation::readParameter(int state) { @@ -1122,10 +1112,8 @@ void DialogMeteoComputation::readParameter(int state) climateDbElabList.addItem(climateDbElab[i]); } } - } - elab1Parameter.clear(); elab1Parameter.setReadOnly(true); } @@ -1135,7 +1123,6 @@ void DialogMeteoComputation::readParameter(int state) adjustSize(); elab1Parameter.setReadOnly(false); } - } @@ -1320,14 +1307,15 @@ bool DialogMeteoComputation::checkValidData() } } return true; - } + QList DialogMeteoComputation::getElabSaveList() { return saveClimaLayout.getList(); } + void DialogMeteoComputation::copyDataFromXML() { Crit3DElabList listXMLElab; @@ -1376,6 +1364,7 @@ void DialogMeteoComputation::copyDataFromXML() variableList.setCurrentText(QString::fromStdString(xmlVariable)); int elabIndex = elaborationList.findText(listXMLElab.listElab1()[index], Qt::MatchFixedString); elaborationList.setCurrentIndex(elabIndex); + if ( (listXMLElab.listParam1()[index] != NODATA) && (!listXMLElab.listParam1IsClimate()[index]) ) { elab1Parameter.setReadOnly(false); @@ -1389,13 +1378,12 @@ void DialogMeteoComputation::copyDataFromXML() climateDbElabList.setVisible(true); adjustSize(); - int index = climateDbElabList.findText(listXMLElab.listParam1ClimateField()[index], Qt::MatchFixedString); - if (index == -1) + int climateIndex = climateDbElabList.findText(listXMLElab.listParam1ClimateField()[index], Qt::MatchFixedString); + if (climateIndex == -1) { QMessageBox::information(nullptr, "climate field not found", "Check param1 climate field"); } - climateDbElabList.setCurrentIndex(index); - + climateDbElabList.setCurrentIndex(climateIndex); } else { @@ -1474,12 +1462,12 @@ void DialogMeteoComputation::copyDataFromXML() climateDbElabList.setVisible(true); adjustSize(); - int index = climateDbElabList.findText(listXMLAnomaly.listParam1ClimateField()[index], Qt::MatchFixedString); - if (index == -1) + int climateIndex = climateDbElabList.findText(listXMLAnomaly.listParam1ClimateField()[index], Qt::MatchFixedString); + if (climateIndex == -1) { QMessageBox::information(nullptr, "climate field not found", "Check param1 climate field"); } - climateDbElabList.setCurrentIndex(index); + climateDbElabList.setCurrentIndex(climateIndex); } else @@ -1537,12 +1525,12 @@ void DialogMeteoComputation::copyDataFromXML() { anomaly.AnomalyReadParameter(1); - int index = climateDbElabList.findText(listXMLAnomaly.listRefParam1ClimateField()[index], Qt::MatchFixedString); - if (index == -1) + int climateIndex = climateDbElabList.findText(listXMLAnomaly.listRefParam1ClimateField()[index], Qt::MatchFixedString); + if (climateIndex == -1) { QMessageBox::information(nullptr, "climate field not found", "Check reference param1 climate field"); } - climateDbElabList.setCurrentIndex(index); + climateDbElabList.setCurrentIndex(climateIndex); } else { diff --git a/agrolib/pragaProject/pragaProject.cpp b/agrolib/pragaProject/pragaProject.cpp index d0bde09e5..dc447925c 100644 --- a/agrolib/pragaProject/pragaProject.cpp +++ b/agrolib/pragaProject/pragaProject.cpp @@ -42,12 +42,18 @@ void PragaProject::initializePragaProject() pragaDailyMaps = nullptr; users.clear(); lastElabTargetisGrid = false; + + outputMeteoPointsDbHandler = nullptr; + outputMeteoPointsDbFileName = ""; + outputMeteoPointsLoaded = false; } void PragaProject::clearPragaProject() { if (isProjectLoaded) clearProject(); + closeOutputMeteoPointsDB(); + users.clear(); dataRaster.clear(); @@ -2170,7 +2176,7 @@ bool PragaProject::interpolationMeteoGrid(meteoVariable myVar, frequencyType myF } else { - if (! interpolationGridMain(myVar, myTime)) + if (! interpolationGrid(myVar, myTime)) return false; } @@ -3542,3 +3548,73 @@ bool PragaProject::saveLogProceduresGrid(QString nameProc, QDate date) } return true; } + + +void PragaProject::closeOutputMeteoPointsDB() +{ + if (outputMeteoPointsDbHandler != nullptr) + { + delete outputMeteoPointsDbHandler; + outputMeteoPointsDbHandler = nullptr; + } + + outputMeteoPointsLoaded = false; + outputPoints.clear(); +} + + +bool PragaProject::loadOutputMeteoPointsDB(QString fileName) +{ + if (fileName.isEmpty()) + return false; + + closeOutputMeteoPointsDB(); + errorString = ""; + logInfo("Load output meteo points = " + fileName); + + QString outputDbName = getCompleteFileName(fileName, PATH_METEOPOINT); + if (! QFile(outputDbName).exists()) + { + errorString = "Output meteo points DB does not exists:\n" + outputDbName; + return false; + } + + outputMeteoPointsDbHandler = new Crit3DMeteoPointsDbHandler(outputDbName); + if (! outputMeteoPointsDbHandler->error.isEmpty()) + { + errorString = "Function loadOutputMeteoPointsDB:\n" + outputDbName + + "\n" + outputMeteoPointsDbHandler->error; + return false; + } + + QList listMeteoPoints; + if (! outputMeteoPointsDbHandler->getPropertiesFromDb(listMeteoPoints, gisSettings, errorString)) + { + errorString = "Error in reading table 'point_properties'\n" + errorString; + return false; + } + + if (listMeteoPoints.empty()) + { + errorString = "Missing data in the table 'point_properties'"; + return false; + } + // set output points + outputPoints.resize(listMeteoPoints.size()); + for (int i=0; i < listMeteoPoints.size(); i++) + { + outputPoints[i].id = listMeteoPoints[i].id; + outputPoints[i].latitude = listMeteoPoints[i].latitude; + outputPoints[i].longitude = listMeteoPoints[i].longitude; + outputPoints[i].utm = listMeteoPoints[i].point.utm; + outputPoints[i].z = listMeteoPoints[i].point.z; + outputPoints[i].active = listMeteoPoints[i].active; + } + listMeteoPoints.clear(); + + outputMeteoPointsDbFileName = outputDbName; + outputMeteoPointsLoaded = true; + logInfo("Output meteo points DB = " + outputMeteoPointsDbFileName); + + return true; +} diff --git a/agrolib/pragaProject/pragaProject.h b/agrolib/pragaProject/pragaProject.h index 295063b7a..dc0aeb36d 100644 --- a/agrolib/pragaProject/pragaProject.h +++ b/agrolib/pragaProject/pragaProject.h @@ -49,7 +49,9 @@ void deleteSynchWidget(); public: + QString projectPragaFolder; QList users; + gis::Crit3DRasterGrid dataRaster; Crit3DDailyMeteoMaps* pragaDailyMaps; PragaHourlyMeteoMaps* pragaHourlyMaps; @@ -71,9 +73,14 @@ Crit3DPointStatisticsWidget* pointStatisticsWidget; Crit3DHomogeneityWidget* homogeneityWidget; Crit3DSynchronicityWidget* synchronicityWidget; + std::string synchReferencePoint; + ImportDataXML* importData; - QString projectPragaFolder; + + Crit3DMeteoPointsDbHandler* outputMeteoPointsDbHandler; + QString outputMeteoPointsDbFileName; + bool outputMeteoPointsLoaded; #ifdef NETCDF NetCDFHandler netCDF; @@ -91,6 +98,9 @@ bool loadPragaProject(QString myFileName); bool loadPragaSettings(); + void closeOutputMeteoPointsDB(); + bool loadOutputMeteoPointsDB(QString fileName); + gis::Crit3DRasterGrid* getPragaMapFromVar(meteoVariable myVar); bool downloadDailyDataArkimet(QList variables, bool prec0024, QDate startDate, QDate endDate, bool showInfo); diff --git a/agrolib/project/project.cpp b/agrolib/project/project.cpp index d91082dd9..93d146337 100644 --- a/agrolib/project/project.cpp +++ b/agrolib/project/project.cpp @@ -100,6 +100,7 @@ void Project::initializeProject() proxyWidget = nullptr; } + void Project::clearProject() { if (logFile.is_open()) logFile.close(); @@ -135,6 +136,7 @@ void Project::clearProject() isProjectLoaded = false; } + void Project::clearProxyDEM() { int index = interpolationSettings.getIndexHeight(); @@ -186,6 +188,7 @@ void Project::setProxyDEM() } } + bool Project::checkProxy(const Crit3DProxy &myProxy, QString* error) { std::string name_ = myProxy.getName(); @@ -207,6 +210,7 @@ bool Project::checkProxy(const Crit3DProxy &myProxy, QString* error) return true; } + bool Project::addProxyToProject(std::vector proxyList, std::deque proxyActive, std::vector proxyOrder) { unsigned i, order; @@ -235,7 +239,6 @@ bool Project::addProxyToProject(std::vector proxyList, std::deque if (getProxyPragaName(interpolationSettings.getProxy(i)->getName()) == height) setProxyDEM(); return true; - } @@ -252,6 +255,7 @@ void Project::addProxyGridSeries(QString name_, std::vector gridNames, proxyGridSeries.push_back(mySeries); } + bool Project::loadParameters(QString parametersFileName) { parametersFileName = getCompleteFileName(parametersFileName, PATH_SETTINGS); @@ -1120,6 +1124,7 @@ bool Project::loadMeteoPointsDB(QString fileName) return true; } + bool Project::loadAggregationDBAsMeteoPoints(QString fileName) { if (fileName == "") return false; @@ -2120,9 +2125,10 @@ bool Project::computeStatisticsCrossValidation(Crit3DTime myTime, meteoVariable return true; } + bool Project::interpolationCv(meteoVariable myVar, const Crit3DTime& myTime, crossValidationStatistics *myStats) { - if (! checkInterpolationMain(myVar)) return false; + if (! checkInterpolation(myVar)) return false; // check variables if ( interpolationSettings.getUseDewPoint() && @@ -2373,7 +2379,8 @@ bool Project::interpolateDemRadiation(const Crit3DTime& myTime, gis::Crit3DRaste return true; } -bool Project::checkInterpolationMain(meteoVariable myVar) + +bool Project::checkInterpolation(meteoVariable myVar) { if (! DEM.isLoaded) { @@ -2394,10 +2401,10 @@ bool Project::checkInterpolationMain(meteoVariable myVar) } return true; - } -bool Project::checkInterpolationMainSimple(meteoVariable myVar) + +bool Project::checkInterpolationGrid(meteoVariable myVar) { if (nrMeteoPoints == 0) { @@ -2412,12 +2419,12 @@ bool Project::checkInterpolationMainSimple(meteoVariable myVar) } return true; - } + bool Project::interpolationDemMain(meteoVariable myVar, const Crit3DTime& myTime, gis::Crit3DRasterGrid *myRaster) { - if (! checkInterpolationMain(myVar)) + if (! checkInterpolation(myVar)) return false; // solar radiation model @@ -2465,8 +2472,12 @@ bool Project::meteoGridAggregateProxy(std::vector &myGr return true; } + bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) { + if (! checkInterpolationGrid(myVar)) + return false; + std::vector interpolationPoints; // check quality and pass data to interpolation @@ -2582,21 +2593,6 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) return true; } -bool Project::interpolationGridMain(meteoVariable myVar, const Crit3DTime& myTime) -{ - if (! checkInterpolationMainSimple(myVar)) - return false; - - /* solar radiation model - if (myVar == globalIrradiance) - { - Crit3DTime halfHour = myTime.addSeconds(-1800); - return interpolateDemRadiation(halfHour, myRaster); - }*/ - - return interpolationGrid(myVar, myTime); -} - float Project::meteoDataConsistency(meteoVariable myVar, const Crit3DTime& timeIni, const Crit3DTime& timeFin) { @@ -2610,14 +2606,14 @@ float Project::meteoDataConsistency(meteoVariable myVar, const Crit3DTime& timeI QString Project::getCompleteFileName(QString fileName, QString secondaryPath) { - if (fileName == "") return fileName; + if (fileName.isEmpty()) return fileName; if (getFilePath(fileName) == "") { QString completeFileName = this->getDefaultPath() + secondaryPath + fileName; return QDir().cleanPath(completeFileName); } - else if (fileName.left(1) == ".") + else if (fileName.at(0) == '.') { QString completeFileName = this->getProjectPath() + fileName; return QDir().cleanPath(completeFileName); @@ -2631,14 +2627,14 @@ QString Project::getCompleteFileName(QString fileName, QString secondaryPath) QString Project::getRelativePath(QString fileName) { - if (fileName != "" && fileName.left(1) != "." && getFilePath(fileName) != "") + if (!fileName.isEmpty() && fileName.at(0) != '.' && getFilePath(fileName) != "") { QDir projectDir(getProjectPath()); QString relativePath = projectDir.relativeFilePath(fileName); if (relativePath != fileName) { fileName = relativePath; - if (fileName.left(1) != ".") + if (fileName.at(0) != '.') { fileName = "./" + relativePath; } @@ -2689,7 +2685,7 @@ bool Project::loadProjectSettings(QString settingsFileName) { // modify project path QString newProjectPath; - if(myPath.left(1) == ".") + if (myPath.at(0) == '.') { newProjectPath = getProjectPath() + myPath; } diff --git a/agrolib/project/project.h b/agrolib/project/project.h index ffa784339..01b210f08 100644 --- a/agrolib/project/project.h +++ b/agrolib/project/project.h @@ -241,9 +241,8 @@ bool loadTopographicDistanceMaps(bool onlyWithData, bool showInfo); void passInterpolatedTemperatureToHumidityPoints(Crit3DTime myTime, Crit3DMeteoSettings *meteoSettings); - bool checkInterpolationMain(meteoVariable myVar); - bool checkInterpolationMainSimple(meteoVariable myVar); - bool interpolationGridMain(meteoVariable myVar, const Crit3DTime& myTime); + bool checkInterpolation(meteoVariable myVar); + bool checkInterpolationGrid(meteoVariable myVar); bool interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime); bool interpolationDemMain(meteoVariable myVar, const Crit3DTime& myTime, gis::Crit3DRasterGrid *myRaster); bool interpolationDem(meteoVariable myVar, const Crit3DTime& myTime, gis::Crit3DRasterGrid *myRaster);