32Layers::Layers(
ThreadManager* MTHREAD_h,
string name_h,
string label_h,
bool isInteger_h,
bool dynamicContent_h,
string fullFilename_h,
bool display_h)
48Layers::addLegendItem(
int ID_h,
string label_h,
int rColor_h,
int gColor_h,
int bColor_h,
double minValue_h,
double maxValue_h){
52 msgOut(
MSG_ERROR,
"Trying to add a legend item that already exist on this layer (layer: "+
label+
" - legend label: "+label_h+
")");
73 vector <LegendItems> toAdd;
74 for(uint i=0; i<legendItems_h.size();i++){
75 bool existing =
false;
83 msgOut(
MSG_WARNING,
"Legend item "+
i2s(legendItems_h[i].ID)+
" non added on layer "+this->
name+
" as already existing.");
85 toAdd.push_back(legendItems_h[i]);
99 std::vector <double> cumPVector;
100 std::vector <double> outCodesVector;
108 cumPVector.push_back(cumP);
112 if (!check) {
return code_h;}
113 if (cumP <= 0.99999999 || cumP >= 1.00000001){
msgOut(
MSG_CRITICAL_ERROR,
"the sum of land use reclassification rules is not 1 for at least one input code (input code: "+
d2s(code_h)+
"; cumP: "+
d2s(cumP)+
")");}
116 random = ((double)rand() / ((double)(RAND_MAX)+(double)(1)) );
117 for(uint i=0; i<cumPVector.size(); i++){
118 if (random <= cumPVector.at(i)){
119 returnCode = outCodesVector.at(i);
133 QColor nocolor(255,255,255);
195 for (uint j=0;j<totPixels;j++){
227 vector <double> origValues;
230 for (uint i=0;i<totPixels;i++){
233 origValues.push_back(pxValue);
237 random_shuffle(origValues.begin(), origValues.end());
239 for (uint i=0;i<totPixels;i++){
242 double toChangeValue = origValues.at(origValues.size()-1);
244 origValues.pop_back();
256 string mapGridOutputDirectory = mapBaseDirectory+
"asciiGrids/";
257 string catsOutputDirectory = mapBaseDirectory+
"cats/";
258 string coloursOutputDirectory = mapBaseDirectory+
"colr/";
285 msgOut(
MSG_ERROR,
"The X resolution is different to the Y resolution. I am exporting the map in ArcInfo ASCII Grid format using the X resolution, but be aware that it is incorrect, as this format doesn't support different X-Y resolutions.");
293 outm.open(mapFilename.c_str(), ios::out);
294 if (!outm){
msgOut(
MSG_ERROR,
"Error in opening the file "+mapFilename+
".");}
295 outm << header <<
"\n";
307 outc.open(catsFilename.c_str(), ios::out);
308 if (!outc){
msgOut(
MSG_ERROR,
"Error in opening the file "+catsFilename+
".");}
310 outc <<
"0.00 0.00 0.00 0.00"<<
"\n";
325 outcl.open(coloursFilename.c_str(), ios::out);
326 if (!outcl){
msgOut(
MSG_ERROR,
"Error in opening the file "+coloursFilename+
".");}
343 outList.open(filenameListIntLayers.c_str(), ios::app);
347 outList.open(filenameListFloatLayers.c_str(), ios::app);
367 QImage image = QImage(subXR-subXL+1, subYB-subYT+1, QImage::Format_RGB32);
368 image.fill(qRgb(255, 255, 255));
369 for (
int countRow=subYT;countRow<subYB;countRow++){
370 for (
int countColumn=subXL;countColumn<subXR;countColumn++){
372 QColor color = this->
getColor(value);
373 image.setPixel(countColumn-subXL,countRow-subYT,color.rgb());
376 image.save(mapFilename.c_str());
@ DATA_NOW
The required data is for the current year.
@ OUTVL_MAPS
Output verbosity level print (also) the maps in ascii grid format.
@ MSG_CRITICAL_ERROR
Print an error message and stop the model.
@ MSG_ERROR
Print an ERROR message, but don't stop the model.
@ MSG_WARNING
Print a WARNING message.
@ MSG_INFO
Print an INFO message.
ThreadManager * MTHREAD
Pointer to the Thread manager.
string d2s(const double &double_h) const
double to string conversion
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
string i2s(const int &int_h) const
integer to string conversion
double getYMetersByPixel() const
int getYNPixels() const
Return the number of pixels on X.
double getXyNPixels() const
Return the number of pixels on Y.
double getNoValue() const
Pixel * getPixel(int x_h, int y_h)
double getGeoTopY() const
Return a pixel pointer from its ID.
double getGeoLeftX() const
double getGeoRightX() const
double getXMetersByPixel() const
double getGeoBottomY() const
vector< LegendItems > legendItems
Vector of legend items.
void print()
Print the layer content as an ASCII grid map with its companion files (classification and colors)....
string label
Label of the layer (spaces allowed)
bool display
Normally true, but some layers used to just keep data shoudn't be normally processed.
void addLegendItem(int ID_h, string label_h, int rColor_h, int gColor_h, int bColor_h, double minValue_h, double maxValue_h)
Add a legend item.
bool dynamicContent
True if the content may change during simulation year.
string name
ID of the layer (no spaces allowed)
vector< ReclassRules > reclassRulesVector
Vector of initial reclassification rules.
Layers(ThreadManager *MTHREAD_h, string name_h, string label_h, bool isInteger_h, bool dynamicContent_h, string fullFilename_h, bool display_h=true)
In the constructor we set the main layer properties.
double filterExogenousDataset(double code_h)
Used to reclassify the land use map for "generic" categories.
string fullFileName
Filename of the associated dataset (map)
void printBinMap()
Print a binary reppresentation of the data (a standard image, e.g. a .png file). It prints only the s...
void countMyPixels(bool debug=false)
Count the pixels going to each legend item and print them if debug==true.
QColor getColor(double ID_h)
Evaluates all the legend items to find the one that match the input code, and return its color as a Q...
void addLegendItems(vector< LegendItems > legendItems_h)
void randomShuffle()
For some sensitivity analisys, random the values for this layer for not-empty values (only integer la...
bool isInteger
Type of the layer (true==integer, false==double. If true, on each legend item: minValue==maxValue==ID...
string getCategory(double ID_h)
Evaluates all the legend items to find the one that match the input code, and return its label.
string getOutputDirectory() const
Return a vector of objects that together provide the specified resource in the specified quantity.
string getBaseDirectory() const
int getIntSetting(const string &name_h, int position=0, int reg=WORLD) const
void changeValue(const string &layerName_h, const double &value_h, const bool &setNoValueForZero=false)
Change the value of an existing layerMTHREAD->GIS->pack(parName, forName, dClass, year),...
double getDoubleValue(const string &layerName_h, const bool &returnZeroForNoValue=false) const
Return the value for a specific layer.
Thread manager. Responsable to manage the main thread and "speak" with the GUI.
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
Gis * GIS
GIS information and methods.
ModelData * MD
the model data object
int cashedCount
count the pixels whitin a item range