FFSM++  1.1.0
French Forest Sector Model ++
Gis Class Reference

Class to manage the spatial dimension. More...

#include <Gis.h>

Inheritance diagram for Gis:
Collaboration diagram for Gis:

Public Member Functions

 Gis (ThreadManager *MTHREAD_h)
 Constructor. More...
 
 ~Gis ()
 
void setSpace ()
 Set the initial space environment, including loading data from files. More...
 
void initLayers ()
 Init the layers. More...
 
void initLayersPixelData ()
 
void initLayersModelData (const int &year_h=DATA_NOW)
 
void applyForestReclassification ()
 Apply the forest reclassification with the rules defined in reclRules sheet. More...
 
void filterSubRegion (string layerName_h)
 If subregion mode is on, this function place noValues on the selected layer for all out-of-region pixels. More...
 
void updateImage (string layerName_h)
 Add one layer to the system. More...
 
void addLayer (string name_h, string label_h, bool isInteger_h, bool dynamicContent_h, string fullFileName_h="", bool display_h=true)
 Fill a layer with empty values. More...
 
void resetLayer (string layerName_h)
 Check if a layer with a certain name is loaded in the model. Used e.g. to check if the dtm layer (optional) exist. More...
 
bool layerExist (const string &layerName_h, bool exactMatch=true) const
 Return a pointer to a layer given its name. More...
 
LayersgetLayer (const string &layerName_h)
 Add a legend item to an existing layer. More...
 
void addLegendItem (string name_h, int D_h, string label_h, int rColor_h, int gColor_h, int bColor_h, double minValue_h, double maxValue_h)
 
void countItems (const string &layerName_h, const bool &debug=false)
 Count the pixels within each legend item for the selected layer. More...
 
PixelgetRandomPlotByValue (string layer_h, int layerValue__h)
 Return a pointer to a plot with a specific value for the specified layer. More...
 
vector< Pixel * > getAllPlotsByValue (string layer_h, int layerValue_h, int outputLevel=MSG_WARNING)
 Return the vector (shuffled) of all plots with a specific value for a specified layer. It is also possible to specify the level in case of failure. More...
 
vector< Pixel * > getAllPlotsByValue (string layer_h, vector< int > layerValues_h, int outputLevel=MSG_WARNING)
 Return the vector (shuffled) of all plots with specific values for a specified layer. It is also possible to specify the level in case of failure. More...
 
vector< Pixel * > getAllPlots (bool masked=true, int outputLevel=MSG_WARNING)
 Return the vector (shuffled) of all plots. It is also possible to specify the level in case of failure. More...
 
vector< Pixel * > getAllPlotsByRegion (ModelRegion &region_h, bool shuffle=false)
 Return the vector of all plots by a specific region (main region or subregion), optionally shuffled;. More...
 
vector< Pixel * > getAllPlotsByRegion (int regId_h, bool shuffle=false)
 
vector< string > getLayerNames ()
 Return a vector of the layer ids (as string) More...
 
vector< Layers * > getLayerPointers ()
 Return a vector of pointers of existing layers. More...
 
void printLayers (string layerName_h="")
 Print the specified layer or all layers (if param layerName_h is missing). More...
 
void printBinMaps (string layerName_h="")
 Save an image in standard png format. More...
 
void printDebugValues (string layerName_h, int min_h=0, int max_h=0)
 
double getDistance (const Pixel *px1, const Pixel *px2)
 
int getXNPixels () const
 
int getYNPixels () const
 Return the number of pixels on X. More...
 
double getXyNPixels () const
 Return the number of pixels on Y. More...
 
double getHaByPixel () const
 Return the total number of pixels. More...
 
double getNoValue () const
 
PixelgetPixel (int x_h, int y_h)
 
PixelgetPixel (int ID_h)
 Return a pixel pointer from its coordinates. More...
 
double getGeoTopY () const
 Return a pixel pointer from its ID. More...
 
double getGeoBottomY () const
 
double getGeoLeftX () const
 
double getGeoRightX () const
 
double getXMetersByPixel () const
 
double getYMetersByPixel () const
 
int getSubXL () const
 
int getSubXR () const
 
int getSubYT () const
 
int getSubYB () const
 
int sub2realID (int id_h)
 Transform the ID of a pixel in subregion coordinates to the real (and model used) coordinates. More...
 
string pack (const string &parName, const string &forName, const string &dClass, const int &year) const
 
void unpack (const string &key, string &parName, string &forName, string &dClass, int &year) const
 
void swap (const int &swap_what)
 
- Public Member Functions inherited from BaseClass
 BaseClass ()
 
 ~BaseClass ()
 
