Skip to content

Commit

Permalink
update criteriaGEo project
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Oct 25, 2023
1 parent a96f1f0 commit 88d3eec
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 119 deletions.
9 changes: 5 additions & 4 deletions agrolib/criteriaOutput/criteriaOutput.pro
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,24 @@ DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += _CRT_SECURE_NO_WARNINGS


INCLUDEPATH += ../crit3dDate ../mathFunctions ../gis ../utilities \
../shapeHandler ../netcdfHandler ../shapeUtilities

SOURCES += \
../../agrolib/crop/cropDbQuery.cpp \
../crop/cropDbQuery.cpp \
criteriaAggregationVariable.cpp \
criteriaOutputElaboration.cpp \
criteriaOutputProject.cpp \
criteriaOutputVariable.cpp

HEADERS += \
../crop/cropDbQuery.h \
criteriaAggregationVariable.h \
criteriaOutputElaboration.h \
criteriaOutputProject.h \
criteriaOutputVariable.h


INCLUDEPATH += ../crit3dDate ../mathFunctions ../crop ../gis \
../utilities ../shapeHandler ../netcdfHandler ../shapeUtilities

# comment to compile without GDAL library
CONFIG += GDAL

Expand Down
2 changes: 1 addition & 1 deletion agrolib/criteriaOutput/criteriaOutputElaboration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "commonConstants.h"
#include "basicMath.h"
#include "utilities.h"
#include "cropDbQuery.h"
#include "../crop/cropDbQuery.h"

#include <QSqlQuery>
#include <QSqlError>
Expand Down
56 changes: 28 additions & 28 deletions agrolib/shapeUtilities/unitCropMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
#include <QFile>


bool computeUcmPrevailing(Crit3DShapeHandler &ucm, Crit3DShapeHandler &crop, Crit3DShapeHandler &soil, Crit3DShapeHandler &meteo,
bool computeUcmPrevailing(Crit3DShapeHandler &shapeUCM, Crit3DShapeHandler &shapeCrop, Crit3DShapeHandler &shapeSoil, Crit3DShapeHandler &shapeMeteo,
std::string idCrop, std::string idSoil, std::string idMeteo, double cellSize, double threshold,
QString ucmFileName, std::string &error, bool showInfo)
{

// make a copy of crop shapefile (reference) and return cloned shapefile complete path
QString refFileName = QString::fromStdString(crop.getFilepath());
QString refFileName = QString::fromStdString(shapeCrop.getFilepath());
QString ucmShapeFileName = cloneShapeFile(refFileName, ucmFileName);

if (!ucm.open(ucmShapeFileName.toStdString()))
if (!shapeUCM.open(ucmShapeFileName.toStdString()))
{
error = "Load shapefile failed: " + ucmShapeFileName.toStdString();
return false;
Expand All @@ -27,37 +27,37 @@ bool computeUcmPrevailing(Crit3DShapeHandler &ucm, Crit3DShapeHandler &crop, Cri
// create reference and value raster
gis::Crit3DRasterGrid rasterRef;
gis::Crit3DRasterGrid rasterVal;
initializeRasterFromShape(ucm, rasterRef, cellSize);
initializeRasterFromShape(ucm, rasterVal, cellSize);
initializeRasterFromShape(shapeUCM, rasterRef, cellSize);
initializeRasterFromShape(shapeUCM, rasterVal, cellSize);

FormInfo formInfo;

// CROP (reference shape)
if (showInfo) formInfo.start("[1/8] Rasterize crop (reference)...", 0);
fillRasterWithShapeNumber(rasterRef, ucm);
fillRasterWithShapeNumber(rasterRef, shapeUCM);

// meteo grid
if (showInfo) formInfo.setText("[2/8] Rasterize meteo grid...");
fillRasterWithShapeNumber(rasterVal, meteo);
fillRasterWithShapeNumber(rasterVal, shapeMeteo);

if (showInfo) formInfo.setText("[3/8] Compute matrix crop/meteo...");
std::vector <int> vectorNull;
std::vector <std::vector<int> > matrix = computeMatrixAnalysis(ucm, meteo, rasterRef, rasterVal, vectorNull);
std::vector <std::vector<int> > matrix = computeMatrixAnalysis(shapeUCM, shapeMeteo, rasterRef, rasterVal, vectorNull);

if (showInfo) formInfo.setText("[4/8] Zonal statistic crop/meteo...");
bool isOk = zonalStatisticsShapeMajority(ucm, meteo, matrix, vectorNull, idMeteo, "ID_METEO", threshold, error);
bool isOk = zonalStatisticsShapeMajority(shapeUCM, shapeMeteo, matrix, vectorNull, idMeteo, "ID_METEO", threshold, error);

// zonal statistic on soil map
if (isOk)
{
if (showInfo) formInfo.setText("[5/8] Rasterize soil...");
fillRasterWithShapeNumber(rasterVal, soil);
fillRasterWithShapeNumber(rasterVal, shapeSoil);

if (showInfo) formInfo.setText("[6/8] Compute matrix crop/soil...");
matrix = computeMatrixAnalysis(ucm, soil, rasterRef, rasterVal, vectorNull);
matrix = computeMatrixAnalysis(shapeUCM, shapeSoil, rasterRef, rasterVal, vectorNull);

if (showInfo) formInfo.setText("[7/8] Zonal statistic crop/soil...");
isOk = zonalStatisticsShapeMajority(ucm, soil, matrix, vectorNull, idSoil, "ID_SOIL", threshold, error);
isOk = zonalStatisticsShapeMajority(shapeUCM, shapeSoil, matrix, vectorNull, idSoil, "ID_SOIL", threshold, error);
}

if (! isOk)
Expand All @@ -79,29 +79,29 @@ bool computeUcmPrevailing(Crit3DShapeHandler &ucm, Crit3DShapeHandler &crop, Cri
if (showInfo) formInfo.setText("[8/8] Write UCM...");

// add ID CASE
ucm.addField("ID_CASE", FTString, 20, 0);
int idCaseIndex = ucm.getFieldPos("ID_CASE");
shapeUCM.addField("ID_CASE", FTString, 20, 0);
int idCaseIndex = shapeUCM.getFieldPos("ID_CASE");

// add ID CROP
bool existIdCrop = ucm.existField("ID_CROP");
if (! existIdCrop) ucm.addField("ID_CROP", FTString, 5, 0);
int idCropIndex = ucm.getFieldPos("ID_CROP");
bool existIdCrop = shapeUCM.existField("ID_CROP");
if (! existIdCrop) shapeUCM.addField("ID_CROP", FTString, 5, 0);
int idCropIndex = shapeUCM.getFieldPos("ID_CROP");

// read indexes
int nShape = ucm.getShapeCount();
int cropIndex = ucm.getFieldPos(idCrop);
int nShape = shapeUCM.getShapeCount();
int cropIndex = shapeUCM.getFieldPos(idCrop);
if(cropIndex == -1)
{
error = "Missing idCrop: " + idCrop;
return false;
}
int soilIndex = ucm.getFieldPos("ID_SOIL");
int soilIndex = shapeUCM.getFieldPos("ID_SOIL");
if(soilIndex == -1)
{
error = "Missing idSoil: " + idSoil;
return false;
}
int meteoIndex = ucm.getFieldPos("ID_METEO");
int meteoIndex = shapeUCM.getFieldPos("ID_METEO");
if(meteoIndex == -1)
{
error = "Missing idMeteo: " + idMeteo;
Expand All @@ -111,28 +111,28 @@ bool computeUcmPrevailing(Crit3DShapeHandler &ucm, Crit3DShapeHandler &crop, Cri
// FILL ID_CROP and ID_CASE
for (int shapeIndex = 0; shapeIndex < nShape; shapeIndex++)
{
std::string cropStr = ucm.readStringAttribute(shapeIndex, cropIndex);
std::string cropStr = shapeUCM.readStringAttribute(shapeIndex, cropIndex);
if (cropStr == "-9999") cropStr = "";

std::string soilStr = ucm.readStringAttribute(shapeIndex, soilIndex);
std::string soilStr = shapeUCM.readStringAttribute(shapeIndex, soilIndex);
if (soilStr == "-9999") soilStr = "";

std::string meteoStr = ucm.readStringAttribute(shapeIndex, meteoIndex);
std::string meteoStr = shapeUCM.readStringAttribute(shapeIndex, meteoIndex);
if (meteoStr == "-9999") meteoStr = "";

std::string caseStr = "";
if (meteoStr != "" && soilStr != "" && cropStr != "")
caseStr = "M" + meteoStr + "S" + soilStr + "C" + cropStr;

if (! existIdCrop) ucm.writeStringAttribute(shapeIndex, idCropIndex, cropStr.c_str());
ucm.writeStringAttribute(shapeIndex, idCaseIndex, caseStr.c_str());
if (! existIdCrop) shapeUCM.writeStringAttribute(shapeIndex, idCropIndex, cropStr.c_str());
shapeUCM.writeStringAttribute(shapeIndex, idCaseIndex, caseStr.c_str());

if (caseStr == "")
ucm.deleteRecord(shapeIndex);
shapeUCM.deleteRecord(shapeIndex);
}

if (showInfo) formInfo.close();
cleanShapeFile(ucm);
cleanShapeFile(shapeUCM);

return isOk;
}
Expand Down
3 changes: 2 additions & 1 deletion agrolib/shapeUtilities/unitCropMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#endif
#include <QString>

bool computeUcmPrevailing(Crit3DShapeHandler &ucm, Crit3DShapeHandler &crop, Crit3DShapeHandler &soil, Crit3DShapeHandler &meteo,
bool computeUcmPrevailing(Crit3DShapeHandler &shapeUCM, Crit3DShapeHandler &shapeCrop,
Crit3DShapeHandler &shapeSoil, Crit3DShapeHandler &shapeMeteo,
std::string idCrop, std::string idSoil, std::string idMeteo, double cellSize, double threshold,
QString ucmFileName, std::string &error, bool showInfo);

Expand Down
4 changes: 2 additions & 2 deletions agrolib/utilities/computationUnitsDb.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* \brief computation unit for CRITERIA-1D
* \note Unit = distinct combination of crop, soil and meteo
* \brief computational unit for CRITERIA-1D
* \note computational unit = distinct combination of crop, soil and meteo
*/

#ifndef COMPUTATIONUNITSDB_H
Expand Down
12 changes: 5 additions & 7 deletions bin/CRITERIAGEO/CRITERIAGEO.pro
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ win32:{
}

INCLUDEPATH += ../../mapGraphics \
../../agrolib/crit3dDate ../../agrolib/mathFunctions ../../agrolib/gis ../../agrolib/crop \
../../agrolib/crit3dDate ../../agrolib/mathFunctions ../../agrolib/gis ../../agrolib/meteo \
../../agrolib/utilities ../../agrolib/shapeUtilities \
../../agrolib/shapeHandler ../../agrolib/shapeHandler/shapelib ../../agrolib/netcdfHandler \
../../agrolib/criteriaOutput ../../agrolib/graphics ../../agrolib/commonDialogs
Expand All @@ -62,6 +62,7 @@ CONFIG(debug, debug|release) {

LIBS += -L../../mapGraphics/debug -lMapGraphics
LIBS += -L../../agrolib/commonDialogs/debug -lcommonDialogs
LIBS += -L../../agrolib/graphics/debug -lgraphics
LIBS += -L../../agrolib/criteriaOutput/debug -lcriteriaOutput
LIBS += -L../../agrolib/netcdfHandler/debug -lnetcdfHandler
win32:{
Expand All @@ -76,6 +77,7 @@ CONFIG(debug, debug|release) {
LIBS += -L../../agrolib/shapeUtilities/debug -lshapeUtilities
LIBS += -L../../agrolib/shapeHandler/debug -lshapeHandler
LIBS += -L../../agrolib/utilities/debug -lutilities
LIBS += -L../../agrolib/meteo/debug -lmeteo
LIBS += -L../../agrolib/gis/debug -lgis
LIBS += -L../../agrolib/crit3dDate/debug -lcrit3dDate
LIBS += -L../../agrolib/mathFunctions/debug -lmathFunctions
Expand All @@ -84,6 +86,7 @@ CONFIG(debug, debug|release) {

LIBS += -L../../mapGraphics/release -lMapGraphics
LIBS += -L../../agrolib/commonDialogs/release -lcommonDialogs
LIBS += -L../../agrolib/graphics/release -lgraphics
LIBS += -L../../agrolib/criteriaOutput/release -lcriteriaOutput
LIBS += -L../../agrolib/netcdfHandler/release -lnetcdfHandler
win32:{
Expand All @@ -98,15 +101,13 @@ CONFIG(debug, debug|release) {
LIBS += -L../../agrolib/shapeUtilities/release -lshapeUtilities
LIBS += -L../../agrolib/shapeHandler/release -lshapeHandler
LIBS += -L../../agrolib/utilities/release -lutilities
LIBS += -L../../agrolib/meteo/release -lmeteo
LIBS += -L../../agrolib/gis/release -lgis
LIBS += -L../../agrolib/crit3dDate/release -lcrit3dDate
LIBS += -L../../agrolib/mathFunctions/release -lmathFunctions
}

HEADERS += \
../../agrolib/graphics/mapGraphicsRasterObject.h \
../../agrolib/graphics/mapGraphicsShapeObject.h \
../../agrolib/graphics/colorLegend.h \
criteriaGeoProject.h \
dialogDbfNewCol.h \
dialogDbfTable.h \
Expand All @@ -122,9 +123,6 @@ HEADERS += \
tableDbf.h

SOURCES += \
../../agrolib/graphics/mapGraphicsRasterObject.cpp \
../../agrolib/graphics/mapGraphicsShapeObject.cpp \
../../agrolib/graphics/colorLegend.cpp \
criteriaGeoProject.cpp \
dialogDbfNewCol.cpp \
dialogDbfTable.cpp \
Expand Down
12 changes: 6 additions & 6 deletions bin/CRITERIAGEO/criteriaGeoProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,21 @@ void CriteriaGeoProject::getRasterFromShape(Crit3DShapeHandler &shape, QString f
}


bool CriteriaGeoProject::addUnitCropMap(Crit3DShapeHandler *crop, Crit3DShapeHandler *soil, Crit3DShapeHandler *meteo,
bool CriteriaGeoProject::addUnitCropMap(Crit3DShapeHandler *shapeCrop, Crit3DShapeHandler *shapeSoil, Crit3DShapeHandler *shapeMeteo,
std::string idCrop, std::string idSoil, std::string idMeteo,
double cellSize, double threshold,
QString ucmFileName, bool isPrevailing, bool showInfo)
{
std::string errorStr;

Crit3DShapeHandler *ucm = new(Crit3DShapeHandler);
Crit3DShapeHandler *shapeUCM = new(Crit3DShapeHandler);

if (isPrevailing)
{
if (computeUcmPrevailing(*ucm, *crop, *soil, *meteo, idCrop, idSoil, idMeteo,
if (computeUcmPrevailing(*shapeUCM, *shapeCrop, *shapeSoil, *shapeMeteo, idCrop, idSoil, idMeteo,
cellSize, threshold, ucmFileName, errorStr, showInfo))
{
addShapeFile(ucm, QString::fromStdString(ucm->getFilepath()), "", ucm->getUtmZone());
addShapeFile(ucm, QString::fromStdString(shapeUCM->getFilepath()), "", shapeUCM->getUtmZone());
return true;
}
else
Expand All @@ -187,9 +187,9 @@ bool CriteriaGeoProject::addUnitCropMap(Crit3DShapeHandler *crop, Crit3DShapeHan
{
#ifdef GDAL
/*
if (computeUcmIntersection(ucm, crop, soil, meteo, idCrop, idSoil, idMeteo, ucmFileName, &errorStr))
if (computeUcmIntersection(shapeUCM, shapeCrop, shapeSoil, shapeMeteo, idCrop, idSoil, idMeteo, ucmFileName, &errorStr))
{
addShapeFile(ucm, QString::fromStdString(ucm->getFilepath()), "", ucm->getUtmZone());
addShapeFile(shapeUCM, QString::fromStdString(shapeUCM->getFilepath()), "", shapeUCM->getUtmZone());
return true;
}
else
Expand Down
2 changes: 1 addition & 1 deletion bin/CRITERIAGEO/criteriaGeoProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

bool extractUcmListToDb(Crit3DShapeHandler* shapeHandler, bool showInfo);

bool addUnitCropMap(Crit3DShapeHandler *crop, Crit3DShapeHandler *soil, Crit3DShapeHandler *meteo,
bool addUnitCropMap(Crit3DShapeHandler *shapeCrop, Crit3DShapeHandler *shapeSoil, Crit3DShapeHandler *shapeMeteo,
std::string idCrop, std::string idSoil, std::string idMeteo,
double cellSize, double threshold, QString ucmFileName, bool isPrevailing, bool showInfo);

Expand Down
Loading

0 comments on commit 88d3eec

Please sign in to comment.