Skip to content

Commit

Permalink
update vine3D
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jul 15, 2024
1 parent 73b9125 commit a9f1f03
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
8 changes: 7 additions & 1 deletion bin/CRITERIA3D/shared/project3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,19 @@ bool Project3D::loadSoilMap(QString fileName)

fileName = getCompleteFileName(fileName, PATH_GEO);

gis::Crit3DRasterGrid inputGrid;
std::string errorStr;
if (! gis::openRaster(fileName.toStdString(), &soilMap, gisSettings.utmZone, errorStr))
if (! gis::openRaster(fileName.toStdString(), &inputGrid, gisSettings.utmZone, errorStr))
{
logError("Loading soil map failed: " + fileName + "\n" + QString::fromStdString(errorStr));
return false;
}

// compute prevailing map
soilMap.initializeGrid(DEM);
gis::prevailingMap(inputGrid, &(soilMap));
gis::updateMinMaxRasterGrid(&(soilMap));

soilMapFileName = fileName;
logInfo("Soil map = " + soilMapFileName);

Expand Down
31 changes: 14 additions & 17 deletions bin/VINE3D/vine3DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,19 @@ bool Vine3DProject::loadVine3DProject(QString projectFileName)
return false;
}

QString fileName = getCompleteFileName(landUseMapFileName, PATH_GEO);
if (! loadFieldMap(fileName))
if (! loadSoilMap(soilMapFileName))
{
logError();
return false;
}

fileName = getCompleteFileName(soilMapFileName, PATH_GEO);
if (! loadSoilMap(fileName))
if (! setSoilIndexMap())
{
logError();
return false;
}

if (! setSoilIndexMap())
if (! loadFieldMap(landUseMapFileName))
{
logError();
return false;
Expand Down Expand Up @@ -426,22 +424,19 @@ int Vine3DProject::getCaseIndexFromId(int caseId)
}


void Vine3DProject::setModelCasesMap(gis::Crit3DRasterGrid &myGrid)
void Vine3DProject::setModelCasesMap()
{
int fieldId, fieldIndex;

// transform from id to index
for (int row = 0; row < myGrid.header->nrRows; row++)
for (int row = 0; row < landUseMap.header->nrRows; row++)
{
for (int col = 0; col < myGrid.header->nrCols; col++)
for (int col = 0; col < landUseMap.header->nrCols; col++)
{
fieldId = int(myGrid.value[row][col]);
if (! isEqual(fieldId, myGrid.header->flag))
float value = landUseMap.value[row][col];
if (! isEqual(value, landUseMap.header->flag) )
{
fieldIndex = getCaseIndexFromId(fieldId);
int fieldIndex = getCaseIndexFromId(value);
if (fieldIndex != NODATA)
{
myGrid.value[row][col] = fieldIndex;
landUseMap.value[row][col] = fieldIndex;
}
}
}
Expand All @@ -453,7 +448,9 @@ bool Vine3DProject::loadFieldMap(QString mapFileName)
{
logInfo ("Read fields map...");

std::string fn = mapFileName.left(mapFileName.length()-4).toStdString();
QString fileName = getCompleteFileName(mapFileName, PATH_GEO);

std::string fn = fileName.left(fileName.length()-4).toStdString();
gis::Crit3DRasterGrid inputGrid;

std::string errorStr;
Expand All @@ -469,7 +466,7 @@ bool Vine3DProject::loadFieldMap(QString mapFileName)
gis::prevailingMap(inputGrid, &(landUseMap));
gis::updateMinMaxRasterGrid(&(landUseMap));

setModelCasesMap(landUseMap);
setModelCasesMap();

logInfo ("Field map = " + mapFileName);
return true;
Expand Down
2 changes: 1 addition & 1 deletion bin/VINE3D/vine3DProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
bool initializeGrapevine();

int getCaseIndexFromId(int caseId);
void setModelCasesMap(gis::Crit3DRasterGrid &myGrid);
void setModelCasesMap();

int queryFieldPoint(double x, double y);
bool loadFieldMap(QString mapFileName);
Expand Down

0 comments on commit a9f1f03

Please sign in to comment.