void msgOut (const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
void msgOut (const int &msgCode_h, const int &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
void msgOut (const int &msgCode_h, const double &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
int s2i (const string &string_h) const
 string to integer conversion More...
 
double s2d (const string &string_h) const
 string to double conversion More...
 
double s2d (const string &string_h, const bool &replaceComma) const
 string to double conversion More...
 
bool s2b (const string &string_h) const
 string to bool conversion More...
 
string i2s (const int &int_h) const
 integer to string conversion More...
 
string d2s (const double &double_h) const
 double to string conversion More...
 
string b2s (const bool &bool_h) const
 bool to string conversion More...
 
vector< int > s2i (const vector< string > &string_h) const
 string to integer conversion (vector) More...
 
vector< double > s2d (const vector< string > &string_h, const bool &replaceComma=false) const
 string to double conversion (vector) More...
 
vector< bool > s2b (const vector< string > &string_h) const
 string to bool conversion (vector) More...
 
vector< string > i2s (const vector< int > &int_h) const
 integer to string conversion (vector) More...
 
vector< string > d2s (const vector< double > &double_h) const
 double to string conversion (vector) More...
 
vector< string > b2s (const vector< bool > &bool_h) const
 bool to string conversion (vector) More...
 
int getType (const string &type_h) const
 Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2)) More...
 
void refreshGUI () const
 Ping to periodically return the control to the GUI. More...
 
template<typename T >
string toString (const T &x) const
 
template<typename T >
stringTo (const std::string &s) const
 
int vSum (const vector< int > &vector_h) const
 
double vSum (const vector< double > &vector_h) const
 
int vSum (const vector< vector< int > > &vector_h) const
 
double vSum (const vector< vector< double > > &vector_h) const
 
void tokenize (const string &str, vector< string > &tokens, const string &delimiter=" ") const
 Tokenize a string using a delimiter (default is space) More...
 
void untokenize (string &str, vector< string > &tokens, const string &delimiter=" ") const
 
template<typename K , typename V >
findMap (const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V &notFoundValue=numeric_limits< V >::min()) const
 Lookup a map for a value. Return the value starting from the key. More...
 
template<typename K , typename V >
void changeMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Change the value stored in a map given the key and the new value. More...
 
template<typename K , typename V >
void incrMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Increments a value stored in a map of the specified value, given the key. More...
 
template<typename K , typename V >
void incrOrAddMapValue (map< K, V > &mymap, const K &key, const V &value)
 Increments a value stored in a map of the specified value, given the key. More...
 
template<typename K , typename V >
void resetMapValues (map< K, V > &mymap, const V &value)
 Reset all values stored in a map to the specified one. More...
 
template<typename K , typename V >
map< K, V > vectorToMap (const vector< K > &keys, const V &value=0.0)
 Returns a map built using the given vector and the given (scalar) value as keys/values pairs. More...
 
template<typename T >
vector< T > positionsToContent (const vector< T > &vector_h, const vector< int > &positions)
 Return a vector of content from a vector and a vector of positions (int) More...
 
template<typename V >
void debugMap (const map< iisskey, V > &mymap)
 Debug a map. More...
 
template<typename K , typename V >
void debugMap (const map< K, V > &mymap, const K &key)
 
template<typename K >
int getMaxPos (const vector< K > &v)
 Returns the position of the maximum element in the vector (the last one in case of multiple equivalent maxima) More...
 
template<typename K >
int getMinPos (const vector< K > &v)
 Returns the position of the minimum element in the vector (the first one in case of multiple equivalent minima) More...
 
template<typename K >
getMax (const vector< K > &v)
 Returns the value of the maximum element in the vector (the last one in case of multiple equivalent maxima) More...
 
template<typename K >
getMin (const vector< K > &v)
 Returns the value of the minimum element in the vector (the first one in case of multiple equivalent minima) More...
 
template<typename K >
double getAvg (const vector< K > &v)
 Returns the average of the elements in the vector. More...
 
template<typename K >
double getSd (const vector< K > &v, bool sample=true)
 
template<typename K >
int getPos (const K &element, const vector< K > &v, const int &msgCode_h=MSG_CRITICAL_ERROR)
 
template<typename K >
bool inVector (const K &element, const vector< K > &v)
 
double normSample (const double &avg, const double &stdev, const double &minval=NULL, const double &maxval=NULL) const
 Sample from a normal distribution with bounds. Slower (double time, but still you see the diff only after milion of loops). More...
 
template<typename K >
normSample (normal_distribution< K > &d, std::mt19937 &gen, const K &minval=NULL, const K &maxval=NULL) const
 Sample from a normal distribution with bounds. Faster (half time) as the normal_distribution is made only once. More...
 
template<typename T >
std::string toString (const T &x) const
 

Private Member Functions

void loadLayersDataFromFile ()
 Load the data of a layer its datafile. More...
 
void applySpatialStochasticValues ()
 Apply stochastic simulation, e.g. regional volume growth s.d. -> tp multipliers. More...
 
void applyStochasticRiskAdversion ()
 Give to each agend a stochastic risk adversion. For now Pixel = Agent. More...
 

Private Attributes

vector< PixelpxVector
 array of Pixel objects More...
 
vector< LayerslayerVector
 array of Layer objects More...
 
vector< double > lUseTotals
 totals, in ha, of area in the region for each type (cached values) More...
 
int xNPixels
 number of pixels along the X dimension More...
 
int yNPixels
 number of pixels along the Y dimension More...
 
double xyNPixels
 total number of pixels More...
 
double xMetersByPixel
 pixel dimension (meters), X More...
 
double yMetersByPixel
 pixel dimension (meters), Y More...
 
double geoLeftX
 geo-coordinates of the map left border More...
 
double geoTopY
 geo-coordinates of the map upper border More...
 
double geoRightX
 geo-coordinates of the map right border More...
 
double geoBottomY
 geo-coordinates of the map bottom border More...
 
double noValue
 value internally use as novalue (individual layer maps can have other values) More...
 
int subXL
 sub region left X More...
 
int subXR
 sub region right X More...
 
int subYT
 sub region top Y More...
 
int subYB
 sub region bottom Y More...
 

Additional Inherited Members

- Protected Attributes inherited from BaseClass
ThreadManagerMTHREAD
 Pointer to the Thread manager. More...
 

Detailed Description

Class to manage the spatial dimension.

Gis class is responsable to provide all methods for spatial analysis.
It is equipped with two important vectors:

  • pxVector contains the array of all pixels on the screen
  • layerVector contains the layer objects
    Along the model, IDs of pixels are assigned from left to right, from top to down:
    —>
    /
    —>
    /
    —>

Pixel origin (0,0) on the top left corner is also the system used by the underlying libraries, but put attencion that instead geographical coordinates, if we are on the North emisfere, are increasing along the up-right direction.

Author
Antonello Lobianco

Definition at line 67 of file Gis.h.

Constructor & Destructor Documentation

Gis ( ThreadManager MTHREAD_h)

Constructor.

The constructor of the GIS (unique) instance want:

Parameters
RD_hPointer to the manager of the regional data
MTHREAD_hPointer to the main thread manager

Definition at line 40 of file Gis.cpp.

40  {
41  MTHREAD=MTHREAD_h;
42 }
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
~Gis ( )

Definition at line 44 of file Gis.cpp.

44  {
45 }

Member Function Documentation

void addLayer ( string  name_h,
string  label_h,
bool  isInteger_h,
bool  dynamicContent_h,
string  fullFileName_h = "",
bool  display_h = true 
)

Fill a layer with empty values.

Called at init time from initLayers, or during model run-time, this function will add a layer to the system.

Parameters
name_hID of the layer (no spaces!)
label_hlayer label
type_htype of the layer, integer or contiguous
dynamicContent_hif it change during the time (so it needs to be printed each year) or not
fullFilename_hif the layer has to be read at the beginning, the name of the associated datafile (default="")

It:

  • had the layer to the layerVector
  • set all pixels with nodata for that specific layer
  • let the GUI know we have a new layer

Definition at line 515 of file Gis.cpp.

515  {
516  if(name_h == "forArea_ash"){
517  bool debug = true;
518  }
519  for(uint i=0; i<layerVector.size(); i++){
520  if (layerVector.at(i).getName() == name_h){
521  msgOut(MSG_ERROR, "Layer already exist with that name");
522  return;
523  }
524  }
525  Layers LAYER (MTHREAD, name_h, label_h, isInteger_h, dynamicContent_h, fullFileName_h, display_h);
526  layerVector.push_back(LAYER);
527 
528  for (uint i=0;i<xyNPixels; i++){
529  pxVector[i].setValue(name_h,noValue);
530  }
531  if(display_h){
532  MTHREAD->addLayer(name_h,label_h);
533  }
534 
535 }
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
double noValue
value internally use as novalue (individual layer maps can have other values)
Definition: Gis.h:170
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Define layer objects at the regional level.
Definition: Layers.h:49
void addLayer(string layerName_h, string layerLabel_h)
double xyNPixels
total number of pixels
Definition: Gis.h:163
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159
void addLegendItem ( string  name_h,
int  ID_h,
string  label_h,
int  rColor_h,
int  gColor_h,
int  bColor_h,
double  minValue_h,
double  maxValue_h 
)

Search within the layerVector and call addLegendItem(...) to the appropriate one.

Called at init time from initLayers, or during model run-time.

Parameters
name_hName of the layer
ID_hID of the specific lagend item
See also
Layers::addLegendItem

Definition at line 579 of file Gis.cpp.

579  {
580 
581  for(uint i=0; i<layerVector.size(); i++){
582  if (layerVector.at(i).getName() == name_h){
583  layerVector.at(i).addLegendItem(ID_h, label_h, rColor_h, gColor_h, bColor_h, minValue_h, maxValue_h);
584  return;
585  }
586  }
587  msgOut(MSG_ERROR, "Trying to add a legend item to a layer that doesn't exist.");
588  return;
589 }
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159
void applyForestReclassification ( )

Apply the forest reclassification with the rules defined in reclRules sheet.

Definition at line 439 of file Gis.cpp.

Referenced by Init::setInitLevel1().

439  {
440 /*per ogni forest type:
441  - crea i layers delle forest type nuovi
442  - riempi con zero
443  - passa le info dal layerr ereditato al nuovo
444  per ogni pixel
445  */
446 
447  // caching
448  int nReclassRules = MTHREAD->MD->getNReclRules();
449  vector <reclRule*> RRs;
450  for(uint z=0;z<nReclassRules;z++){
451  RRs.push_back(MTHREAD->MD->getReclRule(z));
452  }
453 
454 
455 
456  for (uint i=0;i< MTHREAD->MD->getNForTypes();i++){
457  forType* FT = MTHREAD->MD->getForType(i);
458  if(!layerExist(FT->forLayer)){
459  addLayer(FT->forLayer, "Are layer for forest type "+FT->forTypeId, false, true);
460  resetLayer(FT->forLayer);
461  Layers* newLayer = getLayer(FT->forLayer);
462  Layers* ereditatedLayer = getLayer(MTHREAD->MD->getForType(FT->ereditatedFrom)->forLayer);
463  newLayer->addLegendItems(ereditatedLayer->getLegendItems());
464  }
465  }
466 
467 
468  for (uint i=0;i< MTHREAD->MD->getNForTypes();i++){
469  forType* FT = MTHREAD->MD->getForType(i);
470  for(uint j=0;j<xyNPixels;j++){
471  Pixel* PX = getPixel(j);
472  //int regL1 = PX->getDoubleValue ("regLev_1");
473  int regL2 = PX->getDoubleValue ("regLev_2");
474  double value = PX->getDoubleValue (FT->forLayer, true);
475  for(uint z=0;z<nReclassRules;z++){
476  reclRule* RR = RRs[z];
477  //if( (RR->regId == regL2 || RR->regId == regL1) && RR->forTypeOut == FT->forTypeId ){ // we found a reclassification rule for the region where is located this pixel and that output on the for type we are using
478  if( RR->regId == regL2 && RR->forTypeOut == FT->forTypeId ){ // we found a reclassification rule for the region where is located this pixel and that output on the for type we are using
479  string debugForTypeIn = RR->forTypeIn;
480  double inputValue = PX->getDoubleValue(MTHREAD->MD->getForType(RR->forTypeIn)->forLayer, true);
481  double reclassCoeff = RR->coeff;
482  value += inputValue * reclassCoeff ;
483  // not breaking because we may have more than one input for the same output
484  }
485  }
486  PX->changeValue(FT->forLayer, value, true);
487  }
488  updateImage(FT->forLayer);
489  }
490  //countItems("forType_B_HF", true);
491  refreshGUI();
492  /*Pixel* DP = getPixel(8386);
493  msgOut(MSG_DEBUG,"Debug info on plot 8386");
494  for (uint i=0;i< MTHREAD->MD->getNForTypes();i++){
495  forType* FT = MTHREAD->MD->getForType(i);
496  msgOut(MSG_DEBUG,FT->forTypeId+" - "+d2s(DP->getDoubleValue (FT->forLayer)));
497  }
498  */
499 }
void updateImage(string layerName_h)
Add one layer to the system.
Definition: Gis.cpp:700
void resetLayer(string layerName_h)
Check if a layer with a certain name is loaded in the model. Used e.g. to check if the dtm layer (opt...
Definition: Gis.cpp:538
vector< LegendItems > getLegendItems()
Definition: Layers.h:70
void addLegendItems(vector< LegendItems > legendItems_h)
Definition: Layers.cpp:72
void addLayer(string name_h, string label_h, bool isInteger_h, bool dynamicContent_h, string fullFileName_h="", bool display_h=true)
Fill a layer with empty values.
Definition: Gis.cpp:515
Forest types (struct)
Definition: ModelData.h:293
IO production matrix between the forest resources and the primary products (struct) ...
Definition: ModelData.h:306
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
bool layerExist(const string &layerName_h, bool exactMatch=true) const
Return a pointer to a layer given its name.
Definition: Gis.cpp:552
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)...
Definition: Pixel.cpp:135
reclRule * getReclRule(int position)
Definition: ModelData.h:137
ModelData * MD
the model data object
Definition: ThreadManager.h:72
string forTypeOut
Definition: ModelData.h:309
string forTypeIn
Definition: ModelData.h:308
string ereditatedFrom
Definition: ModelData.h:298
int getNReclRules()
Definition: ModelData.h:127
double getDoubleValue(const string &layerName_h, const bool &returnZeroForNoValue=false) const
Return the value for a specific layer.
Definition: Pixel.cpp:158
Define layer objects at the regional level.
Definition: Layers.h:49
Pixel-level class.
Definition: Pixel.h:47
string forTypeId
Definition: ModelData.h:294
string forLayer
Definition: ModelData.h:297
Pixel * getPixel(int x_h, int y_h)
Definition: Gis.h:134
double xyNPixels
total number of pixels
Definition: Gis.h:163
int regId
Definition: ModelData.h:307
double coeff
Definition: ModelData.h:310
void refreshGUI() const
Ping to periodically return the control to the GUI.
Definition: BaseClass.cpp:142
int getNForTypes()
Definition: ModelData.h:126
Layers * getLayer(const string &layerName_h)
Add a legend item to an existing layer.
Definition: Gis.cpp:429
forType * getForType(int position)
Definition: ModelData.h:128

Here is the call graph for this function:

Here is the caller graph for this function:

void applySpatialStochasticValues ( )
private

Apply stochastic simulation, e.g. regional volume growth s.d. -> tp multipliers.

Apply all stochastic modifications required by the model at init time. Currently used to change time of passage devending on regional variance

with simmetric boundary on the cv I do not change the average, but of course I slighly reduce the stdev. See file monte_carlo_with_multipliers_sample_proof.ods

Definition at line 121 of file Gis.cpp.

121  {
122  // apply regional volume growth st.dev. -> variance to pixel based t.p.
123  // - cashing value to the pixels
124  // - apply to the tp layers with change values
125 
126  if(!MTHREAD->MD->getBoolSetting("usePixelData")) return;
127 
128  vector <int> regIds2 = MTHREAD->MD->getRegionIds(2);
129  //ModelRegion* reg = MTHREAD->MD->getRegion(regIds2[i]);
130  //vector<Pixel*> regPixels = region->getMyPixels();
131  //double sumc = 0;
132  //double nc = 0;
133  for(uint i=0;i<regIds2.size();i++){
134  int regId = regIds2[i];
135  ModelRegion* reg = MTHREAD->MD->getRegion(regId );
136  vector <Pixel*> rpx = MTHREAD->GIS->getAllPlotsByRegion(regId );
137  vector <string> fTypes = MTHREAD->MD->getForTypeIds();
138 
139  // regional variance
140  if(MTHREAD->MD->getBoolSetting("useSpatialRegionalVariance")){
141  for(uint j=0; j<fTypes.size(); j++){
142  double sStDev = MTHREAD->MD->getForData("sStDev",regId ,fTypes[j],""); // spatial standard deviation
143  double agr = MTHREAD->MD->getForData("agr",regId ,fTypes[j],""); // average growth
144  // BUG solved 20141220 To obtain a population with the same avg and st.dev of the original using moltipliers, I need to use the cv not the st.dev. !
145  // tested with excel
146  normal_distribution<double> d(1,sStDev/agr); // default any how to double
147  for (uint z=0;z<rpx.size();z++){
148  double c = d(*MTHREAD->gen);
149  double c2 = max(0.4,min(1.6,c)); /// with simmetric boundary on the cv I do not change the average, but of course I slighly reduce the stdev. See file monte_carlo_with_multipliers_sample_proof.ods
150  // TO.DO: Convert it to using normSample where instead of a min/max a loop is used to fund smaples that are within the bounds
151  //cout << regIds2[i] << ";" <<sStDev <<";"<< c <<endl
152  //rpx[z]->correctInputMultiplier("tp_multiplier",fTypes[j],c);
153  //cout << sStDev/agr << " " << c2 << endl;
154  rpx[z]->setSpModifier(c2,j);
155  //sumc += c;
156  //nc ++;
157  }
158  }
159  }
160 
161  // expectation types
162  double avgExpTypes = MTHREAD->MD->getDoubleSetting("expType",DATA_NOW,regId);
163  double avgExpTypesPrices = MTHREAD->MD->getDoubleSetting("expTypePrices",DATA_NOW,regId);
164  double expTypes_cv = MTHREAD->MD->getDoubleSetting("expType_cv",DATA_NOW,regId);
165  double expTypesPrices_cv = MTHREAD->MD->getDoubleSetting("expTypePrices_cv",DATA_NOW,regId);
166  if((avgExpTypes<0 || avgExpTypes>1) && avgExpTypes != -1){
167  msgOut(MSG_CRITICAL_ERROR, "expType parameter must be between 1 (expectations) and 0 (adaptative) or -1 (fixed).");
168  }
169  if(avgExpTypesPrices<0 || avgExpTypesPrices>1){
170  msgOut(MSG_CRITICAL_ERROR, "vgExpTypesPrices parameter must be between 1 (expectations) and 0 (adaptative).");
171  }
172  //cout << avgExpTypes << " " << expTypes_cv << endl;
173 
174  normal_distribution<double> exp_distr(avgExpTypes,expTypes_cv *avgExpTypes); // works only for double, but default any how to double
175  normal_distribution<double> expPrices_distr(avgExpTypesPrices,expTypesPrices_cv *avgExpTypesPrices);
176 
177  for (uint z=0;z<rpx.size();z++){
178  if(avgExpTypes == -1){
179  rpx[z]->expType = -1;
180  } else {
181  //double c = exp_distr(*MTHREAD->gen);
182  //double c2 = max(0.0,min(1.0,c)); /// Bounded [0,1]. With simmetric boundary on the cv I do not change the average, but of course I slighly reduce the stdev. See file monte_carlo_with_multipliers_sample_proof.ods
183  double c3 = normSample(exp_distr,*MTHREAD->gen,0.0,1.0);
184  //cout << "Sampled:\t" << c3 << endl;
185  rpx[z]->expType = c3;
186  }
187  double cPrice = normSample(expPrices_distr,*MTHREAD->gen,0.0,1.0);
188  rpx[z]->expTypePrices = cPrice;
189  }
190  }
191 }
The required data is for the current year.
Definition: BaseClass.h:73
double normSample(const double &avg, const double &stdev, const double &minval=NULL, const double &maxval=NULL) const
Sample from a normal distribution with bounds. Slower (double time, but still you see the diff only a...
Definition: BaseClass.cpp:330
bool getBoolSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1117
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
ModelData * MD
the model data object
Definition: ThreadManager.h:72
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73
Print an error message and stop the model.
Definition: BaseClass.h:62
const double getForData(const string &type_h, const int &regId_h, const string &forType_h, const string &freeDim_h, const int &year=DATA_NOW)
Definition: ModelData.cpp:1281
vector< Pixel * > getAllPlotsByRegion(ModelRegion &region_h, bool shuffle=false)
Return the vector of all plots by a specific region (main region or subregion), optionally shuffled;...
Definition: Gis.cpp:855
vector< string > getForTypeIds(bool all=false)
By default it doesn&#39;t return forTypes used only as input.
Definition: ModelData.cpp:430
vector< int > getRegionIds(int level_h, bool excludeResidual=true)
Definition: ModelData.cpp:366
double getDoubleSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1109
std::mt19937 * gen
used in the sampling from normal distribution
Definition: ThreadManager.h:83
ModelRegion * getRegion(int regId_h)
Definition: ModelData.cpp:346
void applyStochasticRiskAdversion ( )
private

Give to each agend a stochastic risk adversion. For now Pixel = Agent.

Apply to each agent a random risk-adversion coefficient

For now, 1 pixel = 1 agent, and avg and st.dev. are the same in the model, but eventually this can change

Definition at line 199 of file Gis.cpp.

199  {
200  // apply regional volume growth st.dev. -> variance to pixel based t.p.
201  // - cashing value to the pixels
202  // - apply to the tp layers with change values
203 
204  if(!MTHREAD->MD->getBoolSetting("usePixelData")) return;
205 
206  vector <int> regIds2 = MTHREAD->MD->getRegionIds(2);
207  bool raEnabled = MTHREAD->MD->getBoolSetting("heterogeneousRiskAversion");
208  for(uint i=0;i<regIds2.size();i++){
209  int regId = regIds2[i];
210  ModelRegion* reg = MTHREAD->MD->getRegion(regId);
211  vector <Pixel*> rpx = MTHREAD->GIS->getAllPlotsByRegion(regId);
212  for (uint z=0;z<rpx.size();z++){
213  if(raEnabled){
214  double raStDev = MTHREAD->MD->getDoubleSetting("riskAversionAgentSd",DATA_NOW,regId);
215  double avg = MTHREAD->MD->getDoubleSetting("riskAversionAgentAverage",DATA_NOW,regId);
216  normal_distribution<double> d(avg,raStDev); // default any how to double
217  double c = d(*MTHREAD->gen);
218  rpx[z]->setValue ("ra", c);
219  } else {
220  rpx[z]->setValue ("ra", 0.0);
221  }
222  }
223  }
224 }
The required data is for the current year.
Definition: BaseClass.h:73
bool getBoolSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1117
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
ModelData * MD
the model data object
Definition: ThreadManager.h:72
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73
vector< Pixel * > getAllPlotsByRegion(ModelRegion &region_h, bool shuffle=false)
Return the vector of all plots by a specific region (main region or subregion), optionally shuffled;...
Definition: Gis.cpp:855
vector< int > getRegionIds(int level_h, bool excludeResidual=true)
Definition: ModelData.cpp:366
double getDoubleSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1109
std::mt19937 * gen
used in the sampling from normal distribution
Definition: ThreadManager.h:83
ModelRegion * getRegion(int regId_h)
Definition: ModelData.cpp:346
void countItems ( const string &  layerName_h,
const bool &  debug = false 
)

Count the pixels within each legend item for the selected layer.

Search within the layerVector and call countMyPixels(...) to the appropriate one.

Called at init time from initLayers, or during model run-time.

Parameters
layerName_hName of the layer
debugPrint the values on the GUI
See also
Layers::countMyPixels

Definition at line 599 of file Gis.cpp.

599  {
600 
601  for(uint i=0; i<layerVector.size(); i++){
602  if (layerVector.at(i).getName() == layerName_h){
603  layerVector.at(i).countMyPixels(debug);
604  return;
605  }
606  }
607  msgOut(MSG_ERROR, "Trying to get statistics (count pixels) of a layer that doesn't exist.");
608  return;
609 }
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159
void filterSubRegion ( string  layerName_h)

If subregion mode is on, this function place noValues on the selected layer for all out-of-region pixels.

Update the image behind a layer to the GUI;

This function filter the region, placing noValue on the selected informative layer on pixels that are outside the subregion.
It was thinked for speedup the development without have to run the whole model for testing each new implementation, but it can used to see what happen in the model when only a subset of the region is analysed.

Definition at line 921 of file Gis.cpp.

921  {
922  subXL = 0;
923  subYT = 0;
924  subXR = xNPixels-1;
925  subYB = yNPixels-1;
926 }
int yNPixels
number of pixels along the Y dimension
Definition: Gis.h:162
int subXR
sub region right X
Definition: Gis.h:172
int subXL
sub region left X
Definition: Gis.h:171
int subYT
sub region top Y
Definition: Gis.h:173
int xNPixels
number of pixels along the X dimension
Definition: Gis.h:161
int subYB
sub region bottom Y
Definition: Gis.h:174
vector< Pixel * > getAllPlots ( bool  masked = true,
int  outputLevel = MSG_WARNING 
)

Return the vector (shuffled) of all plots. It is also possible to specify the level in case of failure.

Parameters
onlyFreePlotsFlag to get only plots marked as free (d=false)
outputLevelLevel of output in case of failure (no plots available). Default is warning, but if set as MSG_CRITICAL_ERROR it make stop the model.

Definition at line 823 of file Gis.cpp.

823  {
824  vector <Pixel* > candidates;
825  if(masked = false){
826  for (uint i=0;i<pxVector.size();i++){
827  candidates.push_back(&pxVector.at(i));
828  }
829  if (candidates.size()>0){
830  random_shuffle(candidates.begin(), candidates.end()); // randomize ther elements of the array... cool !!! ;-)))
831  } else {
832  msgOut(outputLevel,"We can't find any free plot.");
833  }
834  } else {
835  // Only pixels within a L2 region
836  vector <int> regIds2 = MTHREAD->MD->getRegionIds(2);
837  for(uint i=0;i<regIds2.size();i++){
838  vector <Pixel*> rpx = getAllPlotsByRegion(regIds2[i]);
839  //for (uint i=0;i<rpx.size();i++){
840  // candidates.push_back(rpx.at(i));
841  //}
842  candidates.insert( candidates.end(), rpx.begin(), rpx.end() );
843  }
844  if (candidates.size()>0){
845  random_shuffle(candidates.begin(), candidates.end()); // randomize ther elements of the array... cool !!! ;-)))
846  } else {
847  msgOut(outputLevel,"We can't find any free plot.");
848  }
849  }
850  return candidates;
851 }
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
ModelData * MD
the model data object
Definition: ThreadManager.h:72
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
vector< Pixel * > getAllPlotsByRegion(ModelRegion &region_h, bool shuffle=false)
Return the vector of all plots by a specific region (main region or subregion), optionally shuffled;...
Definition: Gis.cpp:855
vector< int > getRegionIds(int level_h, bool excludeResidual=true)
Definition: ModelData.cpp:366
vector< Pixel * > getAllPlotsByRegion ( ModelRegion region_h,
bool  shuffle = false 
)

Return the vector of all plots by a specific region (main region or subregion), optionally shuffled;.

Definition at line 855 of file Gis.cpp.

Referenced by ModelCoreSpatial::assignSpMultiplierPropToVols(), ModelCoreSpatial::initializePixelArea(), ModelCoreSpatial::initializePixelVolumes(), ModelCore::updateMapAreas(), ModelCoreSpatial::updateMapAreas(), and ModelCoreSpatial::updateOtherMapData().

855  {
856  vector <Pixel*> regionalPixels = region_h.getMyPixels();
857  if(shuffle){
858  random_shuffle(regionalPixels.begin(), regionalPixels.end()); // randomize the elements of the array.
859  }
860  return regionalPixels;
861 }
vector< Pixel * > getMyPixels()
Definition: ModelRegion.h:86

Here is the call graph for this function:

Here is the caller graph for this function:

vector< Pixel * > getAllPlotsByRegion ( int  regId_h,
bool  shuffle = false 
)

Definition at line 864 of file Gis.cpp.

864  {
865  ModelRegion* reg = MTHREAD->MD->getRegion(regId_h);
866  return getAllPlotsByRegion(*reg,shuffle);
867 }
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
ModelData * MD
the model data object
Definition: ThreadManager.h:72
vector< Pixel * > getAllPlotsByRegion(ModelRegion &region_h, bool shuffle=false)
Return the vector of all plots by a specific region (main region or subregion), optionally shuffled;...
Definition: Gis.cpp:855
ModelRegion * getRegion(int regId_h)
Definition: ModelData.cpp:346
vector< Pixel * > getAllPlotsByValue ( string  layer_h,
int  layerValue_h,
int  outputLevel = MSG_WARNING 
)

Return the vector (shuffled) of all plots with a specific value for a specified layer. It is also possible to specify the level in case of failure.

Parameters
layer_hName of the layer
layerValue_hValue we want the plots for
onlyFreePlotsFlag to get only plots marked as free (d=false)
outputLevelLevel of output in case of failure (no plots available). Default is warning, but if set as MSG_CRITICAL_ERROR it make stop the model.

Definition at line 758 of file Gis.cpp.

758  {
759  // this would be easier to mantain and cleaned code, but slighly slower:
760  //vector<int> layerValues;
761  //layerValues.push_back(layerValue_h);
762  //return getAllPlotsByValue(layer_h, layerValues, onlyFreePlots, outputLevel);
763 
764  vector <Pixel* > candidates;
765  for (uint i=0;i<pxVector.size();i++){
766  if(pxVector.at(i).getDoubleValue(layer_h) == layerValue_h){
767  candidates.push_back(&pxVector.at(i));
768  }
769  }
770 
771  if (candidates.size()>0){
772  random_shuffle(candidates.begin(), candidates.end()); // randomize ther elements of the array... cool !!! ;-)))
773  }
774  else {
775  msgOut(outputLevel,"We can't find any free pixel with "+d2s(layerValue_h)+" value on layer "+layer_h+".");
776  }
777  return candidates;
778 }
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
string d2s(const double &double_h) const
double to string conversion
Definition: BaseClass.cpp:229
vector< Pixel * > getAllPlotsByValue ( string  layer_h,
vector< int >  layerValues_h,
int  outputLevel = MSG_WARNING 
)

Return the vector (shuffled) of all plots with specific values for a specified layer. It is also possible to specify the level in case of failure.

Parameters
layer_hName of the layer
layerValues_hValues we want the plots for
onlyFreePlotsFlag to get only plots marked as free (d=false)
outputLevelLevel of output in case of failure (no plots available). Default is warning, but if set as MSG_CRITICAL_ERROR it make stop the model.

Definition at line 790 of file Gis.cpp.

790  {
791  vector <Pixel* > candidates;
792  string valuesToMatch;
793  unsigned int z;
794 
795  //string of the required land values to match;
796  for (uint j=0;j<layerValues_h.size();j++){
797  valuesToMatch = valuesToMatch + " " + i2s(layerValues_h.at(j));
798  }
799 
800  for (uint i=0;i<pxVector.size();i++){
801  z = valuesToMatch.find(d2s(pxVector.at(i).getDoubleValue(layer_h))); // search if in the string of required values is included also the value of the current plot
802  if(z!=string::npos){ //z is not at the end of the string, means found!
803  candidates.push_back(&pxVector.at(i));
804  }
805  }
806 
807  if (candidates.size()>0){
808  random_shuffle(candidates.begin(), candidates.end()); // randomize ther elements of the array... cool !!! ;-)))
809  }
810  else {
811  msgOut(outputLevel,"We can't find any free plot with the specified values ("+valuesToMatch+") on layer "+layer_h+".");
812  }
813  return candidates;
814 }
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
string d2s(const double &double_h) const
double to string conversion
Definition: BaseClass.cpp:229
double getDistance ( const Pixel px1,
const Pixel px2 
)

Definition at line 929 of file Gis.cpp.

929  {
930  return sqrt (
931  pow ( (((double)px1->getX()) - ((double)px2->getX()))*xMetersByPixel,2)
932  +
933  pow ( (((double)px1->getY()) - ((double)px2->getY()))*yMetersByPixel,2)
934  );
935 }
int getX() const
Definition: Pixel.h:68
double xMetersByPixel
pixel dimension (meters), X
Definition: Gis.h:164
double yMetersByPixel
pixel dimension (meters), Y
Definition: Gis.h:165

Here is the call graph for this function:

double getGeoBottomY ( ) const
inline

Definition at line 137 of file Gis.h.

Referenced by Layers::print().

137 {return geoBottomY;};
double geoBottomY
geo-coordinates of the map bottom border
Definition: Gis.h:169

Here is the caller graph for this function:

double getGeoLeftX ( ) const
inline

Definition at line 138 of file Gis.h.

Referenced by Layers::print().

138 {return geoLeftX;};
double geoLeftX
geo-coordinates of the map left border
Definition: Gis.h:166

Here is the caller graph for this function:

double getGeoRightX ( ) const
inline

Definition at line 139 of file Gis.h.

Referenced by Layers::print().

139 {return geoRightX;};
double geoRightX
geo-coordinates of the map right border
Definition: Gis.h:168

Here is the caller graph for this function:

double getGeoTopY ( ) const
inline

Return a pixel pointer from its ID.

Definition at line 136 of file Gis.h.

Referenced by Layers::print().

136 {return geoTopY;};
double geoTopY
geo-coordinates of the map upper border
Definition: Gis.h:167

Here is the caller graph for this function:

double getHaByPixel ( ) const
inline

Return the total number of pixels.

Definition at line 132 of file Gis.h.

132 {return ((xMetersByPixel*yMetersByPixel)/10000) ;};
double xMetersByPixel
pixel dimension (meters), X
Definition: Gis.h:164
double yMetersByPixel
pixel dimension (meters), Y
Definition: Gis.h:165
Layers * getLayer ( const string &  layerName_h)

Add a legend item to an existing layer.

Init the layers of exogenous data at pixel level (e.g. time of passage) These layers will NOT be read by datafile, but volume for each pixel will be calculated from regional data and area map

Definition at line 429 of file Gis.cpp.

429  {
430  for(uint i=0;i<layerVector.size();i++){
431  if(layerVector[i].getName() == layerName_h){
432  return &layerVector[i];
433  }
434  }
435  msgOut(MSG_CRITICAL_ERROR, "Layer "+layerName_h+" not found. Aborting.");
436 }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159
vector< string > getLayerNames ( )

Return a vector of the layer ids (as string)

Definition at line 872 of file Gis.cpp.

872  {
873  vector <string> toReturn;
874  for (uint i=0;i<layerVector.size();i++){
875  toReturn.push_back(layerVector[i].getName());
876  }
877  return toReturn;
878 }
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159
vector< Layers * > getLayerPointers ( )

Return a vector of pointers of existing layers.

Definition at line 881 of file Gis.cpp.

881  {
882  vector <Layers*> toReturn;
883  for (uint i=0;i<layerVector.size();i++){
884  toReturn.push_back(&layerVector[i]);
885  }
886  return toReturn;
887 }
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159
double getNoValue ( ) const
inline

Definition at line 133 of file Gis.h.

Referenced by Pixel::changeValue(), Layers::getCategory(), Layers::getColor(), Pixel::getDoubleValue(), Layers::print(), and Layers::randomShuffle().

133 {return noValue;};
double noValue
value internally use as novalue (individual layer maps can have other values)
Definition: Gis.h:170

Here is the caller graph for this function:

Pixel* getPixel ( int  x_h,
int  y_h 
)
inline

Definition at line 134 of file Gis.h.

Referenced by Layers::countMyPixels(), Pixel::getPixelsAtDistLevel(), Layers::print(), Layers::printBinMap(), Layers::randomShuffle(), Scheduler::run(), and ModelRegion::setMyPixels().

134 {return &pxVector.at(x_h+y_h*xNPixels);}; ///< Return a pixel pointer from its coordinates
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
int xNPixels
number of pixels along the X dimension
Definition: Gis.h:161

Here is the caller graph for this function:

Pixel* getPixel ( int  ID_h)
inline

Return a pixel pointer from its coordinates.

Definition at line 135 of file Gis.h.

135 {return &pxVector.at(ID_h);}; ///< Return a pixel pointer from its ID
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
Pixel * getRandomPlotByValue ( string  layer_h,
int  layerValue__h 
)

Return a pointer to a plot with a specific value for the specified layer.

Definition at line 730 of file Gis.cpp.

730  {
731 
732  vector <Pixel* > candidates;
733  vector <uint> counts;
734  for(uint i=0;i<pxVector.size();i++) counts.push_back(i);
735  random_shuffle(counts.begin(), counts.end()); // randomize the elements of the array.
736 
737  for (uint i=0;i<counts.size();i++){
738  if(pxVector.at(counts.at(i)).getDoubleValue(layer_h) == layerValue_h ) {
739  return &pxVector.at(counts.at(i));
740  }
741  }
742 
743  msgOut(MSG_CRITICAL_ERROR,"We can't find any plot with "+d2s(layerValue_h)+" value on layer "+layer_h+".");
744  Pixel* toReturn;
745  toReturn =0;
746  return toReturn;
747 }
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62
string d2s(const double &double_h) const
double to string conversion
Definition: BaseClass.cpp:229
Pixel-level class.
Definition: Pixel.h:47
int getSubXL ( ) const
inline

Definition at line 142 of file Gis.h.

Referenced by Layers::printBinMap().

142 {return subXL;};
int subXL
sub region left X
Definition: Gis.h:171

Here is the caller graph for this function:

int getSubXR ( ) const
inline

Definition at line 143 of file Gis.h.

Referenced by Layers::printBinMap().

143 {return subXR;};
int subXR
sub region right X
Definition: Gis.h:172

Here is the caller graph for this function:

int getSubYB ( ) const
inline

Definition at line 145 of file Gis.h.

Referenced by Layers::printBinMap().

145 {return subYB;};
int subYB
sub region bottom Y
Definition: Gis.h:174

Here is the caller graph for this function:

int getSubYT ( ) const
inline

Definition at line 144 of file Gis.h.

Referenced by Layers::printBinMap().

144 {return subYT;};
int subYT
sub region top Y
Definition: Gis.h:173

Here is the caller graph for this function:

double getXMetersByPixel ( ) const
inline

Definition at line 140 of file Gis.h.

Referenced by Layers::print().

140 {return xMetersByPixel;};
double xMetersByPixel
pixel dimension (meters), X
Definition: Gis.h:164

Here is the caller graph for this function:

int getXNPixels ( ) const
inline

Definition at line 129 of file Gis.h.

Referenced by Pixel::getPixelsAtDistLevel(), Layers::print(), Layers::printBinMap(), and Scheduler::run().

129 {return xNPixels;}; ///< Return the number of pixels on X
int xNPixels
number of pixels along the X dimension
Definition: Gis.h:161

Here is the caller graph for this function:

double getXyNPixels ( ) const
inline

Return the number of pixels on Y.

Definition at line 131 of file Gis.h.

Referenced by Layers::countMyPixels(), Layers::randomShuffle(), and ModelRegion::setMyPixels().

131 {return xyNPixels;}; ///< Return the total number of pixels
double xyNPixels
total number of pixels
Definition: Gis.h:163

Here is the caller graph for this function:

double getYMetersByPixel ( ) const
inline

Definition at line 141 of file Gis.h.

Referenced by Layers::print().

141 {return yMetersByPixel;};
double yMetersByPixel
pixel dimension (meters), Y
Definition: Gis.h:165

Here is the caller graph for this function:

int getYNPixels ( ) const
inline

Return the number of pixels on X.

Definition at line 130 of file Gis.h.

Referenced by Pixel::getPixelsAtDistLevel(), and Layers::print().

130 {return yNPixels;}; ///< Return the number of pixels on Y
int yNPixels
number of pixels along the Y dimension
Definition: Gis.h:162

Here is the caller graph for this function:

void initLayers ( )

Init the layers.

Called from setSpace(), initLayers() is responsable of:

  • load each layer propriety (name, label, datafile..)
  • add the layer to the system
    See also
    addLayer
    If the layer is to be read at start-up:
  • adding to the layer each legend item (ID, label, min-max values..)
    See also
    addLegendItem
  • [REMOVED, as reclassification rules are in the input ods file now, not in the gis input file] eventually adding to the layer each reclassification rules
    See also
    addReclassificationRule

Definition at line 259 of file Gis.cpp.

259  {
260  // setting layers...
261  //string filename_complete= MTHREAD->MD->getFilenameByType("gis");
262  string filename_complete = MTHREAD->getBaseDirectory()+MTHREAD->MD->getStringSetting("gisFilename");
263 
264  InputNode gisDocument;
265  bool test=gisDocument.setWorkingFile(filename_complete);
266  if (!test){msgOut(MSG_CRITICAL_ERROR, "Error opening the gis file "+filename_complete+".");}
267  vector<InputNode> layerNodes = gisDocument.getNodesByName("layer");
268  vector<string> ftIds = MTHREAD->MD->getForTypeIds();
269  for (uint i=0; i<layerNodes.size();i++){
270 
271  string nameOrig = layerNodes.at(i).getNodeByName("name").getStringContent();
272  string labelOrig = layerNodes.at(i).getNodeByName("label").getStringContent();
273  bool isInteger = layerNodes.at(i).getNodeByName("isInteger").getBoolContent();
274  bool dynamicContent = layerNodes.at(i).getNodeByName("dynamicContent").getBoolContent();
275  bool expandByFt = layerNodes.at(i).getNodeByName("expandByFt").getBoolContent();
276  string readAtStart = layerNodes.at(i).getNodeByName("readAtStart").getStringContent();
277  if (readAtStart != "true") continue;
278  string dirName = layerNodes.at(i).getNodeByName("dirName").getStringContent();
279  string fileName = layerNodes.at(i).getNodeByName("fileName").getStringContent();
280 
281  // Eventually expanding this input layern in as many layer as forest types exists..
282  uint endingLoop = expandByFt ? ftIds.size(): 1;
283  for(uint z=0;z<endingLoop;z++){
284  string ftExtension= expandByFt ? "_"+ftIds[z]:"";
285  string labelFtExtension= expandByFt ? " ("+ftIds[z]+")":"";
286  string name = nameOrig+ftExtension;
287  string label = labelOrig + labelFtExtension;
288 
289  string fullFileName = ((dirName == "") || (fileName==""))?"":MTHREAD->MD->getBaseDirectory()+dirName+fileName+ftExtension; // TODO: ugly: one would have to put mmyfile.grd_broadL_highF
290  addLayer(name,label,isInteger,dynamicContent,fullFileName);
291  //legend..
292  vector<InputNode> legendItemsNodes = layerNodes.at(i).getNodesByName("legendItem");
293  for (uint j=0; j<legendItemsNodes.size();j++){
294  int lID = legendItemsNodes.at(j).getIntContent();
295  string llabel = legendItemsNodes.at(j).getStringAttributeByName("label");
296  int rColor = legendItemsNodes.at(j).getIntAttributeByName("rColor");
297  int gColor = legendItemsNodes.at(j).getIntAttributeByName("gColor");
298  int bColor = legendItemsNodes.at(j).getIntAttributeByName("bColor");
299  double minValue, maxValue;
300  if (isInteger){
301  minValue = ((double)lID);
302  maxValue = ((double)lID);
303  }
304  else {
305  minValue = legendItemsNodes.at(j).getDoubleAttributeByName("minValue");
306  maxValue = legendItemsNodes.at(j).getDoubleAttributeByName("maxValue");
307  }
308  addLegendItem(name, lID, llabel, rColor, gColor, bColor, minValue, maxValue);
309  }
310  }
311  }
313  //initLayersModelData(DATA_INIT); // only the layers relative to the initial years are inserted now. All the simulation year layers will be added each year before mainSimulationyear()
314 }
void addLayer(string name_h, string label_h, bool isInteger_h, bool dynamicContent_h, string fullFileName_h="", bool display_h=true)
Fill a layer with empty values.
Definition: Gis.cpp:515
bool setWorkingFile(std::string filename_h)
Load the file on memory. Return false if no success.
Definition: InputNode.cpp:37
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
Wrapper around the underlying library for reading DOM elements (nodes).
Definition: InputNode.h:51
ModelData * MD
the model data object
Definition: ThreadManager.h:72
string getBaseDirectory() const
Definition: ModelData.h:118
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
string getStringSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1113
void addLegendItem(string name_h, int D_h, string label_h, int rColor_h, int gColor_h, int bColor_h, double minValue_h, double maxValue_h)
Definition: Gis.cpp:579
Print an error message and stop the model.
Definition: BaseClass.h:62
vector< string > getForTypeIds(bool all=false)
By default it doesn&#39;t return forTypes used only as input.
Definition: ModelData.cpp:430
vector< InputNode > getNodesByName(string nodeName_h, int debugLevel=MSG_WARNING, bool childFlag=false)
Definition: InputNode.cpp:155
void initLayersPixelData()
Definition: Gis.cpp:320
string getBaseDirectory()
Definition: ThreadManager.h:98

Here is the call graph for this function:

void initLayersModelData ( const int &  year_h = DATA_NOW)
void initLayersPixelData ( )

Init the layers of exogenous data at pixel level (e.g. time of passage, multipliers, volumes of sp. espl. ft, spread models) These layers will then be read from datafile

See also
loadLayersDataFromFile

Definition at line 320 of file Gis.cpp.

320  {
321  if (!MTHREAD->MD->getBoolSetting("usePixelData")){return;}
322  string dir = MTHREAD->MD->getBaseDirectory()+MTHREAD->MD->getStringSetting("spatialDataSubfolder");
323  string fileExt = MTHREAD->MD->getStringSetting("spatialDataFileExtension");
324  vector<string> files = vector<string>();
325  string fullFilename, filename, fullPath;
326  //string parName, forName, dClass, yearString;
327  //int year;
328 
329  MTHREAD->MD->getFilenamesByDir(dir,files, fileExt); // Ugly format. Files is the output (reference)
330 
331  for (unsigned int i = 0;i < files.size();i++) {
332  fullFilename = files[i];
333  fullPath = dir+"/"+fullFilename;
334  filename = fullFilename.substr(0,fullFilename.find_last_of("."));
335  addLayer(filename,filename,false,false,fullPath,false);
336  }
337 
338  // Loading volumes of forest types that are spatially known..
339  if(MTHREAD->MD->getBoolSetting("useSpExplicitForestTypes")){
340  string dir2 = MTHREAD->MD->getBaseDirectory()+MTHREAD->MD->getStringSetting("spExplicitForTypesInputDir");
341  string fileExt2 = MTHREAD->MD->getStringSetting("spExplicitForTypesFileExtension");
342  vector<string> files2 = vector<string>();
343  string fullFilename2, filename2, fullPath2;
344  MTHREAD->MD->getFilenamesByDir (dir2,files2, fileExt2); // Ugly format. Files is the output (reference)
345  for (unsigned int i = 0;i < files2.size();i++) {
346  fullFilename2 = files2[i];
347  fullPath2 = dir2+"/"+fullFilename2;
348  filename2 = fullFilename2.substr(0,fullFilename2.find_last_of("."));
349  addLayer(filename2,filename2,false,false,fullPath2,false);
350  }
351  }
352 
353  // Loading pathogens exogenous spread models...
354  if(MTHREAD->MD->getBoolSetting("usePathogenModule")){
355  string dir2 = MTHREAD->MD->getBaseDirectory()+MTHREAD->MD->getStringSetting("pathogenExogenousSpreadModelFolder");
356  string fileExt2 = MTHREAD->MD->getStringSetting("pathogenExogenousSpreadModelFileExtension");
357  vector<string> files2 = vector<string>();
358  string fullFilename2, filename2, fullPath2;
359  MTHREAD->MD->getFilenamesByDir (dir2,files2, fileExt2); // Ugly format. Files is the output (reference)
360  for (unsigned int i = 0;i < files2.size();i++) {
361  fullFilename2 = files2[i];
362  fullPath2 = dir2+"/"+fullFilename2;
363  filename2 = fullFilename2.substr(0,fullFilename2.find_last_of("."));
364  addLayer(filename2,filename2,false,false,fullPath2,false);
365  }
366  }
367 
368  // Add layer of pixel IDs
369  addLayer("pixelIds","Pixel IDs", true, false, "", true);
370  vector <Pixel*> allPx = getAllPlots(false);
371  for (unsigned int i = 0; i < allPx.size();i++) {
372  allPx[i]->changeValue("pixelIds", allPx[i]->getID());
373  }
374 
375 
376 
377 }
void addLayer(string name_h, string label_h, bool isInteger_h, bool dynamicContent_h, string fullFileName_h="", bool display_h=true)
Fill a layer with empty values.
Definition: Gis.cpp:515
bool getBoolSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1117
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
ModelData * MD
the model data object
Definition: ThreadManager.h:72
string getBaseDirectory() const
Definition: ModelData.h:118
vector< Pixel * > getAllPlots(bool masked=true, int outputLevel=MSG_WARNING)
Return the vector (shuffled) of all plots. It is also possible to specify the level in case of failur...
Definition: Gis.cpp:823
string getStringSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1113
int getFilenamesByDir(const string &dir, vector< string > &files, const string &filter="")
Return a list of files in a directory.
Definition: ModelData.cpp:2011
bool layerExist ( const string &  layerName_h,
bool  exactMatch = true 
) const

Return a pointer to a layer given its name.

Definition at line 552 of file Gis.cpp.

Referenced by Pixel::getPathMortality(), ModelCoreSpatial::loadExogenousForestLayers(), and ModelCoreSpatial::updateOtherMapData().

552  {
553 
554  if(exactMatch){
555  for(uint i=0; i<layerVector.size(); i++){
556  if (layerVector.at(i).getName() == layerName_h){
557  return true;
558  }
559  }
560  } else { // partial matching (stored layer name begin with search parameter)
561  for(uint i=0; i<layerVector.size(); i++){
562  if (layerVector.at(i).getName().compare(0, layerName_h.size(),layerName_h )){
563  return true;
564  }
565  }
566  }
567 
568  return false;
569 }
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159

Here is the caller graph for this function:

void loadLayersDataFromFile ( )
private

Load the data of a layer its datafile.

Called at init time from initLayers, this function load the associated datafile to the existing layers (that if exists at this stage are all of type to be loaded at start-up).
This function loop over layerVector and works with GRASS/ASCII (tested) or ARC/ASCII (untested) datasets, assigning to each pixel the readed value to the corresponding layer.
The function also "compose" the initial map with the colors read by the layer (for each specific values) and send the map to the GUI.

NOTE: It uses some Qt functions!!!

See also
Pixel::changeValue
Layers::filterExogenousDataset
Layers::getColor

Definition at line 624 of file Gis.cpp.

624  {
625  double localNoValue = noValue;
626  double inputValue;
627  double outputValue;
628  QColor color;
629 
630  for(uint i=0;i<layerVector.size();i++){
631  string layerName =layerVector.at(i).getName();
632  string fileName=layerVector.at(i).getFilename();
633  if(fileName == "") continue; // BUGGED !!! 20121017, Antonello. It was "return", so it wasn't reading any layers following a layer with no filename
634  QFile file(fileName.c_str());
635  if (!file.open(QFile::ReadOnly)) {
636  cerr << "Cannot open file for reading: "
637  << qPrintable(file.errorString()) << endl;
638  msgOut(MSG_ERROR, "Cannot open map file "+fileName+" for reading.");
639  continue;
640  }
641  QTextStream in(&file);
642  int countRow = 0;
643  QImage image = QImage(xNPixels, yNPixels, QImage::Format_RGB32);
644  image.fill(qRgb(255, 255, 255));
645  while (!in.atEnd()) {
646  QString line = in.readLine();
647  QStringList fields = line.split(' ');
648  if (
649  (fields.at(0)== "north:" && fields.at(1).toDouble() != geoTopY)
650  || ((fields.at(0)== "south:" || fields.at(0) == "yllcorner" ) && fields.at(1).toDouble() != geoBottomY)
651  || (fields.at(0)== "east:" && fields.at(1).toDouble() != geoRightX)
652  || ((fields.at(0)== "west:" || fields.at(0) == "xllcorner" ) && fields.at(1).toDouble() != geoLeftX)
653  || ((fields.at(0)== "rows:" || fields.at(0) == "nrows" ) && fields.at(1).toInt() != yNPixels)
654  || ((fields.at(0)== "cols:" || fields.at(0) == "ncols" ) && fields.at(1).toInt() != xNPixels)
655  )
656  {
657  msgOut(MSG_ERROR, "Layer "+layerName+" has different coordinates. Aborting reading.");
658  break;
659  } else if (fields.at(0)== "null:" || fields.at(0) == "NODATA_value" || fields.at(0) == "nodata_value" ) {
660  localNoValue = fields.at(1).toDouble();
661  } else if (fields.size() > 5) {
662  for (int countColumn=0;countColumn<xNPixels;countColumn++){
663  inputValue = fields.at(countColumn).toDouble();
664  if (inputValue == localNoValue){
665  outputValue = noValue;
666  pxVector.at((countRow*xNPixels+countColumn)).changeValue(layerName,outputValue);
667  QColor nocolor(255,255,255);
668  color = nocolor;
669  }
670  else {
671  outputValue=layerVector.at(i).filterExogenousDataset(fields.at(countColumn).toDouble());
672  pxVector.at((countRow*xNPixels+countColumn)).changeValue(layerName,outputValue);
673  color = layerVector.at(i).getColor(outputValue);
674  }
675  image.setPixel(countColumn,countRow,color.rgb());
676  }
677  countRow++;
678  }
679  }
680  if (MTHREAD->MD->getBoolSetting("initialRandomShuffle") ){
681  layerVector.at(i).randomShuffle();
682  }
683  this->filterSubRegion(layerName);
684  if(layerVector.at(i).getDisplay()){
685  MTHREAD->updateImage(layerName,image);
686  //send the image to the gui...
687  refreshGUI();
688  }
689 
690 
691  }
692 }
void filterSubRegion(string layerName_h)
If subregion mode is on, this function place noValues on the selected layer for all out-of-region pix...
Definition: Gis.cpp:921
int yNPixels
number of pixels along the Y dimension
Definition: Gis.h:162
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
double noValue
value internally use as novalue (individual layer maps can have other values)
Definition: Gis.h:170
double geoBottomY
geo-coordinates of the map bottom border
Definition: Gis.h:169
double geoTopY
geo-coordinates of the map upper border
Definition: Gis.h:167
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
bool getBoolSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1117
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
double geoLeftX
geo-coordinates of the map left border
Definition: Gis.h:166
ModelData * MD
the model data object
Definition: ThreadManager.h:72
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
double geoRightX
geo-coordinates of the map right border
Definition: Gis.h:168
int xNPixels
number of pixels along the X dimension
Definition: Gis.h:161
void refreshGUI() const
Ping to periodically return the control to the GUI.
Definition: BaseClass.cpp:142
void updateImage(string layerName_h, const QImage &image_h)
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159
string pack ( const string &  parName,
const string &  forName,
const string &  dClass,
const int &  year 
) const
inline

Definition at line 148 of file Gis.h.

Referenced by Pixel::getDoubleValue().

148 {return parName+"#"+forName+"#"+dClass+"#"+i2s(year)+"#";};
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219

Here is the caller graph for this function:

void printBinMaps ( string  layerName_h = "")

Save an image in standard png format.

Print debug information (for each pixel in the requested interval, their values on the specified layer)

Definition at line 963 of file Gis.cpp.

Referenced by Output::printMaps().

963  {
964  msgOut(MSG_DEBUG,"Printing the maps as images");
965  int iteration = MTHREAD->SCD->getIteration(); // are we on the first year of the simulation ??
966  if(layerName_h == ""){
967  for (uint i=0;i<layerVector.size();i++){
968  if (!iteration || layerVector[i].getDynamicContent()) {layerVector[i].printBinMap();}
969  }
970  } else {
971  for (uint i=0;i<layerVector.size();i++){
972  if(layerVector[i].getName() == layerName_h){
973  if (!iteration || layerVector[i].getDynamicContent()) {layerVector[i].printBinMap();}
974  return;
975  }
976  }
977  msgOut(MSG_ERROR, "Layer "+layerName_h+" unknow. No layer printed.");
978  }
979 }
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
Definition: ThreadManager.h:75
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print a debug message, normally filtered out.
Definition: BaseClass.h:58
int getIteration()
Definition: Scheduler.h:48
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159

Here is the caller graph for this function:

void printDebugValues ( string  layerName_h,
int  min_h = 0,
int  max_h = 0 
)

Definition at line 890 of file Gis.cpp.

890  {
891  int min=min_h;
892  int max;
893  int ID, X, Y;
894  string out;
895  double value;
896  //double noValue = MTHREAD->MD->getDoubleSetting("noValue");
897  if (max_h==0){
898  max= pxVector.size();
899  }
900  else {
901  max = max_h;
902  }
903  msgOut(MSG_DEBUG,"Printing debug information for layer "+layerName_h+".");
904  for (int i=min;i<max;i++){
905  value = pxVector.at(i).getDoubleValue(layerName_h);
906  if (value != noValue){
907  ID = i;
908  X = pxVector.at(i).getX();
909  Y = pxVector.at(i).getY();
910  out = "Px. "+i2s(ID)+" ("+i2s(X)+","+i2s(Y)+"): "+d2s(value);
911  msgOut(MSG_DEBUG,out);
912  }
913  }
914 }
double noValue
value internally use as novalue (individual layer maps can have other values)
Definition: Gis.h:170
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
string d2s(const double &double_h) const
double to string conversion
Definition: BaseClass.cpp:229
Print a debug message, normally filtered out.
Definition: BaseClass.h:58
void printLayers ( string  layerName_h = "")

Print the specified layer or all layers (if param layerName_h is missing).

See also
Layers::print()

Definition at line 940 of file Gis.cpp.

Referenced by Output::printMaps().

940  {
941  msgOut(MSG_DEBUG,"Printing the layers");
942  int iteration = MTHREAD->SCD->getIteration(); // are we on the first year of the simulation ??
943  if(layerName_h == ""){
944  for (uint i=0;i<layerVector.size();i++){
945  //if(layerVector[i].getName() == "pixelIds"){
946  // cout << layerVector[i].getName() << endl;
947  //}
948  // not printing if we are in a not-0 iteration and the content of the map doesn't change
949  if (!iteration || layerVector[i].getDynamicContent()) layerVector[i].print();
950  }
951  } else {
952  for (uint i=0;i<layerVector.size();i++){
953  if(layerVector[i].getName() == layerName_h){
954  if (!iteration || layerVector[i].getDynamicContent()) layerVector[i].print();
955  return;
956  }
957  }
958  msgOut(MSG_ERROR, "Layer "+layerName_h+" unknow. No layer printed.");
959  }
960 }
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
Definition: ThreadManager.h:75
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print a debug message, normally filtered out.
Definition: BaseClass.h:58
int getIteration()
Definition: Scheduler.h:48
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159

Here is the caller graph for this function:

void resetLayer ( string  layerName_h)

Check if a layer with a certain name is loaded in the model. Used e.g. to check if the dtm layer (optional) exist.

Definition at line 538 of file Gis.cpp.

538  {
539 
540  for(uint i=0; i<layerVector.size(); i++){
541  if (layerVector.at(i).getName() == layerName_h){
542  for (uint i=0;i<xyNPixels; i++){
543  pxVector.at(i).changeValue(layerName_h,noValue); // bug solved 20071022, Antonello
544  }
545  return;
546  }
547  }
548  msgOut(MSG_ERROR, "I could not reset layer "+layerName_h+" as it doesn't exist!");
549 }
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
double noValue
value internally use as novalue (individual layer maps can have other values)
Definition: Gis.h:170
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
double xyNPixels
total number of pixels
Definition: Gis.h:163
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159
void setSpace ( )

Set the initial space environment, including loading data from files.

setSpace is called directly from the init system to setting the space environment in the model.
It is responsable to:

  • define map dimensions (from setting files)
  • create the pixels
  • initialize the layer
    See also
    initLayers
  • load the layer data from their fdata-files
    See also
    loadLayersDataFromFile
  • tell the GUI that our map will have (x,y) dimensions

Definition at line 57 of file Gis.cpp.

Referenced by Init::setInitLevel1().

57  {
58 
59 
60 
61  msgOut(MSG_INFO,"Creating the space...");
62 
63  // init basic settings....
64  geoTopY = MTHREAD->MD->getDoubleSetting("geoNorthEdge");
65  geoBottomY = MTHREAD->MD->getDoubleSetting("geoSouthEdge");
66  geoLeftX = MTHREAD->MD->getDoubleSetting("geoWestEdge");
67  geoRightX = MTHREAD->MD->getDoubleSetting("geoEastEdge");
68  xNPixels = MTHREAD->MD->getIntSetting("nCols");
69  yNPixels = MTHREAD->MD->getIntSetting("nRows");
70  noValue = MTHREAD->MD->getDoubleSetting("noValue");
73  yMetersByPixel = (geoTopY - geoBottomY)/yNPixels;
76  // creating pixels...
77  for (int i=0;i<yNPixels;i++){
78  for (int j=0;j<xNPixels;j++){
79  Pixel myPixel(i*xNPixels+j, MTHREAD);
80  myPixel.setCoordinates(j,i);
81  pxVector.push_back(myPixel);
82  }
83  }
84  initLayers();
86 
87  // Cashing the pixels owned by each region..
88  vector <ModelRegion*> regions = MTHREAD->MD->getAllRegions();
89  int nRegions = regions.size();
90  for(uint i=0;i<nRegions;i++){
91  regions[i]->setMyPixels();
92  }
93 
94  applySpatialStochasticValues(); // regional variance -> different tp in each pixel trought tp modifiers
95  applyStochasticRiskAdversion(); // risk adversion to each pixel
96  //cachePixelValues(); // For computational reasons cache some values in the constant layers directly as properties of the pixel object
97 
98  //< Print a layer of pixels id..
99  //addLayer("pxIds", "idx of the pixels", true, true, "pxIds.grd", true);
100  //resetLayer("pxIds");
101  //vector<Pixel*> allPixels = getAllPlotsByRegion(11000);
102  //for (int i=0;i<allPixels.size();i++){
103  // int pxId= allPixels[i]->getID();
104  // allPixels[i]->changeValue ("pxIds", pxId);
105  //}
106  //printLayers("pxIds");
107  //exit(1);
108 
109  MTHREAD->fitInWindow(); // tell the gui to fit the map to the widget
110 // countItems("landUse",false); // count the various records assigned to each legendItem. Do not print debug infos
111  return;
112 }
int yNPixels
number of pixels along the Y dimension
Definition: Gis.h:162
double noValue
value internally use as novalue (individual layer maps can have other values)
Definition: Gis.h:170
double geoBottomY
geo-coordinates of the map bottom border
Definition: Gis.h:169
double geoTopY
geo-coordinates of the map upper border
Definition: Gis.h:167
int getIntSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1105
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
double geoLeftX
geo-coordinates of the map left border
Definition: Gis.h:166
ModelData * MD
the model data object
Definition: ThreadManager.h:72
void loadLayersDataFromFile()
Load the data of a layer its datafile.
Definition: Gis.cpp:624
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
void initLayers()
Init the layers.
Definition: Gis.cpp:259
double getXyNPixels() const
Return the number of pixels on Y.
Definition: Gis.h:131
double geoRightX
geo-coordinates of the map right border
Definition: Gis.h:168
void applyStochasticRiskAdversion()
Give to each agend a stochastic risk adversion. For now Pixel = Agent.
Definition: Gis.cpp:199
double xMetersByPixel
pixel dimension (meters), X
Definition: Gis.h:164
double getHaByPixel() const
Return the total number of pixels.
Definition: Gis.h:132
string d2s(const double &double_h) const
double to string conversion
Definition: BaseClass.cpp:229
void applySpatialStochasticValues()
Apply stochastic simulation, e.g. regional volume growth s.d. -> tp multipliers.
Definition: Gis.cpp:121
Pixel-level class.
Definition: Pixel.h:47
int xNPixels
number of pixels along the X dimension
Definition: Gis.h:161
double xyNPixels
total number of pixels
Definition: Gis.h:163
void treeViewerChangeGeneralPropertyValue(string propertyName, string newValue)
double getDoubleSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1109
Print an INFO message.
Definition: BaseClass.h:59
void fitInWindow()
vector< ModelRegion * > getAllRegions(bool excludeResidual=true)
Definition: ModelData.cpp:379
double yMetersByPixel
pixel dimension (meters), Y
Definition: Gis.h:165

Here is the call graph for this function:

Here is the caller graph for this function:

int sub2realID ( int  id_h)

Transform the ID of a pixel in subregion coordinates to the real (and model used) coordinates.

Definition at line 982 of file Gis.cpp.

982  {
983  // IMPORTANT: this function is called at refreshGUI() times, so if there are output messages, call them with the option to NOT refresh the gui, otherwise we go to an infinite loop...
984  return id_h;
985 }
void swap ( const int &  swap_what)

Definition at line 1005 of file Gis.cpp.

1005  {
1006 
1007  for(uint i=0;i<pxVector.size();i++) {
1008  pxVector[i].swap(swap_what);
1009  }
1010 
1011 }
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
void unpack ( const string &  key,
string &  parName,
string &  forName,
string &  dClass,
int &  year 
) const

Definition at line 988 of file Gis.cpp.

988  {
989  int parNameDelimiter = key.find("#",0);
990  int forNameDelimiter = key.find("#",parNameDelimiter+1);
991  int dClassDelimiter = key.find("#",forNameDelimiter+1);
992  int yearDelimiter = key.find("#",dClassDelimiter+1);
993  if (yearDelimiter == string::npos){
994  msgOut(MSG_CRITICAL_ERROR, "Error in unpacking the key for the layer.");
995  }
996  parName.assign(key,0,parNameDelimiter);
997  forName.assign(key,parNameDelimiter+1,forNameDelimiter-parNameDelimiter-1);
998  dClass.assign(key,forNameDelimiter+1,dClassDelimiter-forNameDelimiter-1);
999  string yearString="";
1000  yearString.assign(key,dClassDelimiter+1,yearDelimiter-dClassDelimiter-1);
1001  year = s2i(yearString);
1002 }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62
int s2i(const string &string_h) const
string to integer conversion
Definition: BaseClass.cpp:149
void updateImage ( string  layerName_h)

Add one layer to the system.

Update an ALREADY EXISTING image and send the updated image to the GUI.
It is used instead of updating the individual pixels that is much more time consuming than change the individual pixels value and then upgrade the image as a whole.

Parameters
layername_hLayer from where get the image data

Definition at line 700 of file Gis.cpp.

Referenced by ModelCoreSpatial::updateOtherMapData().

700  {
701  msgOut (1, "Update image "+layerName_h+"...");
702 
703  // sub{X,Y}{R,L,T,B} refer to the subregion coordinates, but when this is not active they coincide with the whole region
704  QImage image = QImage(subXR-subXL+1, subYB-subYT+1, QImage::Format_RGB32);
705 
706  image.fill(qRgb(255, 255, 255));
707  int layerIndex=-1;
708  for (uint i=0;i<layerVector.size();i++){
709  if (layerVector.at(i).getName() == layerName_h){
710  layerIndex=i;
711  break;
712  }
713  }
714  if (layerIndex <0) {
715  msgOut(MSG_CRITICAL_ERROR, "Layer not found in Gis::updateImage()");
716  }
717 
718  for (int countRow=subYT;countRow<subYB;countRow++){
719  for (int countColumn=subXL;countColumn<subXR;countColumn++){
720  double value = pxVector.at((countRow*xNPixels+countColumn)).getDoubleValue(layerName_h);
721  QColor color = layerVector.at(layerIndex).getColor(value);
722  image.setPixel(countColumn-subXL,countRow-subYT,color.rgb());
723  }
724  }
725  MTHREAD->updateImage(layerName_h,image);
726  refreshGUI();
727 }
int subXR
sub region right X
Definition: Gis.h:172
vector< Pixel > pxVector
array of Pixel objects
Definition: Gis.h:158
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
int subXL
sub region left X
Definition: Gis.h:171
Print an error message and stop the model.
Definition: BaseClass.h:62
int subYT
sub region top Y
Definition: Gis.h:173
int xNPixels
number of pixels along the X dimension
Definition: Gis.h:161
int subYB
sub region bottom Y
Definition: Gis.h:174
void refreshGUI() const
Ping to periodically return the control to the GUI.
Definition: BaseClass.cpp:142
void updateImage(string layerName_h, const QImage &image_h)
vector< Layers > layerVector
array of Layer objects
Definition: Gis.h:159

Here is the caller graph for this function:

Member Data Documentation

double geoBottomY
private

geo-coordinates of the map bottom border

Definition at line 169 of file Gis.h.

double geoLeftX
private

geo-coordinates of the map left border

Definition at line 166 of file Gis.h.

double geoRightX
private

geo-coordinates of the map right border

Definition at line 168 of file Gis.h.

double geoTopY
private

geo-coordinates of the map upper border

Definition at line 167 of file Gis.h.

vector<Layers> layerVector
private

array of Layer objects

Definition at line 159 of file Gis.h.

vector<double> lUseTotals
private

totals, in ha, of area in the region for each type (cached values)

Definition at line 160 of file Gis.h.

double noValue
private

value internally use as novalue (individual layer maps can have other values)

Definition at line 170 of file Gis.h.

vector<Pixel> pxVector
private

array of Pixel objects

Definition at line 158 of file Gis.h.

int subXL
private

sub region left X

Definition at line 171 of file Gis.h.

int subXR
private

sub region right X

Definition at line 172 of file Gis.h.

int subYB
private

sub region bottom Y

Definition at line 174 of file Gis.h.

int subYT
private

sub region top Y

Definition at line 173 of file Gis.h.

double xMetersByPixel
private

pixel dimension (meters), X

Definition at line 164 of file Gis.h.

int xNPixels
private

number of pixels along the X dimension

Definition at line 161 of file Gis.h.

double xyNPixels
private

total number of pixels

Definition at line 163 of file Gis.h.

double yMetersByPixel
private

pixel dimension (meters), Y

Definition at line 165 of file Gis.h.

int yNPixels
private

number of pixels along the Y dimension

Definition at line 162 of file Gis.h.


The documentation for this class was generated from the following files: