FFSM++
1.1.0
French Forest Sector Model ++
|
Class to manage the spatial dimension. More...
#include <Gis.h>
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... | |
Layers * | getLayer (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... | |
Pixel * | getRandomPlotByValue (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 ®ion_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 |
Pixel * | getPixel (int x_h, int y_h) |
Pixel * | getPixel (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 > | |
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 > | |
V | findMap (const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V ¬FoundValue=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 > | |
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 > | |
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 > | |
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< Pixel > | pxVector |
array of Pixel objects More... | |
vector< Layers > | layerVector |
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 | |
ThreadManager * | MTHREAD |
Pointer to the Thread manager. More... | |
Class to manage the spatial dimension.
Gis class is responsable to provide all methods for spatial analysis.
It is equipped with two important vectors:
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.
Gis | ( | ThreadManager * | MTHREAD_h | ) |
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.
name_h | ID of the layer (no spaces!) |
label_h | layer label |
type_h | type of the layer, integer or contiguous |
dynamicContent_h | if it change during the time (so it needs to be printed each year) or not |
fullFilename_h | if the layer has to be read at the beginning, the name of the associated datafile (default="") |
It:
Definition at line 515 of file Gis.cpp.
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.
name_h | Name of the layer |
ID_h | ID of the specific lagend item |
Definition at line 579 of file Gis.cpp.
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().
|
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.
|
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.
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.
layerName_h | Name of the layer |
debug | Print the values on the GUI |
Definition at line 599 of file Gis.cpp.
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.
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.
onlyFreePlots | Flag to get only plots marked as free (d=false) |
outputLevel | Level 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.
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().
vector< Pixel * > getAllPlotsByRegion | ( | int | regId_h, |
bool | shuffle = false |
||
) |
Definition at line 864 of file Gis.cpp.
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.
layer_h | Name of the layer |
layerValue_h | Value we want the plots for |
onlyFreePlots | Flag to get only plots marked as free (d=false) |
outputLevel | Level 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.
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.
layer_h | Name of the layer |
layerValues_h | Values we want the plots for |
onlyFreePlots | Flag to get only plots marked as free (d=false) |
outputLevel | Level 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.
|
inline |
Definition at line 137 of file Gis.h.
Referenced by Layers::print().
|
inline |
Definition at line 138 of file Gis.h.
Referenced by Layers::print().
|
inline |
Definition at line 139 of file Gis.h.
Referenced by Layers::print().
|
inline |
Return a pixel pointer from its ID.
Definition at line 136 of file Gis.h.
Referenced by Layers::print().
|
inline |
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.
vector< string > getLayerNames | ( | ) |
vector< Layers * > getLayerPointers | ( | ) |
|
inline |
Definition at line 133 of file Gis.h.
Referenced by Pixel::changeValue(), Layers::getCategory(), Layers::getColor(), Pixel::getDoubleValue(), Layers::print(), and Layers::randomShuffle().
|
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().
|
inline |
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.
|
inline |
Definition at line 142 of file Gis.h.
Referenced by Layers::printBinMap().
|
inline |
Definition at line 143 of file Gis.h.
Referenced by Layers::printBinMap().
|
inline |
Definition at line 145 of file Gis.h.
Referenced by Layers::printBinMap().
|
inline |
Definition at line 144 of file Gis.h.
Referenced by Layers::printBinMap().
|
inline |
Definition at line 140 of file Gis.h.
Referenced by Layers::print().
|
inline |
Definition at line 129 of file Gis.h.
Referenced by Pixel::getPixelsAtDistLevel(), Layers::print(), Layers::printBinMap(), and Scheduler::run().
|
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().
|
inline |
Definition at line 141 of file Gis.h.
Referenced by Layers::print().
|
inline |
Return the number of pixels on X.
Definition at line 130 of file Gis.h.
Referenced by Pixel::getPixelsAtDistLevel(), and Layers::print().
void initLayers | ( | ) |
Init the layers.
Called from setSpace(), initLayers() is responsable of:
Definition at line 259 of file Gis.cpp.
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
Definition at line 320 of file Gis.cpp.
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().
|
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!!!
Definition at line 624 of file Gis.cpp.
|
inline |
Definition at line 148 of file Gis.h.
Referenced by Pixel::getDoubleValue().
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().
void printDebugValues | ( | string | layerName_h, |
int | min_h = 0 , |
||
int | max_h = 0 |
||
) |
Definition at line 890 of file Gis.cpp.
void printLayers | ( | string | layerName_h = "" | ) |
Print the specified layer or all layers (if param layerName_h is missing).
Definition at line 940 of file Gis.cpp.
Referenced by Output::printMaps().
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.
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:
Definition at line 57 of file Gis.cpp.
Referenced by Init::setInitLevel1().
int sub2realID | ( | int | id_h | ) |
Transform the ID of a pixel in subregion coordinates to the real (and model used) coordinates.
void swap | ( | const int & | swap_what | ) |
void unpack | ( | const string & | key, |
string & | parName, | ||
string & | forName, | ||
string & | dClass, | ||
int & | year | ||
) | const |
Definition at line 988 of file Gis.cpp.
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.
layername_h | Layer from where get the image data |
Definition at line 700 of file Gis.cpp.
Referenced by ModelCoreSpatial::updateOtherMapData().
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |