Loading...
Searching...
No Matches
GeometryCollection.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/GeometryCollection.h
22
23 \brief It is a collection of other geometric objects.
24*/
25
26#ifndef __TERRALIB_GEOMETRY_INTERNAL_GEOMETRYCOLLECTION_H
27#define __TERRALIB_GEOMETRY_INTERNAL_GEOMETRYCOLLECTION_H
28
29// TerraLib
30#include "Geometry.h"
31
32// STL
33#include <vector>
34
35namespace te
36{
37 namespace gm
38 {
39 /*!
40 \class GeometryCollection
41
42 \brief It is a collection of other geometric objects.
43
44 \ingroup geometry
45
46 \sa Geometry,
47 Point,
48 Curve, LineString, LinearRing,
49 Surface, Polygon, Triangle, PolyhedralSurface, TIN,
50 MultiSurface, MultiCurve,
51 MultiPoint, MultiLineString, MultiPolygon
52
53 \note All the elements shall be in the same Spatial Reference System as
54 the geometry collection. Although the class will not perform this check it
55 is very important to use it to build valid geometries.
56 */
58 {
59 public:
60
62
63 /** @name Initializer methods on geometric objects
64 * Methods for initializing a geometric object.
65 */
66 //@{
67
68 /*!
69 \brief It initializes the geometry collection with the specified spatial reference system id and envelope.
70
71 \param nGeom The number of geometries in the collection. This will reserve same space in the list of geometries.
72 \param t The internal type of the Geometry.
73 \param srid The Spatial Reference System ID associated to the Geometry.
74 \param mbr The minimum bounding rectangle of this geometry (i.e., its envelope). May be a NULL value.
75
76 \note The geometry collection will take the ownership of the given mbr.
77
78 \note When using this constructor you must set all geometries before calling any other method (like getMBR).
79 */
80 GeometryCollection(std::size_t nGeom, GeomType t, int srid = 0, Envelope* mbr = 0);
81
82 /*!
83 \brief Copy constructor.
84
85 \param rhs The other geometry.
86 */
88
89 /*!
90 \brief Assignment operator.
91
92 \param rhs The other geometry.
93
94 \return A reference for this.
95 */
97
98 /*! \brief Virtual destructor. */
100
101 //@}
102
103 /** @name Re-Implementation from AbstractData
104 * Methods re-Implementated from AbstractData.
105 */
106 //@{
107
108 /*!
109 \brief It clones the geometry collection.
110
111 \return A copy of the given geometry collection.
112
113 \note The caller of this method will take the ownership of the returned geometry collection.
114
115 \note The cloned geometry collection will not have the
116 MBR computed. This will save time when you
117 are just cloning a geometry and don't intend
118 to waste time computing the bounding box.
119 If you have another suggestion, please, let me know.
120 */
121 virtual te::dt::AbstractData* clone() const;
122
123 //@}
124
125 /** @name Re-Implmentation of methods from Geometry class
126 * Re-Implmentation of basic methods from Geometry class.
127 */
128 //@{
129
130 /*!
131 \brief For non-homogeneous collections this method will return the largest dimension of the contained objects.
132
133 \return The largest dimension of the contained objects.
134 */
135 virtual Dimensionality getDimension() const throw();
136
137 /*!
138 \brief The name of the Geometry subtype is: GeometryCollection.
139
140 \return The name of the Geometry subtype is: GeometryCollection.
141 */
142 virtual const std::string& getGeometryType() const throw();
143
144 /*!
145 \brief It sets the Spatial Reference System ID of the geometry collection and all its parts.
146
147 \param srid The Spatial Reference System ID to be associated to the geometric object.
148
149 \note TerraLib extended method.
150 */
151 void setSRID(int srid) throw();
152
153 /*!
154 \brief It will transform the coordinates of the geometry collection to the new one.
155
156 After calling this method the geometry collection will be associated to the new SRID.
157
158 \param converter The converter containing all the information related to the new Spatial Reference System ID used to transform the coordinates of the geometry.
159
160 \exception Exception It will throw an exception if it can not do the transformation.
161
162 \note The geometry collection must be associated to a valid SRID before calling this method.
163
164 \note If the geometry collection already has an associated MBR, it will automatically update it (i. e. automatically recompute it).
165
166 \note TerraLib extended method.
167 */
168 void convert(te::srs::Converter* converter) override;
169
170 /*!
171 \brief It computes the minimum bounding rectangle for the geometry collection.
172
173 \param cascade If true, it will update the MBR of its parts.
174
175 \note You can use this method in order to update the MBR of the geometry collection.
176
177 \note TerraLib extended method.
178 */
179 void computeMBR(bool cascade) const throw();
180
181 /*!
182 \brief it returns the number of points (vertexes) in the geometry.
183
184 \return The number of points (vertexes) in the geometry.
185
186 \note TerraLib extended method.
187 */
188 std::size_t getNPoints() const throw();
189
190 //@}
191
192
193 /** @name GeometryCollection Specific Methods
194 * Specific methods for a GeometryCollection.
195 */
196 //@{
197
198 /*!
199 \brief It returns a reference to the internal list of geometries.
200
201 \return A reference to the internal list of geometries.
202
203 \note This method can be used by database drivers to implement its own geometry wrappers!
204
205 \note TerraLib extended method.
206 */
207 const std::vector<Geometry*>& getGeometries() const { return m_geometries; }
208
209 /*!
210 \brief It returns a reference to the internal list of geometries.
211
212 \return A reference to the internal list of geometries.
213
214 \note This method can be used by database drivers to implement its own geometry wrappers!
215
216 \note TerraLib extended method.
217 */
218 std::vector<Geometry*>& getGeometries() { return m_geometries; }
219
220 /*!
221 \brief It returns the number of geometries in this GeometryCollection.
222
223 \return The number of geometries in this GeometryCollection.
224
225 \note If you are using this method for a loop, try to create a temporary
226 "const size_t variable" to keep this value; this can optimize your loop.
227 */
228 std::size_t getNumGeometries() const { return m_geometries.size(); }
229
230 /*!
231 \brief It sets the number of geometries in this GeometryCollection.
232
233 \param size The new number of geometries for the GeometryCollection.
234
235 \note If size is smaller than the current GeometryCollection size,
236 the content is reduced to its first size elements, the rest being just
237 dropped (the deallocation of geometries is done automatically).
238
239 \note If size is greater than the current GeometryCollection size,
240 the content is expanded by inserting at the end NULL pointers to geometries
241 as needed.
242
243 \note You must assure that all nGeom geometries are set before calling any other method (like getMBR).
244
245 \note TerraLib extended method.
246 */
247 void setNumGeometries(std::size_t size);
248
249 /*!
250 \brief It returns the n-th geometry in this GeometryCollection.
251
252 \param i The index of the given geometry element.
253
254 \return The geometry in the indicated position.
255
256 \note It doesn't check the index range.
257 */
258 Geometry* getGeometryN(std::size_t i) const;
259
260 /*!
261 \brief It returns the n-th geometry in this GeometryCollection.
262
263 \param i The index of the given geometry element.
264
265 \note It doesn't check the index range.
266 */
267 Geometry* getGeometryN(std::size_t i);
268
269 /*!
270 \brief It sets the n-th geometry in this geometry collection.
271
272 GeometryCollection will take the ownership of the informed geometry.
273 If there is a geometry in the given position it will be released before stting the new one.
274
275 \param i The index of the given geometry element.
276 \param g The geometry that will be placed on the position indicated by index.
277
278 \note It doesn't check the index range.
279
280 \note Geometry collection will take the ownership of the informed geometry.
281
282 \note TerraLib extended method.
283 */
284 void setGeometryN(std::size_t i, Geometry* g);
285
286 /*!
287 \brief It removes the n-th geometry in this geometry collection.
288
289 \param i The index of the geometry element we want to remove.
290
291 \note It doesn't check the index range.
292
293 \note TerraLib extended method.
294 */
295 void removeGeometryN(std::size_t i);
296
297 /*!
298 \brief It adds the geometry into the collection.
299
300 GeometryCollection will take the ownership of the informed geometry.
301
302 \param g The geometry you want to add to the collection.
303
304 \note TerraLib extended method.
305 */
306 void add(Geometry* g);
307
308 /*!
309 \brief It deletes all the elements of the collection.
310
311 After calling this method you can NOT use the setGeometryN method. You will need to call setNumGeometries() again or use add().
312
313 \note TerraLib extended method.
314 */
315 void clear();
316
317 //@}
318
319 protected:
320
321 std::vector<Geometry*> m_geometries; //!< The array of geometries that forms the collection.
322
323 private:
324
325 static const std::string sm_typeName; //!< Geometry type name for GeometryCollection.
326 };
327
328 } // end namespace gm
329} // end namespace te
330
331#endif // __TERRALIB_GEOMETRY_INTERNAL_GEOMETRYCOLLECTION_H
332
#define TE_DEFINE_VISITABLE
Definition: BaseVisitable.h:75
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:56
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:52
It is a collection of other geometric objects.
GeometryCollection(std::size_t nGeom, GeomType t, int srid=0, Envelope *mbr=0)
It initializes the geometry collection with the specified spatial reference system id and envelope.
void removeGeometryN(std::size_t i)
It removes the n-th geometry in this geometry collection.
static const std::string sm_typeName
Geometry type name for GeometryCollection.
std::vector< Geometry * > & getGeometries()
It returns a reference to the internal list of geometries.
void add(Geometry *g)
It adds the geometry into the collection.
virtual ~GeometryCollection()
Virtual destructor.
virtual Dimensionality getDimension() const
For non-homogeneous collections this method will return the largest dimension of the contained object...
void setNumGeometries(std::size_t size)
It sets the number of geometries in this GeometryCollection.
GeometryCollection(const GeometryCollection &rhs)
Copy constructor.
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
void setGeometryN(std::size_t i, Geometry *g)
It sets the n-th geometry in this geometry collection.
void clear()
It deletes all the elements of the collection.
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
std::vector< Geometry * > m_geometries
The array of geometries that forms the collection.
virtual te::dt::AbstractData * clone() const
It clones the geometry collection.
GeometryCollection & operator=(const GeometryCollection &rhs)
Assignment operator.
Geometry * getGeometryN(std::size_t i)
It returns the n-th geometry in this GeometryCollection.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:42
Dimensionality
From Wikipedia: "in mathematics, the dimension of an object is an intrinsic property,...
Definition: Enums.h:148
TerraLib.
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76