Gis Class Reference

Class to manage the spatial dimension. More...

#include <Gis.h>

Inheritance diagram for Gis:

Inheritance graph
[legend]
Collaboration diagram for Gis:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Gis (ThreadManager *MTHREAD_h)
 Constructor.
 ~Gis ()
void setSpace ()
 Set the initial space environment, including loading data from files.
void initLayers ()
 Init the layers.
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;.
void updateImage (string layerName_h)
 Add one layer to the system.
void addLayer (string name_h, string label_h, bool isInteger_h, bool dynamicContent_h, string fullFileName_h="")
 Fill a layer with empty values.
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.
bool layerExist (string layerName_h)
 Add a legend item to an existing layer.
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 addReclassificationRule (string name_h, int inCode_h, int outCode_h, double p_h)
 Add a reclassification rule to an existing layer.
void countItems (string layerName_h, bool debug=false)
 Count the pixels within each legend item for the selected layer.
PixelgetRandomPlotByValue (string layer_h, int layerValue__h, bool onlyFreePlots=false)
 Return a pointer to a plot with a specific value for the specified layer, optionally filtering only the free plots.
vector< Pixel * > getAllPlotsByValue (string layer_h, int layerValue_h, bool onlyFreePlots=false, int outputLevel=MSG_WARNING)
 Return the vector (shuffled) of all plots with a specific value for a specified layer, optionally filtering only the free ones. It is also possible to specify the level in case of failure (no free plots available).
vector< Pixel * > getAllPlotsByValue (string layer_h, vector< int > layerValues_h, bool onlyFreePlots=false, int outputLevel=MSG_WARNING)
 Return the vector (shuffled) of all plots with specific values for a specified layer, optionally filtering only the free ones. It is also possible to specify the level in case of failure (no free plots available).
vector< Pixel * > getAllPlots (bool onlyFreePlots=false, int outputLevel=MSG_WARNING)
 Return the vector (shuffled) of all plots, optionally filtering only the free ones. It is also possible to specify the level in case of failure (no free plots available).
vector< string > getLayerNames ()
 Return a vector of the layer ids (as string).
vector< Layers * > getLayerPointers ()
 Return a vector of pointers of existing layers.
void calculateDistancesToClosestFarm ()
 Fill the layer of distance with closest farms;.
void printLayers (string layerName_h="")
 Print the specified layer or all layers (if param layerName_h is missing).
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).
void printDebugValues (string layerName_h, int min_h=0, int max_h=0)
double getDistance (const Pixel *px1, const Pixel *px2)
double getAgrDistCost (const Pixel *px1, const Pixel *px2)
vector< Agent_space * > getClosestAgents (Pixel *px_h, int size, const string &category="")
 The function return a list of all agents (if par category is empty) or of a specified agent category closest to a certain pixel.
vector< double > getAgrLandStats ()
 Return total, owned and rented agr. land.
int getXNPixels () const
int getYNPixels () const
 Return the number of pixels on X.
double getXyNPixels () const
 Return the number of pixels on Y.
double getHaByPixel () const
 Return the total number of pixels.
double getNoValue () const
PixelgetPixel (int x_h, int y_h)
PixelgetPixel (int ID_h)
 Return a pixel pointer from its coordinates.
double getGeoTopY () const
 Return a pixel pointer from its ID.
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.
bool isAgrCode (int code_h)
 return true if a land use code is agricultural

Private Member Functions

void loadLayersDataFromFile ()
 Load the data of a layer its datafile.

Private Attributes

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

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:

Pixel origin (0,0) on the top left corner is also the system used by the underlying liraries, 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 64 of file Gis.h.


Constructor & Destructor Documentation

Gis ( ThreadManager MTHREAD_h  ) 

Constructor.

The constructor of the GIS (unique) instance want:

Parameters:
RD_h Pointer to the manager of the regional data
MTHREAD_h Pointer to the main thread manager

Definition at line 40 of file Gis.cpp.

~Gis (  ) 

Definition at line 46 of file Gis.cpp.


Member Function Documentation

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 60 of file Gis.cpp.

Referenced by Init::setInitLevel1().

Here is the caller graph for this function:

void initLayers (  ) 

Init the layers.

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

Definition at line 104 of file Gis.cpp.

Referenced by setSpace().

Here is the caller graph for this function:

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.

