FFSM++ 1.1.0
French Forest Sector Model ++
Loading...
Searching...
No Matches
Gis.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2015 by Laboratoire d'Economie Forestière *
3 * http://ffsm-project.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version, given the compliance with the *
9 * exceptions listed in the file COPYING that is distribued together *
10 * with this file. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
22#ifndef STDGIS_H
23#define STDGIS_H
24
25#include <cstdlib>
26#include <list>
27#include <string>
28#include <vector>
29#include <stdexcept>
30#include <fstream>
31#include <iostream>
32#include <sstream>
33
34// regmas headers..
35#include "BaseClass.h"
36#include "ModelData.h"
37#include "Layers.h"
38#include "Pixel.h"
39#include "ModelRegion.h"
40
41using namespace std;
42
43struct lUseCats;
44struct reclassRules;
45class Pixel;
46class Agent_space;
47class QImage;
48
49
50/// Class to manage the spatial dimension
51/**
52Gis class is responsable to provide all methods for spatial analysis.
53<br>It is equipped with two important vectors:
54 - pxVector contains the array of all pixels on the screen
55 - layerVector contains the layer objects
56<br>Along the model, IDs of pixels are assigned from left to right, from top to down:
57<br> --->
58<br> /
59<br> --->
60<br> /
61<br> --->
62<p>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.
63
64@author Antonello Lobianco
65*/
66
67class Gis: public BaseClass{
68
69public:
70 Gis(ThreadManager* MTHREAD_h); ///< Constructor
71 ~Gis();
72 /// Set the initial space environment, including loading data from files
73 void setSpace();
74 /// Init the layers
75 void initLayers();
77 void initLayersModelData(const int& year_h=DATA_NOW);
78 /// Apply the forest reclassification with the rules defined in reclRules sheet
80 /// If subregion mode is on, this function place noValues on the selected layer for all out-of-region pixels
81 void filterSubRegion(string layerName_h);
82 ///< Update the image behind a layer to the GUI;
83 void updateImage(string layerName_h);
84 ///< Add one layer to the system
85 void addLayer(string name_h, string label_h, bool isInteger_h, bool dynamicContent_h, string fullFileName_h = "", bool display_h=true);
86 ///< Fill a layer with empty values
87 void resetLayer(string layerName_h);
88 ///< Check if a layer with a certain name is loaded in the model. Used e.g. to check if the dtm layer (optional) exist.
89 bool layerExist(const string & layerName_h, bool exactMatch = true) const;
90 ///< Return a pointer to a layer given its name
91 Layers* getLayer(const string& layerName_h);
92 ///< Add a legend item to an existing layer
93 void addLegendItem (
94 string name_h,
95 int D_h,
96 string label_h,
97 int rColor_h,
98 int gColor_h,
99 int bColor_h,
100 double minValue_h,
101 double maxValue_h );
102 /// Count the pixels within each legend item for the selected layer
103 void countItems(const string& layerName_h, const bool& debug=false);
104 /// Return a pointer to a plot with a specific value for the specified layer
105 Pixel* getRandomPlotByValue(string layer_h, int layerValue__h);
106 /// 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
107 vector <Pixel*> getAllPlotsByValue(string layer_h, int layerValue_h, int outputLevel=MSG_WARNING);
108 /// 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
109 vector <Pixel*> getAllPlotsByValue(string layer_h, vector<int> layerValues_h, int outputLevel=MSG_WARNING);
110 /// Return the vector (shuffled) of all plots. It is also possible to specify the level in case of failure
111 vector <Pixel*> getAllPlots(bool masked=true, int outputLevel=MSG_WARNING);
112 /// Return the vector of all plots by a specific region (main region or subregion), optionally shuffled;
113 vector <Pixel*> getAllPlotsByRegion(ModelRegion &region_h, bool shuffle=false);
114 vector <Pixel*> getAllPlotsByRegion(int regId_h, bool shuffle=false);
115 /// Return a vector of the layer ids (as string)
116 vector <string> getLayerNames();
117 /// Return a vector of pointers of existing layers
118 vector <Layers*> getLayerPointers();
119 /// Print the specified layer or all layers (if param layerName_h is missing). @see Layers::print()
120 void printLayers(string layerName_h="");
121 /// Save an image in standard png format
122 void printBinMaps(string layerName_h="");
123
124
125 ///< Print debug information (for each pixel in the requested interval, their values on the specified layer)
126 void printDebugValues (string layerName_h, int min_h=0, int max_h=0);
127 double getDistance(const Pixel* px1, const Pixel* px2);
128
129 int getXNPixels() const {return xNPixels;}; ///< Return the number of pixels on X
130 int getYNPixels() const {return yNPixels;}; ///< Return the number of pixels on Y
131 double getXyNPixels()const {return xyNPixels;}; ///< Return the total number of pixels
132 double getHaByPixel() const {return ((xMetersByPixel*yMetersByPixel)/10000) ;};
133 double getNoValue() const {return noValue;};
134 Pixel* getPixel(int x_h, int y_h){return &pxVector.at(x_h+y_h*xNPixels);}; ///< Return a pixel pointer from its coordinates
135 Pixel* getPixel(int ID_h){return &pxVector.at(ID_h);}; ///< Return a pixel pointer from its ID
136 double getGeoTopY() const {return geoTopY;};
137 double getGeoBottomY() const {return geoBottomY;};
138 double getGeoLeftX() const {return geoLeftX;};
139 double getGeoRightX() const {return geoRightX;};
140 double getXMetersByPixel() const {return xMetersByPixel;};
141 double getYMetersByPixel() const {return yMetersByPixel;};
142 int getSubXL() const {return subXL;};
143 int getSubXR() const {return subXR;};
144 int getSubYT() const {return subYT;};
145 int getSubYB() const {return subYB;};
146 /// Transform the ID of a pixel in subregion coordinates to the real (and model used) coordinates
147 int sub2realID(int id_h);
148 string pack(const string& parName, const string& forName, const string& dClass, const int& year) const {return parName+"#"+forName+"#"+dClass+"#"+i2s(year)+"#";};
149 void unpack(const string& key, string& parName, string& forName, string& dClass, int& year) const;
150
151 void swap(const int &swap_what);
152
153private:
154 void loadLayersDataFromFile(); ///< Load the data of a layer its datafile
155 void applySpatialStochasticValues(); ///< Apply stochastic simulation, e.g. regional volume growth s.d. -> tp multipliers
156 void applyStochasticRiskAdversion(); ///< Give to each agend a stochastic risk adversion. For now Pixel = Agent
157 //void cachePixelValues(); ///< For computational reasons cache some values in constant layers directly as properties of the pixel object
158 vector <Pixel> pxVector; ///< array of Pixel objects
159 vector <Layers> layerVector; ///< array of Layer objects
160 vector <double> lUseTotals; ///< totals, in ha, of area in the region for each type (cached values)
161 int xNPixels; ///< number of pixels along the X dimension
162 int yNPixels; ///< number of pixels along the Y dimension
163 double xyNPixels; ///< total number of pixels
164 double xMetersByPixel; ///< pixel dimension (meters), X
165 double yMetersByPixel; ///< pixel dimension (meters), Y
166 double geoLeftX; ///< geo-coordinates of the map left border
167 double geoTopY; ///< geo-coordinates of the map upper border
168 double geoRightX; ///< geo-coordinates of the map right border
169 double geoBottomY; ///< geo-coordinates of the map bottom border
170 double noValue; ///< value internally use as novalue (individual layer maps can have other values)
171 int subXL; ///< sub region left X
172 int subXR; ///< sub region right X
173 int subYT; ///< sub region top Y
174 int subYB; ///< sub region bottom Y
175
176
177
178};
179
180#endif
This file is the header of BaseClass and it is included by ALL compiled code.
@ DATA_NOW
The required data is for the current year.
Definition BaseClass.h:73
@ MSG_WARNING
Print a WARNING message.
Definition BaseClass.h:60
Base class for the regmas application.
Definition BaseClass.h:239
string i2s(const int &int_h) const
integer to string conversion
Class to manage the spatial dimension.
Definition Gis.h:67
vector< Layers * > getLayerPointers()
Return a vector of pointers of existing layers.
Definition Gis.cpp:881
string pack(const string &parName, const string &forName, const string &dClass, const int &year) const
Definition Gis.h:148
int yNPixels
number of pixels along the Y dimension
Definition Gis.h:162
void printDebugValues(string layerName_h, int min_h=0, int max_h=0)
Definition Gis.cpp:890
int getSubXR() const
Definition Gis.h:143
void initLayersModelData(const int &year_h=DATA_NOW)
int subXL
sub region left X
Definition Gis.h:171
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
double getYMetersByPixel() const
Definition Gis.h:141
void applyForestReclassification()
Apply the forest reclassification with the rules defined in reclRules sheet.
Definition Gis.cpp:439
double geoRightX
geo-coordinates of the map right border
Definition Gis.h:168
int getYNPixels() const
Return the number of pixels on X.
Definition Gis.h:130
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
~Gis()
Definition Gis.cpp:44
int xNPixels
number of pixels along the X dimension
Definition Gis.h:161
int getSubYT() const
Definition Gis.h:144
double noValue
value internally use as novalue (individual layer maps can have other values)
Definition Gis.h:170
void unpack(const string &key, string &parName, string &forName, string &dClass, int &year) const
Definition Gis.cpp:988
double xMetersByPixel
pixel dimension (meters), X
Definition Gis.h:164
double xyNPixels
total number of pixels
Definition Gis.h:163
double getXyNPixels() const
Return the number of pixels on Y.
Definition Gis.h:131
vector< Layers > layerVector
array of Layer objects
Definition Gis.h:159
double geoLeftX
geo-coordinates of the map left border
Definition Gis.h:166
Pixel * getRandomPlotByValue(string layer_h, int layerValue__h)
Return a pointer to a plot with a specific value for the specified layer.
Definition Gis.cpp:730
void applyStochasticRiskAdversion()
Give to each agend a stochastic risk adversion. For now Pixel = Agent.
Definition Gis.cpp:199
double getNoValue() const
Definition Gis.h:133
double yMetersByPixel
pixel dimension (meters), Y
Definition Gis.h:165
vector< double > lUseTotals
totals, in ha, of area in the region for each type (cached values)
Definition Gis.h:160
double getHaByPixel() const
Return the total number of pixels.
Definition Gis.h:132
Pixel * getPixel(int x_h, int y_h)
Definition Gis.h:134
double getGeoTopY() const
Return a pixel pointer from its ID.
Definition Gis.h:136
double getGeoLeftX() const
Definition Gis.h:138
void swap(const int &swap_what)
Definition Gis.cpp:1005
int getSubXL() const
Definition Gis.h:142
void initLayers()
Init the layers.
Definition Gis.cpp:259
void setSpace()
Set the initial space environment, including loading data from files.
Definition Gis.cpp:57
int subYT
sub region top Y
Definition Gis.h:173
int getXNPixels() const
Definition Gis.h:129
void printBinMaps(string layerName_h="")
Save an image in standard png format.
Definition Gis.cpp:963
int sub2realID(int id_h)
Transform the ID of a pixel in subregion coordinates to the real (and model used) coordinates.
Definition Gis.cpp:982
int getSubYB() const
Definition Gis.h:145
double geoTopY
geo-coordinates of the map upper border
Definition Gis.h:167
vector< Pixel > pxVector
array of Pixel objects
Definition Gis.h:158
int subXR
sub region right X
Definition Gis.h:172
double getDistance(const Pixel *px1, const Pixel *px2)
Definition Gis.cpp:929
void initLayersPixelData()
Definition Gis.cpp:320
double geoBottomY
geo-coordinates of the map bottom border
Definition Gis.h:169
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
void applySpatialStochasticValues()
Apply stochastic simulation, e.g. regional volume growth s.d. -> tp multipliers.
Definition Gis.cpp:121
Pixel * getPixel(int ID_h)
Return a pixel pointer from its coordinates.
Definition Gis.h:135
int subYB
sub region bottom Y
Definition Gis.h:174
double getGeoRightX() const
Definition Gis.h:139
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 > getLayerNames()
Return a vector of the layer ids (as string)
Definition Gis.cpp:872
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....
Definition Gis.cpp:758
double getXMetersByPixel() const
Definition Gis.h:140
void printLayers(string layerName_h="")
Print the specified layer or all layers (if param layerName_h is missing).
Definition Gis.cpp:940
void loadLayersDataFromFile()
Load the data of a layer its datafile.
Definition Gis.cpp:624
Layers * getLayer(const string &layerName_h)
Add a legend item to an existing layer.
Definition Gis.cpp:429
double getGeoBottomY() const
Definition Gis.h:137
void countItems(const string &layerName_h, const bool &debug=false)
Count the pixels within each legend item for the selected layer.
Definition Gis.cpp:599
bool layerExist(const string &layerName_h, bool exactMatch=true) const
Return a pointer to a layer given its name.
Definition Gis.cpp:552
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
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
void updateImage(string layerName_h)
Add one layer to the system.
Definition Gis.cpp:700
Define layer objects at the regional level.
Definition Layers.h:49
Pixel-level class.
Definition Pixel.h:47
Thread manager. Responsable to manage the main thread and "speak" with the GUI.