FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Parser::FMTareaparser Class Reference

#include <FMTareaparser.hpp>

Inheritance diagram for Parser::FMTareaparser:
[legend]
Collaboration diagram for Parser::FMTareaparser:
[legend]

Public Member Functions

Spatial::FMTforest readrasters (const std::vector< Core::FMTtheme > &themes, const std::vector< std::string > &data_rasters, const std::string &age, double agefactor=1.0, double areafactor=0.0001, std::string lock="") const
 
template<typename T >
bool writelayer (const Spatial::FMTlayer< T > &layer, std::string location, const std::map< T, std::string > &mapping, std::string format="GTiff") const
 
bool writelayer (const Spatial::FMTlayer< double > &layer, std::string location, std::string format="GTiff") const
 
bool writeforest (const Spatial::FMTforest &for_layer, const std::vector< Core::FMTtheme > &themes, const std::vector< std::string > &data_rasters, const std::string &age, const std::string &lock, std::vector< std::map< std::string, std::string > > mapping=std::vector< std::map< std::string, std::string > >()) const
 
bool writeforesttheme (const Spatial::FMTforest &for_layer, const Core::FMTtheme &theme, const std::string &location, const std::map< std::string, std::string > &mapping, std::string format="GTiff") const
 
std::vector< Core::FMTGCBMtransitionwritedisturbances (const std::string &location, const Spatial::FMTspatialschedule &disturbances, const std::vector< Core::FMTaction > &actions, const std::vector< Core::FMTtheme > &themes, const int &period) const
 
std::vector< std::vector< Graph::FMTpredictor > > writepredictors (const std::string &location, const Spatial::FMTspatialschedule &spatialsolution, const std::vector< std::string > &yieldnames, const Models::FMTmodel &model, const int &period, bool periodonevalues=false, bool withGCBMid=true) const
 
std::vector< Heuristics::FMToperatingareaschemegetschemeneighbors (std::vector< Heuristics::FMToperatingareascheme > operatingareaparameters, const std::vector< Core::FMTtheme > &themes, const std::string &data_vectors, const std::string &agefield, const std::string &areafield, double agefactor=1.0, double areafactor=1, std::string lockfield="", double minimal_area=0.0, double buffersize=100) const
 
std::vector< Heuristics::FMToperatingareaclustergetclusters (const std::vector< Heuristics::FMToperatingarea > &operatingareas, const std::vector< Core::FMTtheme > &themes, const std::string &data_vectors, const std::string &agefield, const std::string &areafield, const double &maximaldistance, double agefactor=1.0, double areafactor=1, std::string lockfield="", double minimal_area=0.0, double buffersize=100) const
 
std::vector< Heuristics::FMToperatingareaschemegetOperatingArea (const std::string &fichierShp, const std::vector< Core::FMTtheme > &themes, const int &numeroTheme, const int &startingperiod, const std::string &nomChampAge, const std::string &nomChampSuperficie, const std::string &nomChampStanlock, const std::string &fichierParam) const
 
std::vector< Heuristics::FMToperatingareaschemereadOAschedulerparameters (const std::string &location, const std::vector< Core::FMTtheme > &modelthemes, const int &themetarget, const int &startingperiod) const
 
void writeOAschedulerparameters (const std::string &location, const std::vector< Heuristics::FMToperatingareascheme > &OAschemes, std::vector< std::string > creationoptions=std::vector< std::string >()) const
 
std::vector< Core::FMTactualdevelopmentreadvectors (const std::vector< Core::FMTtheme > &themes, const std::string &data_vectors, const std::string &agefield, const std::string &areafield, double agefactor=1.0, double areafactor=1, std::string lockfield="", double minimalarea=0.0) const
 
Spatial::FMTforest vectormaptoFMTforest (const std::string &data_vectors, const int &resolution, const std::vector< Core::FMTtheme > &themes, const std::string &agefield, const std::string &areafield, double agefactor=1.0, double areafactor=1, std::string lockfield="", double minimalarea=0.0, const std::string &writeforestfolder="", const bool &fittoforel=true) const
 
