FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTAreaParser.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Québec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifndef FMTareaparser_Hm_included
9#define FMTareaparser_Hm_included
10
11#include "FMTParser.h"
12#include <iterator>
13#include <map>
14#include <string>
15#include <vector>
16#include "FMTutility.h"
17#include <boost/regex.hpp>
18
19
20class OGRGeometryCollection;
21class OGRFeature;
22class OGRGeometry;
23class OGRMultiPolygon;
24
25namespace Core
26{
27 class FMTDevelopment;
28 class FMTActualDevelopment;
29 class FMTGCBMTransition;
30 class FMTMask;
31 template<typename T>
32 class FMTList;
33}
34namespace Graph
35{
36 class FMTPredictor;
37}
38
39namespace Spatial
40{
41 class FMTForest;
43 class FMTSaSolution;
44}
45
46namespace Heuristics
47{
50 class FMTOperatingArea;
51}
52
53namespace Models
54{
55 class FMTModel;
56}
57
58
59namespace Parser
60{
61// DocString: FMTAreaParser
67 {
68 public:
69#ifdef FMTWITHGDAL
70 // DocString: FMTAreaParser::readRasters
81 Spatial::FMTForest readRasters(const std::vector<Core::FMTTheme>& themes, const std::vector<std::string>& data_rasters,
82 const std::string& age, double agefactor = 1.0, double areafactor = 0.0001, std::string lock = "") const;
83 // DocString: FMTAreaParser::writeLayer
93 template<typename T>
94 bool writeLayer(const Spatial::FMTLayer<T>& layer, std::string location, const std::map<T, std::string>& mapping, std::string format = "GTiff") const;
95 // DocString: FMTAreaParser::writeLayer
103 bool writeLayer(const Spatial::FMTLayer<double>& layer, std::string location, std::string format = "GTiff") const;
104 // DocString: FMTAreaParser::writeForest
115 bool writeForest(const Spatial::FMTForest& for_layer,
116 const std::vector<Core::FMTTheme>& themes,
117 const std::vector<std::string>& data_rasters,
118 const std::string& age,
119 const std::string& lock,
120 std::vector<std::map<std::string, std::string>> mapping = std::vector<std::map<std::string, std::string>>()) const;
121 // DocString: FMTAreaParser::writeForest
130 bool writeForest(const Spatial::FMTForest& p_for_layer,
131 const std::vector<Core::FMTTheme>& p_themes,
132 const std::string& p_folder,
133 std::vector<std::map<std::string, std::string>> p_mapping = std::vector<std::map<std::string, std::string>>()) const;
134 // DocString: FMTAreaParser::writeForestTheme
145 const Spatial::FMTForest& for_layer,
146 const Core::FMTTheme& theme,
147 const std::string& location,
148 const std::map<std::string, std::string>& mapping,
149 std::string format = "GTiff") const;
150 // DocString: FMTAreaParser::writeDisturbances
160 std::vector<Core::FMTGCBMTransition> writeDisturbances(const std::string& location,
161 const Spatial::FMTSpatialSchedule& disturbances,
162 const std::vector<Core::FMTAction>& actions,
163 const std::vector<Core::FMTTheme>& themes,
164 const int& period) const;
165 // DocString: FMTAreaParser::writePredictors()
177 std::vector<std::vector<Graph::FMTPredictor>> writePredictors(const std::string& location,
178 const Spatial::FMTSpatialSchedule& spatialsolution,
179 const std::vector<std::string>& yieldnames,
180 const Models::FMTModel& model,
181 const int& period,
182 bool periodonevalues = false,
183 bool withGCBMid = true) const;
184 // DocString: FMTAreaParser::writeSaSolution
188 /*bool writeSaSolution(const std::string location,
189 const Spatial::FMTSaSolution& solution,
190 const std::vector<Core::FMTTheme>& themes,
191 const std::vector<Core::FMTAction>& actions,
192 const bool& writeevents = true,
193 int periodStart=-1,
194 int periodStop=-1) const;*/
195 #ifdef FMTWITHOSI
196 // DocString: FMTAreaParser::getSchemeNeighbors
211 std::vector<Heuristics::FMTOperatingAreaScheme> getSchemeNeighbors(std::vector<Heuristics::FMTOperatingAreaScheme> operatingareaparameters,
212 const std::vector<Core::FMTTheme>& themes, const std::string& data_vectors,
213 const std::string& agefield, const std::string& areafield, double agefactor = 1.0,
214 double areafactor = 1, std::string lockfield = "",
215 double minimal_area = 0.0, double buffersize = 100) const;
216 // DocString: FMTAreaParser::getClusters
232 std::vector<Heuristics::FMTOperatingAreaCluster> getClusters(const std::vector<Heuristics::FMTOperatingArea>& operatingareas,
233 const std::vector<Core::FMTTheme>& themes, const std::string& data_vectors,
234 const std::string& agefield, const std::string& areafield, const double& maximaldistance,
235 double agefactor = 1.0, double areafactor = 1, std::string lockfield = "",
236 double minimal_area = 0.0, double buffersize = 100) const;
237 // DocString: FMTAreaParser::getOperatingArea
250 std::vector<Heuristics::FMTOperatingAreaScheme> 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;
251 // DocString: FMTAreaParser::readOaSchedulerParameters
260 std::vector<Heuristics::FMTOperatingAreaScheme> readOaSchedulerParameters(const std::string& location, const std::vector<Core::FMTTheme>& modelthemes, const int& themetarget, const int& startingperiod) const;
261 // DocString: FMTAreaParser::writeOaSchedulerParameters
268 void writeOaSchedulerParameters(const std::string& location, const std::vector<Heuristics::FMTOperatingAreaScheme>& OAschemes,
269 std::vector<std::string> creationoptions = std::vector<std::string>()) const;
270#endif
271 // DocString: FMTAreaParser::readVectors
284 std::vector<Core::FMTActualDevelopment>readVectors(const std::vector<Core::FMTTheme>& themes, const std::string& data_vectors,
285 const std::string& agefield, const std::string& areafield, double agefactor = 1.0,
286 double areafactor = 1, std::string lockfield = "",
287 double minimalarea = 0.0) const;
288 // DocString: FMTAreaParser::vectormaptoFMTforest
304 Spatial::FMTForest vectormaptoFMTforest(const std::string& data_vectors,
305 const int& resolution, const std::vector<Core::FMTTheme>& themes,
306 const std::string& agefield, const std::string& areafield, double agefactor = 1.0,
307 double areafactor = 1, std::string lockfield = "",
308 double minimalarea = 0.0, const std::string& writeforestfolder = "",
309 const bool& fittoforel = true) const;
310 // DocString: FMTAreaParser::vectormaptoFMTforest
319 void vectorFieldToRaster(const std::string& data_vectors,
320 const std::string& tifpathandname,
321 const int& resolution,
322 const std::string& field,
323 bool fittoforel = true) const;
324 // DocString: FMTAreaParser::ogrLayerToRaster
334 GDALDataset* ogrLayerToRaster(OGRLayer* layer, const std::string& fieldname, const std::string& outfilename, const int& resolution, const bool& fittoforel) const;
335
336 // DocString: FMTAreaParser::writeForestExtended
345 void writeForestExtended(Spatial::FMTForest& p_forest,const std::string& p_VectorFile,
346 const std::vector<Core::FMTTheme> p_themes,
347 const std::vector<Core::FMTActualDevelopment>& p_area,
348 const std::string& p_folder) const;
349
350#endif
351 // DocString: FMTAreaParser()
356 // DocString: ~FMTAreaParser()
360 ~FMTAreaParser() = default;
361 // DocString: FMTAreaParser(const FMTAreaParser&)
366 FMTAreaParser(const FMTAreaParser& rhs) = default;
367 // DocString: FMTAreaParser::operator=
373 FMTAreaParser& operator = (const FMTAreaParser& rhs) = default;
374 // DocString: FMTAreaParser::read
382 std::vector<Core::FMTActualDevelopment>read(const std::vector<Core::FMTTheme>& themes, const Core::FMTConstants& constants, const std::string& location);
383 // DocString: FMTAreaParser::write
389 void write(const std::vector<Core::FMTActualDevelopment>& areas, const std::string& location) const;
390 private:
391 // DocString: FMTAreaParser::m_rxcleanarea
393 const static boost::regex m_rxcleanarea;
394 // DocString: FMTAreaParser::m_RxExclude
396 const static boost::regex m_RxExclude;
397 // DocString: FMTAreaParser::m_RxExcludeSpec
399 const static boost::regex m_RxExcludeSpec;
400 // DocString: FMTAreaParser::_isExclude
406 bool _isExclude(const std::string& pm_line) const;
407 // DocString: FMTAreaParser::_getExcludeValue
413 std::string _getExcludeValue(const std::string& pm_line) const;
414 // DocString: FMTAreaParser::_getExcludedSpec
422 std::pair<Core::FMTMask, Core::FMTSpec> _getExcludedSpec(const std::vector<Core::FMTTheme>& p_themes,
423 const Core::FMTConstants& p_constants,
424 const std::string& p_value) const;
425 // DocString: FMTAreaParser::_gotNewExclude
434 bool _gotNewExclude(const std::vector<Core::FMTTheme>& p_themes,
435 const Core::FMTConstants& p_constants,
436 const std::string& p_value,
437 Core::FMTList<Core::FMTSpec>& p_list) const;
438 // DocString: FMTAreaParser::_getPeriodPathName
446 std::string _getPeriodPathName(const std::string& location, const int& period,const std::string& name) const;
447 // DocString: FMTAreaParser::_getGCBMtransitions
456 std::vector<Core::FMTGCBMTransition> _getGCBMtransitions(const Spatial::FMTLayer<std::string>& stacked_actions,
457 const Spatial::FMTLayer<int>& ages,
458 const Spatial::FMTForest& newfor,
459 const std::vector<Core::FMTTheme>& themes) const;
460 #ifdef FMTWITHGDAL
461 // DocString: FMTAreaParser::_writeBand
471 template<typename T,typename outT>
472 bool _writeBand(const Spatial::FMTLayer<T>& layer, GDALRasterBand* wband, const std::map<T, std::string>& mapping) const;
473 // DocString: FMTAreaParser::_getUnion
486 std::vector<OGRGeometry*> _getUnion(const std::vector<OGRMultiPolygon>& p_collections) const;
487 // DocString: FMTareaparser::_destroyGeometries
497 void _destroyGeometries(std::vector<OGRGeometry*>& p_geometires) const;
498 // DocString: FMTAreaParser::getFeatureToDevelopment
512 Core::FMTActualDevelopment _getFeatureToDevelopment(const OGRFeature* feature,
513 const std::vector<Core::FMTTheme>& themes,
514 const std::map<int, int>& themes_fields,
515 const int& age_field,
516 const int& lock_field,
517 const int& area_field,
518 const double& agefactor,
519 const double& areafactor,
520 const double& minimalarea) const;
521 // DocString: FMTAreaParser::_validateRaster
526 void _validateRaster(const std::vector<std::string>&data_rasters) const;
527 // DocString: FMTAreaParser::_openVectorFile
541 GDALDataset* _openVectorFile(std::map<int, int>&themes_fields, int& age_field, int& lock_field, int& area_field,
542 const std::string& data_vectors, const std::string& agefield, const std::string& areafield, const std::string& lockfield,
543 const std::vector<Core::FMTTheme>& themes) const;
544 #ifdef FMTWITHOSI
545 // DocString: FMTareaparser::_getMultiPolygons
564 std::vector<OGRMultiPolygon> _getMultiPolygons(const std::vector<Heuristics::FMTOperatingArea>& operatingareas,
565 const std::vector<Core::FMTTheme>& themes, const std::string& data_vectors,
566 const std::string& agefield, const std::string& areafield, double agefactor = 1.0,
567 double areafactor = 1, std::string lockfield = "",
568 double minimal_area = 0.0) const;
569 // DocString: FMTareaparser::_getNeighborsFromPolygons
585 std::vector<Heuristics::FMTOperatingArea> _getNeighborsFromPolygons(const std::vector<OGRGeometry*>& polygons,
586 std::vector<Heuristics::FMTOperatingArea> operatingareas,
587 const double& buffersize) const;
588
589 // DocString: FMTAreaParser::_getClustersFromPolygons
597 std::vector<Heuristics::FMTOperatingAreaCluster> _getClustersFromPolygons(const std::vector<OGRGeometry*>&polygons,
598 const std::vector<Heuristics::FMTOperatingArea>& operatingareas,const double& maximaldistance) const;
599 // DocString: FMTAreaParser::_isMapWithSameThemes
606 bool _isMapWithSameThemes(const std::vector<Core::FMTTheme>& p_themes,
607 const std::string& p_VectorsMap) const;
608 // DocString: FMTareaparser::_GetGeometryArea
615 static double _GetGeometryArea(const OGRGeometry* p_geometry);
616 #endif
617 // DocString: FMTAreaParser::_getFMTforestfromlayer
628 Spatial::FMTForest _getFMTforestfromlayer(OGRLayer* layer,const std::vector<Core::FMTActualDevelopment>& actualdevs, const std::string& devidfield, const int& resolution, const double& areafactor,const bool& fittoforel) const;
629 // DocString: FMTAreaParser::_subsetLayer
638 OGRLayer* _subsetLayer(OGRLayer*layer, const std::vector<Core::FMTTheme>& themes,
639 const std::string& agefield, const std::string& areafield) const;
640 #endif
641
642 };
643}
644#endif // FMTareaparser_Hm_included
645
#define FMTEXPORT
Definition: FMTutility.h:125
Child class of FMTDevelopment representing an actual forest stand, holding the area of the stand.
Definition: FMTActualDevelopment.h:24
Class holding the constants defined in the constants section of a model, used by the parsers.
Definition: FMTConstants.h:28
Definition: FMTAreaParser.h:32
Class holding the attributes and aggregates of a single theme, describing a part of a FMTMask.
Definition: FMTTheme.h:47
Predictor gathering the source and target ages, yields, distances and disturbances of a graph transit...
Definition: FMTPredictor.h:33
Potential cluster of multiple operating areas.
Definition: FMTOperatingAreaCluster.h:27
Operating area scheme giving information about its opening time, green up and return time.
Definition: FMTOperatingAreaScheme.h:42
Operating area giving information about its mask, neighbors and neighbors perimeter.
Definition: FMTOperatingArea.h:29
Base class for the different models in FMT.
Definition: FMTModel.h:62
Parser dealing with the spatial aspects used in multiple FMTModel children, reading and writing the a...
Definition: FMTAreaParser.h:67
bool writeLayer(const Spatial::FMTLayer< T > &layer, std::string location, const std::map< T, std::string > &mapping, std::string format="GTiff") const
Write a layer into a raster file, with a mapping for categorical variables.
bool writeForest(const Spatial::FMTForest &p_for_layer, const std::vector< Core::FMTTheme > &p_themes, const std::string &p_folder, std::vector< std::map< std::string, std::string > > p_mapping=std::vector< std::map< std::string, std::string > >()) const
Write a forest into a folder.
bool writeLayer(const Spatial::FMTLayer< double > &layer, std::string location, std::string format="GTiff") const
Write a double layer into a raster file.
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
Write the predictor ids into a raster file and return the corresponding predictors for the period.
std::vector< Heuristics::FMTOperatingAreaScheme > 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
Return the operating area schemes with their neighbors filled from a vector file.
std::vector< Core::FMTActualDevelopment > 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
Return the actual developments present in a vector file.
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
Rasterize a vector file and return the corresponding forest.
GDALDataset * ogrLayerToRaster(OGRLayer *layer, const std::string &fieldname, const std::string &outfilename, const int &resolution, const bool &fittoforel) const
Rasterize a layer to 20x20 in memory then reproject it to the given resolution using MODE resampling.
std::vector< Heuristics::FMTOperatingAreaScheme > readOaSchedulerParameters(const std::string &location, const std::vector< Core::FMTTheme > &modelthemes, const int &themetarget, const int &startingperiod) const
Return the operating area schemes from a parameters file, for use in the operating area scheduler.
void writeForestExtended(Spatial::FMTForest &p_forest, const std::string &p_VectorFile, const std::vector< Core::FMTTheme > p_themes, const std::vector< Core::FMTActualDevelopment > &p_area, const std::string &p_folder) const
Write an extended forest to a folder using a vector file.
~FMTAreaParser()=default
Default destructor for FMTAreaParser.
void writeOaSchedulerParameters(const std::string &location, const std::vector< Heuristics::FMTOperatingAreaScheme > &OAschemes, std::vector< std::string > creationoptions=std::vector< std::string >()) const
Write a parameters file with the full mask in the OA column into a csv file.
std::vector< Core::FMTGCBMTransition > 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
Write the disturbances into a raster file and return the corresponding GCBM transitions for the perio...
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
Write a forest theme into a raster file using a mapping.
FMTAreaParser(const FMTAreaParser &rhs)=default
Copy constructor for FMTAreaParser.
void 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 from a vector file field.
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
Write a forest into multiple raster files.
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
Generate a FMTForest layer from raster files.
std::vector< Heuristics::FMTOperatingAreaScheme > 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
Return the operating area schemes from a shapefile.
std::vector< Heuristics::FMTOperatingAreaCluster > 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
Return the operating area clusters with their linker mask from a vector file.
FMTAreaParser()
Default constructor for FMTAreaParser.
std::vector< Core::FMTActualDevelopment > read(const std::vector< Core::FMTTheme > &themes, const Core::FMTConstants &constants, const std::string &location)
Read a regular area section and return the actual developments.
void write(const std::vector< Core::FMTActualDevelopment > &areas, const std::string &location) const
Write an area section from a vector of actual developments.
Main parent class of all the parsers in FMT.
Definition: FMTParser.h:72
Spatially referenced layer of Core::FMTDevelopment representing the forest.
Definition: FMTForest.h:33
Definition: FMTParser.h:54
Map containing a line graph for each cell, representing the stand, the action and the transition at e...
Definition: FMTSpatialSchedule.h:50
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
Definition: FMTAreaParser.h:35
Namespace regrouping all tools for solving LP/MIP problems using an heuristic.
Definition: FMTAreaParser.h:47
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTAreaParser.h:54
Namespace handling all FMT's parsers. Everything related to I/O should be located in this namespace.
Definition: FMTActionParser.h:27
Definition: FMTAreaParser.h:40