Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ARPA-SIMC/CRITERIA1D
Browse files Browse the repository at this point in the history
  • Loading branch information
giadasan committed Oct 27, 2023
2 parents 97a54e0 + ccab197 commit 4f8f5f1
Show file tree
Hide file tree
Showing 28 changed files with 464 additions and 358 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
15 changes: 14 additions & 1 deletion agrolib/gis/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,20 @@ unsigned int Crit3DColorScale::getColorIndex(float value)
}


bool setDefaultDEMScale(Crit3DColorScale* myScale)
bool setDefaultScale(Crit3DColorScale* myScale)
{
myScale->initialize(4, 256);

myScale->keyColor[0] = Crit3DColor(0, 0, 255); /*!< blue */
myScale->keyColor[1] = Crit3DColor(64, 196, 64); /*!< green */
myScale->keyColor[2] = Crit3DColor(255, 255, 0); /*!< yellow */
myScale->keyColor[3] = Crit3DColor(255, 0, 0); /*!< red */

return(myScale->classify());
}


bool setDTMScale(Crit3DColorScale* myScale)
{
myScale->initialize(4, 256);

Expand Down
3 changes: 2 additions & 1 deletion agrolib/gis/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
bool isRangeBlocked() { return _isRangeBlocked; }
};

bool setDefaultDEMScale(Crit3DColorScale* myScale);
bool setDefaultScale(Crit3DColorScale* myScale);
bool setDTMScale(Crit3DColorScale* myScale);
bool setTemperatureScale(Crit3DColorScale* myScale);
bool setAnomalyScale(Crit3DColorScale* myScale);
bool setPrecipitationScale(Crit3DColorScale* myScale);
Expand Down
72 changes: 33 additions & 39 deletions agrolib/graphics/mapGraphicsShapeObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ MapGraphicsShapeObject::MapGraphicsShapeObject(MapGraphicsView* _view, MapGraphi
isFill = false;
shapePointer = nullptr;
nrShapes = 0;
selectedShape = NODATA;

updateCenter();
}

Expand Down Expand Up @@ -59,12 +61,14 @@ void MapGraphicsShapeObject::paint(QPainter *painter, const QStyleOptionGraphics
Q_UNUSED(option)
Q_UNUSED(widget)

if (this->isDrawing)
if (isDrawing)
{
setMapExtents();

if (this->shapePointer != nullptr)
if (shapePointer != nullptr)
{
drawShape(painter);
}
}
}

Expand Down Expand Up @@ -112,24 +116,30 @@ void MapGraphicsShapeObject::drawShape(QPainter* myPainter)
QColor color;
std::vector<unsigned int> myHoles;

myPainter->setPen(QColor(64, 64, 64));
myPainter->setBrush(Qt::NoBrush);

for (unsigned long i = 0; i < nrShapes; i++)
{
if (isFill)
QPen myPen;
if (i != selectedShape)
{
myPen.setColor(QColor(64, 64, 64));
myPen.setWidth(1);
}
else
{
myPen.setColor(QColor(255, 0, 0));
myPen.setWidth(5);
}
myPainter->setPen(myPen);
myPainter->setBrush(Qt::NoBrush);

if (isFill && values[i] != NODATA)
{
if (values[i] != NODATA)
Crit3DColor* myColor = colorScale->getColor(values[i]);
color = QColor(myColor->red, myColor->green, myColor->blue);
myPainter->setBrush(color);
if (i != selectedShape)
{
Crit3DColor* myColor = colorScale->getColor(values[i]);
color = QColor(myColor->red, myColor->green, myColor->blue);
myPainter->setPen(color);
myPainter->setBrush(color);
}
else
{
myPainter->setPen(QColor(64, 64, 64));
myPainter->setBrush(Qt::NoBrush);
}
}

Expand Down Expand Up @@ -188,8 +198,6 @@ bool MapGraphicsShapeObject::initializeUTM(Crit3DShapeHandler* shapePtr)
double lat, lon;
ShapeObject myShape;
Box<double>* bounds;
const Point<double> *p_ptr;
Point<double> point;

nrShapes = unsigned(shapePointer->getShapeCount());
shapeParts.resize(nrShapes);
Expand All @@ -200,8 +208,10 @@ bool MapGraphicsShapeObject::initializeUTM(Crit3DShapeHandler* shapePtr)
double refLatitude = geoMap->referencePoint.latitude;

int zoneNumber = shapePtr->getUtmZone();
if (zoneNumber < 1 || zoneNumber > 60)
if ((zoneNumber < 1) || (zoneNumber > 60))
{
return false;
}

for (unsigned int i = 0; i < nrShapes; i++)
{
Expand Down Expand Up @@ -230,13 +240,14 @@ bool MapGraphicsShapeObject::initializeUTM(Crit3DShapeHandler* shapePtr)
// vertices
unsigned long nrVertices = myShape.getVertexCount();
geoPoints[i].resize(nrVertices);
p_ptr = myShape.getVertices();

const Point<double> *pointPtr = myShape.getVertices();
for (unsigned long j = 0; j < nrVertices; j++)
{
gis::utmToLatLon(zoneNumber, refLatitude, p_ptr->x, p_ptr->y, &lat, &lon);
gis::utmToLatLon(zoneNumber, refLatitude, pointPtr->x, pointPtr->y, &lat, &lon);
geoPoints[i][j].lat = lat;
geoPoints[i][j].lon = lon;
p_ptr++;
pointPtr++;
}
}

Expand All @@ -245,12 +256,6 @@ bool MapGraphicsShapeObject::initializeUTM(Crit3DShapeHandler* shapePtr)
}


