Validation.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.h
22 
23  \brief A list of Validation functions for the Geometry Module.
24 */
25 
26 #ifndef __TERRALIB_GEOMETRY_INTERNAL_VALIDATION_H
27 #define __TERRALIB_GEOMETRY_INTERNAL_VALIDATION_H
28 
29 // TerraLib
30 #include "Config.h"
31 
32 #include "Coord2D.h"
33 
34 // STL
35 #include <map>
36 #include <string>
37 #include <vector>
38 
39 namespace te
40 {
41  namespace gm
42  {
43 // Forward declarations
44  class Geometry;
45  class GeometryPtr;
46  class LineString;
47 
48  /*!
49  \struct TopologyValidationError
50 
51  \brief This struct contains informations about GEOS TopologyValidationError
52  */
54  {
55  public:
56 
58  std::string m_message;
59  };
60 
62  {
63  public:
64 
65  /*!
66  \brief It check geometry validity using GEOS.
67 
68  \param geom Geometry that will be verified.
69  \param error TopologyValidationError struct.
70 
71  \return True if geometry is valid.
72  */
73  static bool CheckValidity(const Geometry* geom, te::gm::TopologyValidationError& error);
74 
75  /*!
76  \brief Get/create a valid version of the geometry given. If the geometry is a polygon or multi polygon, self intersections /
77  inconsistencies are fixed. Otherwise the geometry is returned.
78 
79  \param geom
80  \return a geometry
81 
82  \note: https://stackoverflow.com/questions/31473553/is-there-a-way-to-convert-a-self-intersecting-polygon-to-a-multipolygon-in-jts
83  */
84  static te::gm::Geometry* Validate(te::gm::Geometry* geom);
85 
86  /*!
87  \brief Apply several fixes to a geometry to ensure that it will be made valid.
88 
89  \description It applies the following fixes:
90  1 - Removes all the repeated consecutive coordidates
91  2 - Add perpendicular points that are within the tolerance to each analysed segment
92  3 - We snap the coordinates to ensure that any "similar" coordinate is now equal
93  4 - To avoid the discard of rings in geos polygonize function, we must ensure that we removed all the collapsed segments
94  5 - Finally we applies a polygonizer to recreate the geometry and ensure that it is now consistent
95 
96  \param geom Geometry that will be verified.
97 
98  \return True if geometry is valid.
99  */
100  static te::gm::GeometryPtr MakeValid(const te::gm::Geometry* geometry);
101 
102  static te::gm::GeometryPtr MakeValid(const te::gm::Geometry* geometry, std::string& errorMessage);
103  };
104 
105  } // end namespace gm
106 } // end namespace te
107 
108 #endif // __TERRALIB_GEOMETRY_INTERNAL_VALIDATION_H
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76
TerraLib.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:77
Configuration flags for the Vector Geometry Model of TerraLib.
This struct contains informations about GEOS TopologyValidationError.
Definition: Validation.h:53
An utility struct for representing 2D coordinates.