FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTlayer.hpp
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 FMTLAYER_H_INCLUDED
9#define FMTLAYER_H_INCLUDED
10#include <memory>
11#include <map>
12#include <vector>
13#include "FMTcoordinate.hpp"
14#include "FMTobject.hpp"
15#include <boost/serialization/nvp.hpp>
17
19namespace Spatial
20 {
21 // DocString: FMTlayer
27 template <typename T>
29 {
31 // DocString: FMTlifespans::serialize
35 template<class Archive>
36 void serialize(Archive& ar, const unsigned int version)
37 {
38 ar & boost::serialization::make_nvp("FMTobject", boost::serialization::base_object<FMTobject>(*this));
39 ar & BOOST_SERIALIZATION_NVP(geotransform);
40 ar & BOOST_SERIALIZATION_NVP(maxx);
41 ar & BOOST_SERIALIZATION_NVP(maxy);
42 ar & BOOST_SERIALIZATION_NVP(SRS_WKT);
43 ar & BOOST_SERIALIZATION_NVP(cellsize);
44 ar & BOOST_SERIALIZATION_NVP(mapping);
45 }
46 protected:
47 // DocString: FMTlayer::geotransform
49 std::vector<double>geotransform;
50 // DocString: FMTlayer::maxx
52 unsigned int maxx;
53 // DocString: FMTlayer::maxy
55 unsigned int maxy;
56 // DocString: FMTlayer::SRS_WKT
58 std::string SRS_WKT;
59 // DocString: FMTlayer::cellsize
61 double cellsize;
62 // DocString: FMTlayer::mapping
64 std::map<FMTcoordinate, T>mapping;
65 public:
66 // DocString: FMTlayer::value_type
68 typedef typename std::map<FMTcoordinate,T>::value_type value_type;
69 // DocString: FMTlayer::iterator
71 typedef typename std::map<FMTcoordinate,T>::iterator iterator;
72 // DocString: FMTlayer::const_iterator
74 typedef typename std::map<FMTcoordinate,T>::const_iterator const_iterator;
75 // DocString: FMTlayer::operator[]
79 T& operator [](const FMTcoordinate& coordinate)
80 {
81 return mapping[coordinate];
82 }
83 // DocString: FMTlayer::at
87 const T& at(const FMTcoordinate& coordinate) const
88 {
89 return mapping.at(coordinate);
90 }
91 // DocString: FMTlayer::empty
95 inline bool empty() const
96 {
97 return mapping.empty();
98 }
99 // DocString: FMTlayer::begin
104 {
105 return mapping.begin();
106 }
107 // DocString: FMTlayer::begin
112 {
113 return mapping.begin();
114 }
115 // DocString: FMTlayer::end
120 {
121 return mapping.end();
122 }
123 // DocString: FMTlayer::end
128 {
129 return mapping.end();
130 }
131 // DocString: FMTlayer::find
135 const_iterator find(const FMTcoordinate& coordinate) const
136 {
137 return mapping.find(coordinate);
138 }
139 // DocString: FMTlayer::find
143 iterator find(const FMTcoordinate& coordinate)
144 {
145 return mapping.find(coordinate);
146 }
147 // DocString: FMTlayer()
152 // DocString: ~FMTlayer()
156 virtual~FMTlayer()=default;
157 // DocString: FMTlayer(FMTlayer&&)
161 FMTlayer(FMTlayer&& rhs) noexcept :
162 Core::FMTobject(std::move(rhs)),
163 geotransform(std::move(rhs.geotransform)),
164 maxx(std::move(rhs.maxx)),
165 maxy(std::move(rhs.maxy)),
166 SRS_WKT(std::move(rhs.SRS_WKT)),
167 cellsize(std::move(rhs.cellsize)),
168 mapping(std::move(rhs.mapping))
169 {
170
171 }
172 // DocString: FMTlayer(const std::vector<double>&,const unsigned int&,const unsigned int&,const std::string&,const double&)
176 FMTlayer(const std::vector<double>& lgeotransform,
177 const unsigned int& lmaxx,
178 const unsigned int& lmaxy,
179 const std::string& lSRS_WKT,
180 const double& lcellsize):Core::FMTobject(),
181 geotransform(lgeotransform),
182 maxx(lmaxx),
183 maxy(lmaxy),
184 SRS_WKT(lSRS_WKT),
185 cellsize(lcellsize),
186 mapping(){}
187 // DocString: FMTlayer(const std::map<FMTcoordinate,T>&,const std::vector<double>&,const unsigned int&,const unsigned int&,const std::string&,const double&)
191 FMTlayer(const std::map<FMTcoordinate,T>& lmapping,
192 const std::vector<double>& lgeotransform,
193 const unsigned int& lmaxx,
194 const unsigned int& lmaxy,
195 const std::string& lSRS_WKT,
196 const double& lcellsize):
197 Core::FMTobject(),
198 geotransform(lgeotransform),
199 maxx(lmaxx),
200 maxy(lmaxy),
201 SRS_WKT(lSRS_WKT),
202 cellsize(lcellsize),
203 mapping(lmapping){}
204 // DocString: FMTlayer(const FMTlayer&)
208 FMTlayer(const FMTlayer& rhs):Core::FMTobject(rhs),
210 maxx(rhs.maxx),
211 maxy(rhs.maxy),
212 SRS_WKT(rhs.SRS_WKT),
213 cellsize(rhs.cellsize),
214 mapping(rhs.mapping){}
215 // DocString: FMTlayer::operator=
220 {
221 if(this!=&rhs)
222 {
224 mapping = (rhs.mapping);
226 maxx = rhs.maxx;
227 maxy = rhs.maxy;
228 SRS_WKT = rhs.SRS_WKT;
229 cellsize = rhs.cellsize;
230 }
231 return *this;
232 }
233 // DocString: FMTlayer::swap
237 void swap(FMTlayer<T>& rhs)
238 {
239 try {
240 mapping.swap(rhs.mapping);
241 geotransform.swap(rhs.geotransform);
242 std::swap(maxx, rhs.maxx);
243 std::swap(maxy, rhs.maxy);
244 std::swap(SRS_WKT, rhs.SRS_WKT);
245 std::swap(cellsize, rhs.cellsize);
246 }catch (...)
247 {
248 _exhandler->raisefromcatch("", "FMTlayer::swap", __LINE__, __FILE__);
249 }
250 }
251
252 // DocString: FMTlayer::setextentfrom
256 void setextentfrom(const FMTlayer<T>& rhs)
257 {
258 this->geotransform = rhs.geotransform;
259 this->maxx = rhs.maxx;
260 this->maxy = rhs.maxy;
261 this->SRS_WKT = rhs.SRS_WKT;
262 this->cellsize = rhs.cellsize;
263 }
264 // DocString: FMTlayer::copyextent
268 template<typename newtype>
270
271 {
272 return FMTlayer<newtype>(std::map<FMTcoordinate,newtype>(),
273 this->geotransform,
274 this->maxx,
275 this->maxy,
276 this->SRS_WKT,
277 this->cellsize);
278 }
279 // DocString: FMTlayer::general
284 {
285 return *this;
286 }
287 // DocString: FMTlayer::GetXSize
291 unsigned int GetXSize() const
292 {
293 return maxx;
294 }
295 // DocString: FMTlayer::GetYSize
299 unsigned int GetYSize() const
300 {
301 return maxy;
302 }
303 // DocString: FMTlayer::getgeotransform
307 std::vector<double> getgeotransform() const
308 {
309 return geotransform;
310 }
311 // DocString: FMTlayer::getprojection
315 std::string getprojection() const
316 {
317 return SRS_WKT;
318 }
319 // DocString: FMTlayer::getmapping
323 std::map<FMTcoordinate,T>getmapping() const
324 {
325 return mapping;
326 }
327 // DocString: FMTlayer::area
331 double area() const
332 {
333 return (cellsize * static_cast<double>(mapping.size()));
334 }
335 // DocString: FMTlayer::getcellsize
339 double getcellsize() const
340 {
341 return cellsize;
342 }
343 // DocString: FMTlayer::getattributes
347 std::vector<T>getattributes() const
348 {
349 std::vector<T>unique_attributes;
350 for(typename std::map<FMTcoordinate,T>::const_iterator it = mapping.begin();it != mapping.end(); it++)
351 {
352 if (std::find(unique_attributes.begin(),unique_attributes.end(),it->second)==unique_attributes.end())
353 {
354 unique_attributes.push_back(it->second);
355 }
356 }
357 return unique_attributes;
358 }
359 // DocString: FMTlayer::size
363 size_t size() const
364 {
365 return mapping.size();
366 }
367 // DocString: FMTlayer::size
371 void replace(typename std::map<FMTcoordinate,T>::const_iterator first,typename std::map<FMTcoordinate,T>::const_iterator last)
372 {
373 while (first!=last)
374 {
375 typename std::map<FMTcoordinate,T>::iterator it = mapping.find(first->first);
376 if (it != last)
377 {
378 it->second = first->second;
379 }
380 ++first;
381 }
382 }
383 };
384
386 {
387 std::map<FMTcoordinate, std::string>new_mapping;
388 for (std::map<FMTcoordinate, std::string>::const_iterator mit = mapping.begin(); mit != mapping.end(); mit++)
389 {
390 std::map<FMTcoordinate, std::string>::const_iterator rhsit = rhs.mapping.find(mit->first);
391 if (rhsit != rhs.mapping.end())
392 {
393 new_mapping[mit->first] = (mit->second + "-" + rhsit->second);
394 }
395 }
396 mapping = new_mapping;
397 return *this;
398 }
399
400 }
401
402#endif // FMTLAYER_H_INCLUDED
Definition: FMTobject.hpp:50
FMTobject & operator=(const FMTobject &rhs)
static std::shared_ptr< Exception::FMTexceptionhandler > _exhandler
A shared pointer to the exception handler.
Definition: FMTobject.hpp:66
Definition: FMTcoordinate.hpp:25
Definition: FMTlayer.hpp:29
virtual ~FMTlayer()=default
std::map< FMTcoordinate, T > mapping
std::map keeping the information of each pixel.
Definition: FMTlayer.hpp:64
std::string SRS_WKT
Projection string of the raster (see GDAL for more information about Geotransform)
Definition: FMTlayer.hpp:58
size_t size() const
Definition: FMTlayer.hpp:363
double cellsize
Size of the pixel in the unit used by the map (SRS_WKT)
Definition: FMTlayer.hpp:61
iterator find(const FMTcoordinate &coordinate)
Definition: FMTlayer.hpp:143
void setextentfrom(const FMTlayer< T > &rhs)
Definition: FMTlayer.hpp:256
void replace(typename std::map< FMTcoordinate, T >::const_iterator first, typename std::map< FMTcoordinate, T >::const_iterator last)
Definition: FMTlayer.hpp:371
FMTlayer()
Definition: FMTlayer.hpp:151
void swap(FMTlayer< T > &rhs)
Definition: FMTlayer.hpp:237
FMTlayer< T > & operator+=(const FMTlayer< T > &rhs)
Definition: FMTlayer.hpp:283
std::vector< double > geotransform
Geotransform of the map (see GDAL for more information about Geotransform)
Definition: FMTlayer.hpp:49
unsigned int GetXSize() const
Definition: FMTlayer.hpp:291
const_iterator begin() const
Definition: FMTlayer.hpp:111
unsigned int GetYSize() const
Definition: FMTlayer.hpp:299
FMTlayer(const std::vector< double > &lgeotransform, const unsigned int &lmaxx, const unsigned int &lmaxy, const std::string &lSRS_WKT, const double &lcellsize)
Definition: FMTlayer.hpp:176
unsigned int maxx
Maximal x value in the map.
Definition: FMTlayer.hpp:52
const_iterator find(const FMTcoordinate &coordinate) const
Definition: FMTlayer.hpp:135
const T & at(const FMTcoordinate &coordinate) const
Definition: FMTlayer.hpp:87
FMTlayer(const std::map< FMTcoordinate, T > &lmapping, const std::vector< double > &lgeotransform, const unsigned int &lmaxx, const unsigned int &lmaxy, const std::string &lSRS_WKT, const double &lcellsize)
Definition: FMTlayer.hpp:191
std::map< FMTcoordinate, T > getmapping() const
Definition: FMTlayer.hpp:323
std::vector< T > getattributes() const
Definition: FMTlayer.hpp:347
std::map< FMTcoordinate, T >::const_iterator const_iterator
Const_Iterator typedef of the FMTlist.
Definition: FMTlayer.hpp:74
std::map< FMTcoordinate, T >::iterator iterator
Iterator typedef of the FMTlayer.
Definition: FMTlayer.hpp:71
FMTlayer(FMTlayer &&rhs) noexcept
Definition: FMTlayer.hpp:161
unsigned int maxy
Maximal y value in the map.
Definition: FMTlayer.hpp:55
FMTlayer< T > & operator=(const FMTlayer< T > &rhs)
Definition: FMTlayer.hpp:219
FMTlayer< newtype > copyextent() const
Definition: FMTlayer.hpp:269
T & operator[](const FMTcoordinate &coordinate)
Definition: FMTlayer.hpp:79
std::vector< double > getgeotransform() const
Definition: FMTlayer.hpp:307
iterator end()
Definition: FMTlayer.hpp:119
friend class boost::serialization::access
Definition: FMTlayer.hpp:30
const_iterator end() const
Definition: FMTlayer.hpp:127
std::map< FMTcoordinate, T >::value_type value_type
Value typedef of the FMTlayer.
Definition: FMTlayer.hpp:68
iterator begin()
Definition: FMTlayer.hpp:103
std::string getprojection() const
Definition: FMTlayer.hpp:315
FMTlayer(const FMTlayer &rhs)
Definition: FMTlayer.hpp:208
double area() const
Definition: FMTlayer.hpp:331
bool empty() const
Definition: FMTlayer.hpp:95
double getcellsize() const
Definition: FMTlayer.hpp:339
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTaction.hpp:31
The spatial namespace provides classes for spatialy explicit simulation/optimization based on raster ...
Definition: FMTareaparser.hpp:36