void vectorfieldtoraster (const std::string &data_vectors, const std::string &tifpathandname, const int &resolution, const std::string &field, bool fittoforel=true) const
 
GDALDataset * OGRlayertoRaster (OGRLayer *layer, const std::string &fieldname, const std::string &outfilename, const int &resolution, const bool &fittoforel) const
 
 FMTareaparser ()
 
 ~FMTareaparser ()=default
 
 FMTareaparser (const FMTareaparser &rhs)=default
 
FMTareaparseroperator= (const FMTareaparser &rhs)=default
 
std::vector< Core::FMTactualdevelopmentread (const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &constants, const std::string &location)
 
void write (const std::vector< Core::FMTactualdevelopment > &areas, const std::string &location) const
 
- Public Member Functions inherited from Parser::FMTparser
 FMTparser ()
 
 FMTparser (const FMTparser &rhs)
 
FMTparseroperator= (const FMTparser &rhs)
 
virtual ~FMTparser ()=default
 
std::time_t getmostrecentfiletime () const
 
void setheader (const std::string &header)
 
bool tryopening (const std::ifstream &stream, const std::string &location) const
 
bool tryopening (std::ofstream &stream, const std::string &location) const
 
bool isvalidfile (const std::string &location) const
 
bool isvalid (const std::string &line) const
 
std::vector< std::string > regexloop (const boost::regex &cutregex, std::string &str) const
 
std::vector< std::string > spliter (std::string strmask, const boost::regex &xspliter) const
 
void clearcomments (std::string &line)
 
std::string upper (const std::string &lowercases) const
 
std::string getcleanline (std::ifstream &stream)
 
std::queue< std::string > tryinclude (const std::string &line, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons)
 
std::string returninclude (const std::string &line, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons)
 
bool getforloops (std::string &line, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons, std::vector< std::string > &allvalues, std::string &target)
 
std::string getcleanlinewfor (std::ifstream &stream, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons)
 
bool isnum (std::string value) const
 
bool isnum (const std::string &value, const Core::FMTconstants &constant, bool throwerror=true) const
 
template<typename T >
getnum (const std::string &value, const Core::FMTconstants &constant, int period=0) const
 
template<typename T >
getnum (const std::string &value, bool omitnumtest=false) const
 
template<typename T >
bool tryfillnumber (T &number, const std::string &value, const Core::FMTconstants &constant, int period=0) const
 
template<typename T >
Core::FMTbounds< T > bounds (const Core::FMTconstants &constants, const std::string &value, const std::string &ope, Core::FMTsection section) const
 
GDALDataset * createOGRdataset (std::string location=std::string(), std::string gdaldrivername="CSV") const
 
OGRLayer * createlayer (GDALDataset *dataset, const std::string &name, std::vector< std::string > creationoptions=std::vector< std::string >()) const
 
std::vector< std::string > getGDALvectordrivernames (bool testcreation=true) const
 
std::vector< std::string > getGDALrasterdrivernames (bool testcreation=true) const
 
std::vector< std::vector< std::string > > getGDALvectordriverextensions (bool testcreation=true) const
 
std::vector< std::vector< std::string > > getGDALrasterdriverextensions (bool testcreation=true) const
 
- Public Member Functions inherited from Core::FMTobject
 FMTobject ()
 
virtual ~FMTobject ()
 
 FMTobject (const std::shared_ptr< Exception::FMTexceptionhandler > exhandler)
 
 FMTobject (const FMTobject &rhs)
 
FMTobjectoperator= (const FMTobject &rhs)
 
virtual void passinlogger (const std::shared_ptr< Logging::FMTlogger > &logger)
 
void passinexceptionhandler (const std::shared_ptr< Exception::FMTexceptionhandler > &exhandler)
 
void redirectlogtofile (const std::string &location)
 
virtual void setdefaultlogger ()
 
virtual void setquietlogger ()
 
virtual void settasklogger ()
 
virtual void setdebuglogger ()
 
