PolygonSubdivider.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 PolygonSubdivider.h
22 
23  \brief Algorithm to subdivide polygons based on a cell tilling and merge them back to their original format
24 
25  \ingroup vp
26  */
27 
28 #ifndef __TERRALIB_VP_INTERNAL_POLYGONSUBDIVIDER_H
29 #define __TERRALIB_VP_INTERNAL_POLYGONSUBDIVIDER_H
30 
31 // Terralib
32 #include "Config.h"
33 
34 #include "../geometry/CommonDataStructures.h"
35 #include "../geometry/Enums.h"
36 #include "CommonDataStructures.h"
37 
38 //STL include files
39 #include <map>
40 #include <memory>
41 #include <set>
42 #include <vector>
43 
44 namespace te
45 {
46  namespace gm
47  {
48  class Envelope;
49  class LineString;
50  }
51 
52  namespace vp
53  {
54  class SubdividerTilling;
55 
56  /*!
57  \class PolygonSubdivider
58 
59  \brief Algorithm to subdivide polygons based on a cell tilling and merge them back to their original format
60  */
62  {
63  public:
64 
65  using SetIndexes = std::set<std::size_t>;
66  using GeometryAssociation = std::pair<std::size_t, std::size_t>;
67  using GeometryAssociations = std::vector<GeometryAssociation>;
68  using ClusterIndexes = std::vector<std::size_t>;
69  using Clusters = std::vector<ClusterIndexes>;
70 
71  /*!
72  * \brief Subdivides the given geometry using the given envelope. This has the same result as an intersection operation, but uses an optimized algorithm which considers an envelope
73  *
74  * \param geometry The input geometry to be clipped
75  * \param envelope The envelope to be used as clipping area
76  *
77  * \return A geometry vector containing the clipping result
78  */
79  static te::gm::GeometryVector subdivide(const te::gm::Geometry* geometry, std::size_t maxCoordinates);
80 
81  /*!
82  * \brief Subdivides the given geometry using the given envelope. This has the same result as an intersection operation, but uses an optimized algorithm which considers an envelope
83  *
84  * \param geometry The input geometry to be clipped
85  * \param envelope The envelope to be used as clipping area
86  *
87  * \return A geometry vector containing the clipping result
88  */
89  static te::gm::GeometryVector subdivide(const te::gm::Geometry* geometry, const te::gm::Envelope& envelope, std::size_t maxCoordinates);
90 
91  /*!
92  * \brief Subdivides the given geometry using the given envelope. This has the same result as an intersection operation, but uses an optimized algorithm which considers an envelope
93  *
94  * \param geometry The input geometry to be clipped
95  * \param envelope The envelope to be used as clipping area
96  *
97  * \return A geometry vector containing the clipping result
98  */
99  static te::gm::GeometryVector subdivide(const te::gm::Geometry* geometry, const SubdividerTilling& tilling, std::size_t maxCoordinates);
100 
101  /*!
102  * \brief Subdivides the given vecInputGeometries using the given envelope. This has the same result as an intersection operation, but uses an optimized algorithm which considers an envelope
103  *
104  * \param vecInputGeometries The input geometries to be clipped
105  * \param envelope The envelope to be used as clipping area
106  *
107  * \return A geometry vector containing the clipping result
108  */
109  static te::gm::GeometryVector subdivide(const te::gm::GeometryVector& vecInputGeometries, std::size_t maxCoordinates, std::vector<std::size_t>& vecParentIndexes);
110  static te::gm::GeometryVector subdivide(const te::gm::GeometryVector& vecInputGeometries, const te::gm::Envelope& envelope, std::size_t maxCoordinates);
111 
112  /*!
113  * \brief Subdivides the given vecInputGeometries using the given envelope. This has the same result as an intersection operation, but uses an optimized algorithm which considers an envelope
114  *
115  * \param vecInputGeometries The input geometries to be clipped
116  * \param envelope The envelope to be used as clipping area
117  *
118  * \return A geometry vector containing the clipping result
119  */
120  static te::gm::GeometryVector subdivide(const te::gm::GeometryVector& vecInputGeometries, const SubdividerTilling& tilling, std::size_t maxCoordinates);
121 
122  /*!
123  * \brief Creates a normalized match map containing only the indexes of geometries that have a border relation to each other. This analysis is recursive
124  *
125  * \param vecFragments The vector containing the geometry fragments to be analysed
126  * \param splitLine The referente split line where the geomtry fragments must be analysed
127  *
128  * \return The normalized match map containing only the indexes of geometries that have a border relation to each other
129  */
131 
132  /*!
133  * \brief Normalizes an match map ensuring that all the list of indexes is complete, that is, the list will containg the indexes of all fragments that have borders with the key index
134  *
135  * \param geometryMatchMap The match map to be normalized
136  */
137  static Clusters calculateGeometryClusters(const GeometryAssociations& geometryMatchMap);
138 
139  /*!
140  * \brief Creates a non-normalized match map containing only the indexes of geometries that have a border relation to each other. This analysis is not recursive
141  *
142  * \param vecBorderSegments The vector containing the border segments to be analysed
143  *
144  * \return The non-normalized match map containing only the indexes of geometries that have a border relation to each other
145  */
146  static GeometryAssociations calculateGeometryAssociations(const std::vector<te::vp::SegmentInfo*>& vecBorderSegments, te::gm::Dimensionality dimensionality);
147 
148  /*!
149  * \brief From the givem geometry, creates a list of all the segments that are exactly in the border of the given split reference line. It also returns the indexes of the geometries that doesnt overlap the given split reference line
150  *
151  * \param geometry The geometry to be analysed
152  * \param geometryIndex The index of the geometry
153  * \param splitLine The referente split line where the geomtry fragments must be analysed
154  * \param vecSegmentsInBorder (Return parameter) A vector containing all the segments in the border of the given split reference line. f the vector is empty, the given geometry does not share borders with the given split line
155  *
156  * \return TRUE if at least one segment is in the border.
157  */
158  static bool filterSegmentsInBorder(const te::gm::Geometry* geometry, std::size_t geometryIndex, const te::gm::LineString* splitLine, std::vector<te::vp::SegmentInfo*>& vecSegmentsInBorder);
159 
160  /*!
161  * \brief From the givem geometry vector, creates a list of all the segments that are exactly in the border of the given split reference line. It also returns the indexes of the geometries that doesnt overlap the given split reference line
162  *
163  * \param vecFragments The vector containing the geometry fragments to be analysed
164  * \param splitLine The referente split line where the geomtry fragments must be analysed
165  * \param vecIndexesNotInBorder (Return parameter) A return value containing the indexes of the geometries that doesnt overlap the given split reference line
166  *
167  * \return A vector containing all the segments in the border of the given split reference line
168  */
169  static std::vector<te::vp::SegmentInfo*> filterSegmentsInBorder(const te::gm::GeometryVector& vecFragments, const te::gm::LineString* splitLine, std::vector<std::size_t>& vecIndexesNotInBorder);
170 
171  static bool checkForGeometrySubdivision(const te::gm::Envelope& currentTile, const te::gm::Geometry* geometry, std::size_t geometryIndex, std::vector<te::vp::SegmentInfo*>& vecSegmentsInBorder);
172 
173  /*!
174  * \brief Dissolves all the geometries from the given fragments vector using the given match map as reference
175  *
176  * \param vecFragments A vector containing all the candidate fragments to be dissolved
177  * \param geometryMatchMap The match map to be be used as reference
178  *
179  * \return The geometry vector containing the dissolved geometries
180  */
181  static te::gm::GeometryVector dissolveFragments(const te::gm::GeometryVector& vecFragments, const Clusters& clusters);
182 
183  /*!
184  * \brief Dissolves all the geometries from the given fragments vector that have borders with the given split reference line
185  *
186  * \param vecFragments A vector containing all the candidate fragments to be dissolved
187  * \param splitLine The split reference line
188  *
189  * \return The geometry vector containing the dissolved geometries
190  */
191  static te::gm::GeometryVector merge(const te::gm::GeometryVector& vecFragments, const te::gm::LineString* splitLine);
192 
193  /*!
194  * \brief Dissolves all the geometries from the given fragments vector that have borders with the given split reference line
195  *
196  * \param vecFragments A vector containing all the candidate fragments to be dissolved
197  * \param splitLine The split reference line
198  *
199  * \return The geometry vector containing the dissolved geometries
200  */
201  static te::gm::GeometryVector merge(const te::gm::GeometryVector& vecFragments, const SubdividerTilling& tilling);
202 
203  static SetIndexes getUniqueIndexes(const GeometryAssociations& geometryAssociations);
204  };
205  }
206 }
207 
208 #endif //__TERRALIB_VP_INTERNAL_POLYGONSUBDIVIDER_H
te::vp::PolygonSubdivider::getUniqueIndexes
static SetIndexes getUniqueIndexes(const GeometryAssociations &geometryAssociations)
te::vp::PolygonSubdivider::filterSegmentsInBorder
static bool filterSegmentsInBorder(const te::gm::Geometry *geometry, std::size_t geometryIndex, const te::gm::LineString *splitLine, std::vector< te::vp::SegmentInfo * > &vecSegmentsInBorder)
From the givem geometry, creates a list of all the segments that are exactly in the border of the giv...
te::gm::Envelope
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:52
te::vp::PolygonSubdivider::subdivide
static te::gm::GeometryVector subdivide(const te::gm::GeometryVector &vecInputGeometries, std::size_t maxCoordinates, std::vector< std::size_t > &vecParentIndexes)
Subdivides the given vecInputGeometries using the given envelope. This has the same result as an inte...
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::vp::PolygonSubdivider::SetIndexes
std::set< std::size_t > SetIndexes
Definition: PolygonSubdivider.h:65
te::vp::PolygonSubdivider::subdivide
static te::gm::GeometryVector subdivide(const te::gm::GeometryVector &vecInputGeometries, const te::gm::Envelope &envelope, std::size_t maxCoordinates)
te::vp::PolygonSubdivider::GeometryAssociation
std::pair< std::size_t, std::size_t > GeometryAssociation
Definition: PolygonSubdivider.h:66
te::vp::PolygonSubdivider::calculateGeometryClusters
static Clusters calculateGeometryClusters(const GeometryAssociations &geometryMatchMap)
Normalizes an match map ensuring that all the list of indexes is complete, that is,...
te::vp::PolygonSubdivider::subdivide
static te::gm::GeometryVector subdivide(const te::gm::Geometry *geometry, const te::gm::Envelope &envelope, std::size_t maxCoordinates)
Subdivides the given geometry using the given envelope. This has the same result as an intersection o...
te::vp::SubdividerTilling
Algorithm to help controlling creating and iterating in a tile.
Definition: SubdividerTilling.h:54
te::vp::PolygonSubdivider::calculateGeometryAssociations
static GeometryAssociations calculateGeometryAssociations(const std::vector< te::vp::SegmentInfo * > &vecBorderSegments, te::gm::Dimensionality dimensionality)
Creates a non-normalized match map containing only the indexes of geometries that have a border relat...
te::vp::PolygonSubdivider::calculateGeometryAssociations
static GeometryAssociations calculateGeometryAssociations(const te::gm::GeometryVector &vecFragments, const te::gm::LineString *splitLine)
Creates a normalized match map containing only the indexes of geometries that have a border relation ...
te::gm::GeometryVector
std::vector< te::gm::Geometry * > GeometryVector
Definition: CommonDataStructures.h:50
TEVPEXPORT
#define TEVPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61
te::vp::PolygonSubdivider::ClusterIndexes
std::vector< std::size_t > ClusterIndexes
Definition: PolygonSubdivider.h:68
te::vp::PolygonSubdivider::GeometryAssociations
std::vector< GeometryAssociation > GeometryAssociations
Definition: PolygonSubdivider.h:67
te::vp::PolygonSubdivider::filterSegmentsInBorder
static std::vector< te::vp::SegmentInfo * > filterSegmentsInBorder(const te::gm::GeometryVector &vecFragments, const te::gm::LineString *splitLine, std::vector< std::size_t > &vecIndexesNotInBorder)
From the givem geometry vector, creates a list of all the segments that are exactly in the border of ...
te::gm::Dimensionality
Dimensionality
From Wikipedia: "in mathematics, the dimension of an object is an intrinsic property,...
Definition: Enums.h:148
te::gm::LineString
LineString is a curve with linear interpolation between points.
Definition: LineString.h:65
te::vp::PolygonSubdivider::subdivide
static te::gm::GeometryVector subdivide(const te::gm::GeometryVector &vecInputGeometries, const SubdividerTilling &tilling, std::size_t maxCoordinates)
Subdivides the given vecInputGeometries using the given envelope. This has the same result as an inte...
te::vp::PolygonSubdivider::Clusters
std::vector< ClusterIndexes > Clusters
Definition: PolygonSubdivider.h:69
te::vp::PolygonSubdivider::merge
static te::gm::GeometryVector merge(const te::gm::GeometryVector &vecFragments, const SubdividerTilling &tilling)
Dissolves all the geometries from the given fragments vector that have borders with the given split r...
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::vp::PolygonSubdivider::subdivide
static te::gm::GeometryVector subdivide(const te::gm::Geometry *geometry, const SubdividerTilling &tilling, std::size_t maxCoordinates)
Subdivides the given geometry using the given envelope. This has the same result as an intersection o...
te::vp::PolygonSubdivider
Algorithm to subdivide polygons based on a cell tilling and merge them back to their original format.
Definition: PolygonSubdivider.h:62
CommonDataStructures.h
Utility classes, structures and definitions for Vector Processing.
te::gm::Geometry
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
te::vp::PolygonSubdivider::merge
static te::gm::GeometryVector merge(const te::gm::GeometryVector &vecFragments, const te::gm::LineString *splitLine)
Dissolves all the geometries from the given fragments vector that have borders with the given split r...
te::vp::PolygonSubdivider::checkForGeometrySubdivision
static bool checkForGeometrySubdivision(const te::gm::Envelope &currentTile, const te::gm::Geometry *geometry, std::size_t geometryIndex, std::vector< te::vp::SegmentInfo * > &vecSegmentsInBorder)
te::vp::PolygonSubdivider::dissolveFragments
static te::gm::GeometryVector dissolveFragments(const te::gm::GeometryVector &vecFragments, const Clusters &clusters)
Dissolves all the geometries from the given fragments vector using the given match map as reference.
te::vp::PolygonSubdivider::subdivide
static te::gm::GeometryVector subdivide(const te::gm::Geometry *geometry, std::size_t maxCoordinates)
Subdivides the given geometry using the given envelope. This has the same result as an intersection o...