AbstractValidator.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20  /*!
21  \file terralib/geometry/validation/AbstractValidator.h
22 
23  \brief An abstract class to represent an algorithm that validates an geometry
24  */
25 
26 #ifndef __TERRALIB_GEOMETRY_INTERNAL_ABSTRACTVALIDATOR_H
27 #define __TERRALIB_GEOMETRY_INTERNAL_ABSTRACTVALIDATOR_H
28 
29  // TerraLib
30 #include "../Config.h"
31 
32 #include "../CommonDataStructures.h"
33 
34 #include <memory>
35 
36 namespace te
37 {
38  namespace gm
39  {
40  class Geometry;
41  class GeometryCollection;
42  class GeometryPtr;
43  class LineString;
44  class Polygon;
45 
46  /*!
47  \class AbstractValidator
48 
49  \brief An abstract class to represent an algorithm that validates an geometry
50  */
52  {
53  public:
54 
55  /*!
56  * \brief Constructor
57  */
59 
60  /*!
61  * \brief Destructor
62  */
63  virtual ~AbstractValidator() = default;
64 
65  /*!
66  * \brief Validates a geometry
67  *
68  * \param geometry The input geometry to be validate
69  *
70  * \return The valdiated result geometry
71  */
72  virtual te::gm::GeometryPtr validate(const te::gm::Geometry* geometry) const;
73 
74  /*!
75  * \brief Validates a geometry, an returns additional variable to inform if the geometry has been changed or not
76  *
77  * \param geometry The input geometry to be validate
78  * \param wasChanged output param. TRUE if the geometry has been changed. FALSE otherwise
79  *
80  * \return The valdiated result geometry
81  */
82  virtual te::gm::GeometryPtr validate(const te::gm::Geometry* geometry, bool& wasChanged) const;
83 
84  /*!
85  * \brief When appliable, sets the precision to be used in the validation
86  *
87  * \param precision When appliable, the precision to be used in the validation
88  */
89  virtual void setPrecision(double precision);
90 
91  protected:
92 
93  /*!
94  * \brief Validates a geometry collection, an returns additional variable to inform if the geometry has been changed or not
95  *
96  * \param geometry The input geometry collection to be validate
97  * \param wasChanged output param. TRUE if the geometry has been changed. FALSE otherwise
98  *
99  * \return The valdiated result geometry collection
100  */
101  virtual te::gm::GeometryPtr validateCollection(const te::gm::GeometryCollection* collection, bool& wasChanged) const;
102 
103  /*!
104  * \brief Validates a polygon, an returns additional variable to inform if the geometry has been changed or not
105  *
106  * \param geometry The input polygon to be validate
107  * \param wasChanged output param. TRUE if the geometry has been changed. FALSE otherwise
108  *
109  * \return The valdiated result polygon
110  */
111  virtual te::gm::GeometryPtr validatePolygon(const te::gm::Polygon* polygon, bool& wasChanged) const;
112 
113  /*!
114  * \brief Validates a line, an returns additional variable to inform if the geometry has been changed or not
115  *
116  * \param geometry The input line to be validate
117  * \param wasChanged output param. TRUE if the geometry has been changed. FALSE otherwise
118  *
119  * \return The valdiated result line
120  */
121  virtual te::gm::GeometryPtr validateLine(const te::gm::LineString* lineString, bool& wasChanged) const = 0;
122 
123  /*!
124  * \brief This function recreates the rings topology of a polygon, distributing the given inner rings among all the given outer rings.
125  *
126  * \param vecOuterRings A vector containing all the outer rings
127  * \param vecInnerRings A vector containing all the inner rings
128  *
129  * \return The geometry with the ring topology fixed
130  */
131  te::gm::GeometryPtr mountTopology(const te::gm::GeometryVector& vecOuterRings, const te::gm::GeometryVector& vecInnerRings) const;
132 
133  protected:
134 
135  double m_precision; //!< When appliable, the precision to be used in the validation
136  };
137 
138  //Typedef
139  class AbstractValidatorPtr : public std::unique_ptr<AbstractValidator>
140  {
141  public:
142  AbstractValidatorPtr(te::gm::AbstractValidator* validator = nullptr) : std::unique_ptr<te::gm::AbstractValidator>(validator) {};
143  };
144 
145  class AbstractValidatorSharedPtr : public std::shared_ptr<AbstractValidator>
146  {
147  public:
148  AbstractValidatorSharedPtr(te::gm::AbstractValidator* validator = nullptr) : std::shared_ptr<te::gm::AbstractValidator>(validator) {};
149  };
150 
151  } // end namespace gm
152 } // end namespace te
153 
154 #endif // __TERRALIB_GEOMETRY_INTERNAL_ABSTRACTVALIDATOR_H
AbstractValidatorPtr(te::gm::AbstractValidator *validator=nullptr)
AbstractValidatorSharedPtr(te::gm::AbstractValidator *validator=nullptr)
An abstract class to represent an algorithm that validates an geometry.
virtual ~AbstractValidator()=default
Destructor.
virtual te::gm::GeometryPtr validate(const te::gm::Geometry *geometry, bool &wasChanged) const
Validates a geometry, an returns additional variable to inform if the geometry has been changed or no...
virtual te::gm::GeometryPtr validateCollection(const te::gm::GeometryCollection *collection, bool &wasChanged) const
Validates a geometry collection, an returns additional variable to inform if the geometry has been ch...
virtual te::gm::GeometryPtr validatePolygon(const te::gm::Polygon *polygon, bool &wasChanged) const
Validates a polygon, an returns additional variable to inform if the geometry has been changed or not...
virtual te::gm::GeometryPtr validateLine(const te::gm::LineString *lineString, bool &wasChanged) const =0
Validates a line, an returns additional variable to inform if the geometry has been changed or not.
double m_precision
When appliable, the precision to be used in the validation.
virtual void setPrecision(double precision)
When appliable, sets the precision to be used in the validation.
te::gm::GeometryPtr mountTopology(const te::gm::GeometryVector &vecOuterRings, const te::gm::GeometryVector &vecInnerRings) const
This function recreates the rings topology of a polygon, distributing the given inner rings among all...
AbstractValidator()
Constructor.
virtual te::gm::GeometryPtr validate(const te::gm::Geometry *geometry) const
Validates a geometry.
It is a collection of other geometric objects.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
LineString is a curve with linear interpolation between points.
Definition: LineString.h:65
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:51
std::vector< te::gm::Geometry * > GeometryVector
TerraLib.
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76