void setdefaultexceptionhandler ()
 
void setquietexceptionhandler ()
 
void setdebugexceptionhandler ()
 
void setfreeexceptionhandler ()
 
void disablenestedexceptions ()
 
void enablenestedexceptions ()
 
void seterrorstowarnings (const std::vector< Exception::FMTexc > &errors)
 
void setmaxwarningsbeforesilenced (const size_t &maxwarningcount)
 

Additional Inherited Members

- Static Public Member Functions inherited from Core::FMTobject
static std::string getruntimelocation ()
 
static unsigned long long getavailablememory ()
 
- Static Public Attributes inherited from Parser::FMTparser
static const boost::regex rxseparator
 A regex for splitting general string.
 
- Protected Member Functions inherited from Parser::FMTparser
void setsection (const Core::FMTsection &section) const
 
std::vector< GDALDriver * > getallGDALdrivers (const char *spatialtype, bool testcreation=true) const
 
std::vector< std::vector< std::string > > getGDALextensions (const char *spatialtype, bool testcreation=true) const
 
void setcategories (GDALRasterBand *band, const std::vector< std::string > &categories) const
 
OGRCoordinateTransformation * getprojtransform (OGRLayer *baselayer, bool fittoforel=true) const
 
GDALDataset * gettransformmemlayercopy (OGRLayer *baselayer, const OGRSpatialReference *newreference, const std::string &fieldname) const
 
std::unique_ptr< OGRSpatialReference > getFORELspatialref () const
 
template<typename T >
GDALDataset * createdataset (const std::string &location, const Spatial::FMTlayer< T > &layer, const int datatypeid, std::string format="GTiff") const
 
GDALDataset * getdataset (const std::string &location) const
 
GDALDataset * getvectordataset (const std::string &location) const
 
OGRLayer * getlayer (GDALDataset *dataset, int id) const
 
GDALRasterBand * getband (GDALDataset *dataset, int bandid=1) const
 
GDALRasterBand * createband (GDALDataset *dataset, const std::vector< std::string > &categories, int bandid=1) const
 
std::vector< std::string > getcat (GDALDataset *dataset, int bandid=1) const
 
GDALRasterBand * getoverview (GDALRasterBand *band, int view=1) const
 
void getWSfields (OGRLayer *layer, std::map< int, int > &themes, int &age, int &area, int &lock, std::string agefield="", std::string areafield="", std::string lockfield="") const
 
GDALDataset * createvectormemoryds () const
 
std::array< std::string, 5 > getbaseoperators () const
 
std::vector< std::string > sameas (const std::string &allset) const
 
std::map< Core::FMTsection, std::string > getprimary (const std::string &primarylocation)
 
bool isyld (const Core::FMTyields &ylds, const std::string &value, Core::FMTsection section) const
 
bool isact (Core::FMTsection section, const std::vector< Core::FMTaction > &actions, std::string action) const
 
std::string setspecs (Core::FMTsection section, Core::FMTkwor key, const Core::FMTyields &ylds, const Core::FMTconstants &constants, std::vector< Core::FMTspec > &specs, const std::string &line)
 
std::string setspec (Core::FMTsection section, Core::FMTkwor key, const Core::FMTyields &ylds, const Core::FMTconstants &constants, Core::FMTspec &spec, const std::string &line)
 
Core::FMTsection from_extension (const std::string &ext) const
 
std::vector< std::vector< std::string > > readcsv (const std::string &location, const char &separator)
 
- Protected Member Functions inherited from Core::FMTobject
template<class Archive >
void forcesave (Archive &ar, const unsigned int version) const
 
template<class Archive >
void forceload (Archive &ar, const unsigned int version)
 
void checksignals () const
 
void setCPLhandler ()
 
- Static Protected Member Functions inherited from Core::FMTobject
static std::chrono::time_point< std::chrono::high_resolution_clock > getclock ()
 