When the subRegionMode is actived also agents mouldCoefficients are rescaled to match the new subregion, however this is just approximated, as the upscaling process was performed on the whole region.

Definition at line 615 of file Gis.cpp.

Referenced by loadLayersDataFromFile().

Here is the caller graph for this function:

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_h Layer from where get the image data

Definition at line 388 of file Gis.cpp.

Referenced by Manager_farmers::act(), Output::collectData(), filterSubRegion(), Manager_farmers::landAllocation(), Manager_farmers::locateMyAgents(), and Scheduler::run().

Here is the caller graph for this function:

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

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_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 202 of file Gis.cpp.

Referenced by initLayers(), Output::initOutputMaps(), and Manager_farmers::locateMyAgents().

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 221 of file Gis.cpp.

Referenced by Manager_farmers::act(), and Output::collectData().

Here is the caller graph for this function:

bool layerExist ( string  layerName_h  ) 

Add a legend item to an existing layer.

Definition at line 235 of file Gis.cpp.

Referenced by Agent_farmer::filterActivity().

Here is the caller graph for this function:

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_h Name of the layer
ID_h ID of the specific lagend item
See also:
Layers::addLegendItem

Definition at line 252 of file Gis.cpp.

Referenced by initLayers(), Output::initOutputMaps(), and Manager_farmers::locateMyAgents().

Here is the caller graph for this function:

void addReclassificationRule ( string  name_h,
int  inCode_h,
int  outCode_h,
double  p_h 
)

Add a reclassification rule to an existing layer.

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

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

See also:
Layers::addReclassificationRule

Definition at line 291 of file Gis.cpp.

Referenced by initLayers().

Here is the caller graph for this function:

void countItems ( string  layerName_h,
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_h Name of the layer
debug Print the values on the GUI
See also:
Layers::countMyPixels

Definition at line 272 of file Gis.cpp.

Referenced by setSpace().

Here is the caller graph for this function:

Pixel * getRandomPlotByValue ( string  layer_h,
int  layerValue__h,
bool  onlyFreePlots = false 
)

Return a pointer to a plot with a specific value for the specified layer, optionally filtering only the free plots.

Definition at line 416 of file Gis.cpp.

vector< Pixel * > getAllPlotsByValue ( string  layer_h,
int  layerValue_h,
bool  onlyFreePlots = false,
int  outputLevel = MSG_WARNING 
)

Return the vector (shuffled) of all plots with a specific value for a specified layer, optionally filtering only the free ones. It is also possible to specify the level in case of failure (no free plots available).

Parameters:
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 455 of file Gis.cpp.

Referenced by Manager_farmers::landAllocation(), and Manager_farmers::locateMyAgents().

Here is the caller graph for this function:

vector< Pixel * > getAllPlotsByValue ( string  layer_h,
vector< int >  layerValues_h,
bool  onlyFreePlots = false,
int  outputLevel = MSG_WARNING 
)

Return the vector (shuffled) of all plots with specific values for a specified layer, optionally filtering only the free ones. It is also possible to specify the level in case of failure (no free plots available).

Parameters:
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 495 of file Gis.cpp.

vector< Pixel * > getAllPlots ( bool  onlyFreePlots = false,
int  outputLevel = MSG_WARNING 
)

Return the vector (shuffled) of all plots, optionally filtering only the free ones. It is also possible to specify the level in case of failure (no free plots available).

Parameters:
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 538 of file Gis.cpp.

Referenced by Manager_space::assignSpatialObjectsToAgents().

Here is the caller graph for this function:

vector< string > getLayerNames (  ) 

Return a vector of the layer ids (as string).

Definition at line 564 of file Gis.cpp.

vector< Layers * > getLayerPointers (  ) 

Return a vector of pointers of existing layers.

Definition at line 573 of file Gis.cpp.

Referenced by ThreadManager::computeQuery().

void calculateDistancesToClosestFarm (  ) 

Fill the layer of distance with closest farms;.

Definition at line 779 of file Gis.cpp.

Referenced by Scheduler::run().

Here is the caller graph for this function:

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 711 of file Gis.cpp.

Referenced by Output::printMaps().

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 731 of file Gis.cpp.

Referenced by Output::printMaps().

Here is the caller graph for this function:

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

Definition at line 582 of file Gis.cpp.

double getDistance ( const Pixel px1,
const Pixel px2 
)

Definition at line 642 of file Gis.cpp.

Referenced by calculateDistancesToClosestFarm(), getAgrDistCost(), and Agent_space::getDistance().

Here is the caller graph for this function:

double getAgrDistCost ( const Pixel px1,
const Pixel px2 
)

Definition at line 652 of file Gis.cpp.

vector< Agent_space * > getClosestAgents ( Pixel px_h,
int  size,
const string &  category = "" 
)

The function return a list of all agents (if par category is empty) or of a specified agent category closest to a certain pixel.

The function return a list of all agents (if par category is empty) or of a specified agent category closest to a certain pixel

Parameters:
px_h pointer to the pixel we want get the closest agents
size how many agents we want return
category category of agents we want (optional)

Definition at line 663 of file Gis.cpp.

Referenced by calculateDistancesToClosestFarm(), Manager_farmers::landAllocation(), and Manager_farmers::quotePlot().

Here is the caller graph for this function:

vector< double > getAgrLandStats (  ) 

Return total, owned and rented agr. land.

Definition at line 687 of file Gis.cpp.

Referenced by Scheduler::run(), and Init::setInitLevel5().

Here is the caller graph for this function:

int getXNPixels (  )  const [inline]

Definition at line 127 of file Gis.h.

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

Here is the caller graph for this function:

int getYNPixels (  )  const [inline]

Return the number of pixels on X.

Definition at line 128 of file Gis.h.

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

Here is the caller graph for this function:

double getXyNPixels (  )  const [inline]

Return the number of pixels on Y.

Definition at line 129 of file Gis.h.

Referenced by Layers::countMyPixels(), Manager_farmers::locateMyAgents(), Layers::randomShuffle(), and setSpace().

Here is the caller graph for this function:

double getHaByPixel (  )  const [inline]

Return the total number of pixels.

Definition at line 130 of file Gis.h.

Referenced by getAgrLandStats(), Agent_farmer::getUAA(), Manager_farmers::landAllocation(), Manager_farmers::locateMyAgents(), Output::printAggregatedData(), and setSpace().

Here is the caller graph for this function:

double getNoValue (  )  const [inline]

Definition at line 131 of file Gis.h.

Referenced by Agent_farmer::collectProductionEffects(), Pixel::getDoubleValue(), Manager_farmers::locateMyAgents(), Layers::print(), Layers::randomShuffle(), and Manager_farmers::removeFromModel().

Here is the caller graph for this function:

Pixel* getPixel ( int  x_h,
int  y_h 
) [inline]

Definition at line 132 of file Gis.h.

Referenced by Agent_farmer::collectProductionEffects(), ThreadManager::computeQuery(), Layers::countMyPixels(), Pixel::getPixelsAtDistLevel(), Manager_farmers::locateMyAgents(), Layers::print(), Layers::printBinMap(), Layers::randomShuffle(), Scheduler::run(), and SuperAgentManager::update().

Here is the caller graph for this function:

Pixel* getPixel ( int  ID_h  )  [inline]

Return a pixel pointer from its coordinates.

Definition at line 133 of file Gis.h.

double getGeoTopY (  )  const [inline]

Return a pixel pointer from its ID.

Definition at line 134 of file Gis.h.

Referenced by Layers::print().

Here is the caller graph for this function:

double getGeoBottomY (  )  const [inline]

Definition at line 135 of file Gis.h.

Referenced by Layers::print().

Here is the caller graph for this function:

double getGeoLeftX (  )  const [inline]

Definition at line 136 of file Gis.h.

Referenced by Layers::print().

Here is the caller graph for this function:

double getGeoRightX (  )  const [inline]

Definition at line 137 of file Gis.h.

Referenced by Layers::print().

Here is the caller graph for this function:

double getXMetersByPixel (  )  const [inline]

Definition at line 138 of file Gis.h.

Referenced by Layers::print().

Here is the caller graph for this function:

double getYMetersByPixel (  )  const [inline]

Definition at line 139 of file Gis.h.

Referenced by Layers::print().

Here is the caller graph for this function:

int getSubXL (  )  const [inline]

Definition at line 140 of file Gis.h.

Referenced by Layers::printBinMap().

Here is the caller graph for this function:

int getSubXR (  )  const [inline]

Definition at line 141 of file Gis.h.

Referenced by Layers::printBinMap().

Here is the caller graph for this function:

int getSubYT (  )  const [inline]

Definition at line 142 of file Gis.h.

Referenced by Layers::printBinMap().

Here is the caller graph for this function:

int getSubYB (  )  const [inline]

Definition at line 143 of file Gis.h.

Referenced by Layers::printBinMap().

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 750 of file Gis.cpp.

Referenced by ThreadManager::computeQuery().

bool isAgrCode ( int  code_h  ) 

return true if a land use code is agricultural

Definition at line 770 of file Gis.cpp.

Referenced by Output::printAggregatedData(), and Output::printDetailedData().

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 314 of file Gis.cpp.

Referenced by setSpace().

Here is the caller graph for this function:


Member Data Documentation

vector<Pixel> pxVector [private]

array of Pixel objects

Definition at line 150 of file Gis.h.

Referenced by addLayer(), calculateDistancesToClosestFarm(), getAgrLandStats(), getAllPlots(), getAllPlotsByValue(), getPixel(), getRandomPlotByValue(), loadLayersDataFromFile(), printDebugValues(), resetLayer(), setSpace(), and updateImage().

vector<Layers> layerVector [private]

array of Layer objects

Definition at line 151 of file Gis.h.

Referenced by addLayer(), addLegendItem(), addReclassificationRule(), countItems(), getLayerNames(), getLayerPointers(), layerExist(), loadLayersDataFromFile(), printBinMaps(), printLayers(), resetLayer(), and updateImage().

vector<double> lUseTotals [private]

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

Definition at line 152 of file Gis.h.

int xNPixels [private]

number of pixels along the X dimension

Definition at line 153 of file Gis.h.

Referenced by filterSubRegion(), getPixel(), getXNPixels(), loadLayersDataFromFile(), setSpace(), sub2realID(), and updateImage().

int yNPixels [private]

number of pixels along the Y dimension

Definition at line 154 of file Gis.h.

Referenced by filterSubRegion(), getYNPixels(), loadLayersDataFromFile(), and setSpace().

double xyNPixels [private]

total number of pixels

Definition at line 155 of file Gis.h.

Referenced by addLayer(), getXyNPixels(), resetLayer(), and setSpace().

double xMetersByPixel [private]

pixel dimension (meters), X

Definition at line 156 of file Gis.h.

Referenced by getDistance(), getHaByPixel(), getXMetersByPixel(), initLayers(), and setSpace().

double yMetersByPixel [private]

pixel dimension (meters), Y

Definition at line 157 of file Gis.h.

Referenced by getDistance(), getHaByPixel(), getYMetersByPixel(), initLayers(), and setSpace().

double geoLeftX [private]

geo-coordinates of the map left border

Definition at line 158 of file Gis.h.

Referenced by getGeoLeftX(), loadLayersDataFromFile(), and setSpace().

double geoTopY [private]

geo-coordinates of the map upper border

Definition at line 159 of file Gis.h.

Referenced by getGeoTopY(), loadLayersDataFromFile(), and setSpace().

double geoRightX [private]

geo-coordinates of the map right border

Definition at line 160 of file Gis.h.

Referenced by getGeoRightX(), loadLayersDataFromFile(), and setSpace().

double geoBottomY [private]

geo-coordinates of the map bottom border

Definition at line 161 of file Gis.h.

Referenced by getGeoBottomY(), loadLayersDataFromFile(), and setSpace().

double noValue [private]

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

Definition at line 162 of file Gis.h.

Referenced by addLayer(), filterSubRegion(), getNoValue(), loadLayersDataFromFile(), printDebugValues(), resetLayer(), and setSpace().

int subXL [private]

sub region left X

Definition at line 163 of file Gis.h.

Referenced by filterSubRegion(), getSubXL(), sub2realID(), and updateImage().

int subXR [private]

sub region right X

Definition at line 164 of file Gis.h.

Referenced by filterSubRegion(), getSubXR(), sub2realID(), and updateImage().

int subYT [private]

sub region top Y

Definition at line 165 of file Gis.h.

Referenced by filterSubRegion(), getSubYT(), sub2realID(), and updateImage().

int subYB [private]

sub region bottom Y

Definition at line 166 of file Gis.h.

Referenced by filterSubRegion(), getSubYB(), sub2realID(), and updateImage().

bool subRegionMode [private]

Definition at line 167 of file Gis.h.

Referenced by filterSubRegion(), and Gis().


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