FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTCoordinate.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 FMTCOORD_Hm_included
9#define FMTCOORD_Hm_included
10
11#include <memory>
12#include <boost/unordered_map.hpp>
13#include <vector>
14#include <array>
15#include <boost/serialization/serialization.hpp>
16#include <boost/serialization/nvp.hpp>
17#include <boost/serialization/array.hpp>
18#include <string>
19#include <set>
20#include "FMTException.h"
21
22namespace Spatial
23 {
24 // DocString: FMTCoordinate
29 {
30 public:
31 // DocString: FMTCoordinate()
36 // DocString: ~FMTCoordinate()
40 ~FMTCoordinate() = default;
41 // DocString: FMTCoordinate(uint16_t, uint16_t)
47 FMTCoordinate(uint16_t p_x, uint16_t p_y);
48 // DocString: FMTCoordinate(const FMTCoordinate&)
54 // DocString: FMTCoordinate::at
60 FMTCoordinate at(unsigned int id) const;
61 // DocString: FMTCoordinate::distance
67 double distance(const FMTCoordinate& coord) const;
68 // DocString: FMTCoordinate::within
76 template<typename T>
77 bool within(const T& ldistance, const FMTCoordinate& coord) const;
78 // DocString: FMTCoordinate::upEnveloppe
83 void upEnveloppe(std::array<FMTCoordinate, 4>& enveloppe) const;
84 // DocString: FMTCoordinate::hash
89 size_t hash() const;
90 // DocString: FMTCoordinate::operator=
96 FMTCoordinate& operator = (const FMTCoordinate& rhs);
97 // DocString: FMTCoordinate::getSpatialCoordinate
103 const std::vector<double> getSpatialCoordinate(std::vector<double> geoTransform) const;
104 // DocString: FMTCoordinate::operator==
110 bool operator == (const FMTCoordinate& rhs) const;
111 // DocString: FMTCoordinate::operator<
117 bool operator < (const FMTCoordinate& rhs) const;
118 // DocString: FMTCoordinate::closest
125 std::set<FMTCoordinate>::const_iterator closest(const std::vector<std::set<FMTCoordinate>::const_iterator>& coordinates, double& approximation) const;
126 // DocString: FMTCoordinate::operator std::string
131 operator std::string() const;
132 // DocString: FMTCoordinate::getNeighbors
139 std::set<FMTCoordinate> getNeighbors(const uint16_t& nsize, const bool& circle = false) const;
140 // DocString: FMTCoordinate::getAverageCentroid
146 static FMTCoordinate getAverageCentroid(const std::array<FMTCoordinate, 4>& p_enveloppe);
147 // DocString: FMTCoordinate::getTerritory
154 static std::set<FMTCoordinate> getTerritory(const std::array<FMTCoordinate, 4>& p_enveloppe, const size_t& p_distance);
155 // DocString: FMTCoordinate::getHeight
161 static size_t getHeight(const std::array<FMTCoordinate, 4>& p_enveloppe);
162 // DocString: FMTCoordinate::getWidth
168 static size_t getWidth(const std::array<FMTCoordinate, 4>& p_enveloppe);
169 // DocString: FMTCoordinate::getX
174 uint16_t getX() const;
175 // DocString: FMTCoordinate::getY
180 uint16_t getY() const;
181 private:
182 friend class boost::serialization::access;
183 //unsigned int x,y;
184 uint16_t m_x;
185 uint16_t m_y;
186 // DocString: FMTCoordinate::serialize
193 template<class Archive>
194 void serialize(Archive& ar, const unsigned int version)
195 {
196 ar & BOOST_SERIALIZATION_NVP(m_x);
197 ar & BOOST_SERIALIZATION_NVP(m_y);
198 }
199 // DocString: FMTCoordinate::_getXyGap
206 void _getXyGap(const FMTCoordinate& rhs, int& xgap, int& y_gap) const;
207 // DocString: FMTCoordinate::_distanceApproximation
213 double _distanceApproximation(const FMTCoordinate& coord) const;
214
215 };
216 }
217
218namespace boost {
219
220 template <>
221 struct hash<Spatial::FMTCoordinate>
222 {
223 std::size_t operator()(const Spatial::FMTCoordinate& p_coord) const
224 {
225 //unsigned int x = coord.getX();
226 //unsigned int y = coord.getY();
227 //return (boost::hash<unsigned int>()(x) && hash<unsigned int>()(y));
228 return p_coord.hash();
229 }
230 };
231
232}
233
234#endif // FMTCOORD_Hm_included
#define FMTEXPORT
Definition: FMTutility.h:125
Spatially referenced coordinate holding an x and y position on a raster grid.
Definition: FMTCoordinate.h:29
const std::vector< double > getSpatialCoordinate(std::vector< double > geoTransform) const
Return the spatial coordinate using a geographic transform.
static size_t getWidth(const std::array< FMTCoordinate, 4 > &p_enveloppe)
Return the width of an envelope.
double distance(const FMTCoordinate &coord) const
Return the distance to another coordinate.
FMTCoordinate()
Default constructor for FMTCoordinate.
bool within(const T &ldistance, const FMTCoordinate &coord) const
Return true if another coordinate is within a given distance.
FMTCoordinate at(unsigned int id) const
Return the coordinate at a given index.
void upEnveloppe(std::array< FMTCoordinate, 4 > &enveloppe) const
Update the bounding envelope with this coordinate.
static std::set< FMTCoordinate > getTerritory(const std::array< FMTCoordinate, 4 > &p_enveloppe, const size_t &p_distance)
Return the coordinates of a territory within a distance of an envelope.
FMTCoordinate(const FMTCoordinate &rhs)
Copy constructor for FMTCoordinate.
~FMTCoordinate()=default
Default destructor for FMTCoordinate.
size_t hash() const
Return the hash of the coordinate.
uint16_t getY() const
Return the y position of the coordinate.
std::set< FMTCoordinate >::const_iterator closest(const std::vector< std::set< FMTCoordinate >::const_iterator > &coordinates, double &approximation) const
Return the closest coordinate among the given coordinates.
static FMTCoordinate getAverageCentroid(const std::array< FMTCoordinate, 4 > &p_enveloppe)
Return the average centroid of an envelope.
std::set< FMTCoordinate > getNeighbors(const uint16_t &nsize, const bool &circle=false) const
Return the neighboring coordinates within a given size.
static size_t getHeight(const std::array< FMTCoordinate, 4 > &p_enveloppe)
Return the height of an envelope.
FMTCoordinate(uint16_t p_x, uint16_t p_y)
Construct a FMTCoordinate from an x and y position.
uint16_t getX() const
Return the x position of the coordinate.
Definition: FMTAreaParser.h:40
Definition: FMTAction.h:463
std::size_t operator()(const Spatial::FMTCoordinate &p_coord) const
Definition: FMTCoordinate.h:223