template<class chrono >
static double getduration (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 
static std::string getdurationinseconds (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 
- Protected Attributes inherited from Parser::FMTparser
boost::recursive_mutex mtx
 Mutex for multi-threading.
 
Core::FMTsection _section
 The section in which the child class is in.
 
int _constreplacement
 Number of constant replaced by a numerical number.
 
int _line
 Line id at which the parser is reading the values.
 
std::string _comment
 Comment found in the actual line read by the parser.
 
std::string _location
 File location of the section read by the parser.
 
std::time_t mostrecentfile
 The most recent file time read by this parser.
 
- Static Protected Attributes inherited from Parser::FMTparser
static const boost::regex rxayld
 A regex for capturing age/period/yield specification.
 
static const boost::regex rxaage
 A regex for capturing age specificaiton.
 
static const boost::regex rxayldage
 A regex for capturing age or yield specification.
 
static const boost::regex rxbounds
 A regex for capturing bounds for yield or age specification.
 
static const boost::regex rxoperators
 A regex for capturing simple operators.
 
static const boost::regex rxprimary
 A regex for capturing the primary file.
 
- Static Protected Attributes inherited from Core::FMTobject
static std::shared_ptr< Exception::FMTexceptionhandler_exhandler
 A shared pointer to the exception handler.
 
static std::shared_ptr< Logging::FMTlogger_logger
 A shared pointer to the logger.
 

Detailed Description

FMTareaparser is a important parser in FMT because this parser deals with spatial stuff used in multiple FMTmodel children. If FMT is compiled without the compile proprocessor FMTWITHGDAL than alot of funcionalities of the FMTareaparser wont be available to the user. This class is also used by the FMTmodelparser.

Constructor & Destructor Documentation

◆ FMTareaparser() [1/2]

Parser::FMTareaparser::FMTareaparser ( )

Default constructor for FMTareaparser

◆ ~FMTareaparser()

Parser::FMTareaparser::~FMTareaparser ( )
default

Default destructor for FMTareaparser

◆ FMTareaparser() [2/2]

Parser::FMTareaparser::FMTareaparser ( const FMTareaparser rhs)
default

Default copy constructor for FMTareaparser

Member Function Documentation

◆ getclusters()

std::vector< Heuristics::FMToperatingareacluster > Parser::FMTareaparser::getclusters ( const std::vector< Heuristics::FMToperatingarea > &  operatingareas,
const std::vector< Core::FMTtheme > &  themes,
const std::string &  data_vectors,
const std::string &  agefield,
const std::string &  areafield,
const double &  maximaldistance,
double  agefactor = 1.0,
double  areafactor = 1,
std::string  lockfield = "",
double  minimal_area = 0.0,
double  buffersize = 100 
) const

Using a vector of operating area (operatingareaparameters), a complete vector of FMTtheme (themes), a vector file (data_vectors), the name of the age field name (agefield) an area field name (areafield), an (gefactor), an (areafactor), an optional (lockfield) name, a (minimal_area) : the minimal area parameters indicate that if a feature has an area lower than the minimal area it wont be selected. For (buffersize) see getneighborsfrompolygons function. The returned operating area clusters with their linker mask.

◆ getOperatingArea()

std::vector< Heuristics::FMToperatingareascheme > Parser::FMTareaparser::getOperatingArea ( const std::string &  fichierShp,
const std::vector< Core::FMTtheme > &  themes,
const int &  numeroTheme,
const int &  startingperiod,
const std::string &  nomChampAge,
const std::string &  nomChampSuperficie,
const std::string &  nomChampStanlock,
const std::string &  fichierParam 
) const

◆ getschemeneighbors()

std::vector< Heuristics::FMToperatingareascheme > Parser::FMTareaparser::getschemeneighbors ( std::vector< Heuristics::FMToperatingareascheme operatingareaparameters,
const std::vector< Core::FMTtheme > &  themes,
const std::string &  data_vectors,
const std::string &  agefield,
const std::string &  areafield,
double  agefactor = 1.0,
double  areafactor = 1,
std::string  lockfield = "",
double  minimal_area = 0.0,
double  buffersize = 100 
) const

Using a vector of operating area (operatingareaparameters), a complete vector of FMTtheme (themes), a vector file (data_vectors), the name of the age field name (agefield) an area field name (areafield), an (gefactor), an (areafactor), an optional (lockfield) name, a (minimal_area) : the minimal area parameters indicate that if a feature has an area lower than the minimal area it wont be selected. For (buffersize) see getneighborsfrompolygons function. The returned operating area will have theirs neighboors vector filled.

◆ OGRlayertoRaster()

GDALDataset * Parser::FMTareaparser::OGRlayertoRaster ( OGRLayer *  layer,
const std::string &  fieldname,
const std::string &  outfilename,
const int &  resolution,
const bool &  fittoforel 
) const

This function first rasterize the layer to a resolution of 20x20 in memory using gdal virtual file system. Then, the raster is reproject with the given (resolution) using (for now) only MODE as resampling. The field to rasterize (fieldname) must be of type int. If (fittoforel), the layer must be projected in ESPG32198 and will align with the Quebec FOREL rasters. –In the future, arguments will be added to change the resampling type and allow field with float type.

◆ operator=()

FMTareaparser & Parser::FMTareaparser::operator= ( const FMTareaparser rhs)
default

Default copy assignment for FMTareaparser

◆ read()

std::vector< Core::FMTactualdevelopment > Parser::FMTareaparser::read ( const std::vector< Core::FMTtheme > &  themes,
const Core::FMTconstants constants,
const std::string &  location 
)

The read function will read a regular area section (location) with a complete vector of (themes) and some (constants). It will return a vector of actualdevelopment present in the area file.

◆ readOAschedulerparameters()

std::vector< Heuristics::FMToperatingareascheme > Parser::FMTareaparser::readOAschedulerparameters ( const std::string &  location,
const std::vector< Core::FMTtheme > &  modelthemes,
const int &  themetarget,
const int &  startingperiod 
) const

Using the location for parameters file (must contain headers "OA","OPT","RET","MAXRET","REP","OPR"), the modelthemes, the themetarget corresponding to the themeid where the OA in parameters is in, and the startingperiod it return a vector of operatingareascheme, to use in operatingareascheduler.

◆ readrasters()

Spatial::FMTforest Parser::FMTareaparser::readrasters ( const std::vector< Core::FMTtheme > &  themes,
const std::vector< std::string > &  data_rasters,
const std::string &  age,
double  agefactor = 1.0,
double  areafactor = 0.0001,
std::string  lock = "" 
) const

Using a complete vector of (themes), a vector of raster files path (data_rasters) each raster represent a theme, an (age) raster file and some optional parameters (agefactor=1.0),(areafactor=0.0001) to multiply with the actualdevelopement age and area and a optional (lock) raster file. The function generates a FMTforest layer from those rasters files.

◆ readvectors()

std::vector< Core::FMTactualdevelopment > Parser::FMTareaparser::readvectors ( const std::vector< Core::FMTtheme > &  themes,
const std::string &  data_vectors,
const std::string &  agefield,
const std::string &  areafield,
double  agefactor = 1.0,
double  areafactor = 1,
std::string  lockfield = "",
double  minimalarea = 0.0 
) const

This function returns a vector of actualdevelopement present in a vector file (data_vectors) using a complete (themes) vector, an age field name (agefield), and area field name (areafield), an age factor (agefactor), and areafactor (areafactor), an optional lock field name (lockfield) and an (minimal_area) which is this minimal size a feature needs to have to be selected.

◆ vectorfieldtoraster()

void Parser::FMTareaparser::vectorfieldtoraster ( const std::string &  data_vectors,
const std::string &  tifpathandname,
const int &  resolution,
const std::string &  field,
bool  fittoforel = true 
) const

Create a raster file of a given resolution based on a the data_vectors field.

◆ vectormaptoFMTforest()

Spatial::FMTforest Parser::FMTareaparser::vectormaptoFMTforest ( const std::string &  data_vectors,
const int &  resolution,
const std::vector< Core::FMTtheme > &  themes,
const std::string &  agefield,
const std::string &  areafield,
double  agefactor = 1.0,
double  areafactor = 1,
std::string  lockfield = "",
double  minimalarea = 0.0,
const std::string &  writeforestfolder = "",
const bool &  fittoforel = true 
) const

◆ write()

void Parser::FMTareaparser::write ( const std::vector< Core::FMTactualdevelopment > &  areas,
const std::string &  location 
) const

Giving a vector of actual development (areas) and a file (location) for the area section this function is going to write a new area section usging the areas developments.

◆ writedisturbances()

std::vector< Core::FMTGCBMtransition > Parser::FMTareaparser::writedisturbances ( const std::string &  location,
const Spatial::FMTspatialschedule disturbances,
const std::vector< Core::FMTaction > &  actions,
const std::vector< Core::FMTtheme > &  themes,
const int &  period 
) const

Giving a .tif file (location) and a disturbancesstack (disturbances) the actual forest (for_layer) and the last forest layer (out_layer). a complete vector of model (themes) and a optional (mapping) for the disturbance stack layer created. The function will write all the disturbances in the locaiton .tif file and it will also returns the corresponding GCBMtransition for this planning period.

◆ writeforest()

bool Parser::FMTareaparser::writeforest ( const Spatial::FMTforest for_layer,
const std::vector< Core::FMTtheme > &  themes,
const std::vector< std::string > &  data_rasters,
const std::string &  age,
const std::string &  lock,
std::vector< std::map< std::string, std::string > >  mapping = std::vector< std::map< std::string, std::string > >() 
) const

The function will write a complete FMTforest (for_layer) using a complete vector of (themes), in multiple (data_rasters) file paths number of paths should be equal to number of themes an (age) file path and (lock) file path. The generated .tiff files can have categorical values but it needs to be specified in the mapping vector each element of the vector represent a corresponging key to write in the categorical dataset of the raster.

◆ writeforesttheme()

bool Parser::FMTareaparser::writeforesttheme ( const Spatial::FMTforest for_layer,
const Core::FMTtheme theme,
const std::string &  location,
const std::map< std::string, std::string > &  mapping,
std::string  format = "GTiff" 
) const

Write a forest theme based on a mapping for a FMTforest with a given file format in raster file.

◆ writelayer() [1/2]

bool Parser::FMTareaparser::writelayer ( const Spatial::FMTlayer< double > &  layer,
std::string  location,
std::string  format = "GTiff" 
) const

Using a layer of a given type double the function will write this (layer) into a raster file (location). the mapping add a table to the raster file when dealing with categorical variables

◆ writelayer() [2/2]

template<typename T >
bool Parser::FMTareaparser::writelayer ( const Spatial::FMTlayer< T > &  layer,
std::string  location,
const std::map< T, std::string > &  mapping,
std::string  format = "GTiff" 
) const

Using a layer of a given type T the function will write this (layer) into a raster file (location). the mapping add a table to the raster file when dealing with categorical variables

◆ writeOAschedulerparameters()

void Parser::FMTareaparser::writeOAschedulerparameters ( const std::string &  location,
const std::vector< Heuristics::FMToperatingareascheme > &  OAschemes,
std::vector< std::string >  creationoptions = std::vector< std::string >() 
) const

Write down a parameters files on the form ("OA","OPT","RET","MAXRET","REP","OPR") but the column OA is gona contains the full mask not just the selected theme into a regular csv files.

◆ writepredictors()

std::vector< std::vector< Graph::FMTpredictor > > Parser::FMTareaparser::writepredictors ( const std::string &  location,
const Spatial::FMTspatialschedule spatialsolution,
const std::vector< std::string > &  yieldnames,
const Models::FMTmodel model,
const int &  period,
bool  periodonevalues = false,
bool  withGCBMid = true 
) const

Giving a .tif file (location) and a spatialschedule (spatialsolution). a complete vector of model (yieldnames) and a yield section (yields) The function will write all the predictor id in the location .tif file and it will also returns the corresponding predictors for this planning period.


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