Crit3DShapeHandler* MapGraphicsShapeObject::getShapePointer()
{
return this->shapePointer;
}


// warning: call after initializeUTM
void MapGraphicsShapeObject::setNumericValues(std::string fieldName)
{
Expand Down Expand Up @@ -284,6 +289,7 @@ int MapGraphicsShapeObject::getCategoryIndex(std::string strValue)
{
if (categories[i] == strValue) return signed(i);
}

return NODATA;
}

Expand Down Expand Up @@ -325,18 +331,6 @@ void MapGraphicsShapeObject::setCategories(std::string fieldName)
}


void MapGraphicsShapeObject::setFill(bool value)
{
isFill = value;
}


void MapGraphicsShapeObject::setDrawing(bool value)
{
this->isDrawing = value;
}


void MapGraphicsShapeObject::setMapExtents()
{
int widthPixels = view->width() - MAPBORDER*2;
Expand Down
11 changes: 8 additions & 3 deletions agrolib/graphics/mapGraphicsShapeObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
QPointF referencePixel;

unsigned int nrShapes;
unsigned int selectedShape;

std::vector< std::vector<ShapeObject::Part>> shapeParts;
std::vector< std::vector<GeoBounds>> geoBounds;
std::vector< std::vector<LatLonPoint>> geoPoints;
Expand Down Expand Up @@ -76,16 +78,19 @@

Crit3DColorScale* colorScale;

void setDrawing(bool value);
void updateCenter();
void clear();

bool initializeUTM(Crit3DShapeHandler* shapePtr);
void setNumericValues(std::string fieldName);
void setCategories(std::string fieldName);

void setFill(bool value);
Crit3DShapeHandler* getShapePointer();
int getSelected() { return selectedShape; }
void setSelected(int index) { selectedShape = index; }
void setFill(bool value) { isFill = value; }
void setDrawing(bool value) { isDrawing = value; }

Crit3DShapeHandler* getShapePointer() { return shapePointer; }

QPointF getPixel(const LatLonPoint &geoPoint);
};
Expand Down
8 changes: 5 additions & 3 deletions agrolib/meteo/meteo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,11 @@ bool setColorScale(meteoVariable variable, Crit3DColorScale *colorScale)
case dailyAirTemperatureMin: case dailyAirTemperatureRange:
case airDewTemperature:
case snowSurfaceTemperature:
case elaboration:
setTemperatureScale(colorScale);
break;
case elaboration:
setDefaultScale(colorScale);
break;
case airRelHumidity: case dailyAirRelHumidityAvg: case dailyAirRelHumidityMax:
case dailyAirRelHumidityMin: case leafWetness: case dailyLeafWetness:
case thom: case dailyThomMax: case dailyThomAvg: case dailyThomHoursAbove: case dailyThomDaytime: case dailyThomNighttime:
Expand Down Expand Up @@ -805,11 +807,11 @@ bool setColorScale(meteoVariable variable, Crit3DColorScale *colorScale)
setAnomalyScale(colorScale);
break;
case noMeteoTerrain:
setDefaultDEMScale(colorScale);
setDTMScale(colorScale);
break;

default:
setDefaultDEMScale(colorScale);
setDefaultScale(colorScale);
}

return true;
Expand Down
Loading

0 comments on commit 4f8f5f1

Please sign in to comment.