All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WKTActions.cpp
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/WKTActions.cpp
22 
23  \brief A class that implements the semanthic actions to grammar rules for well known text (Wkt) format for Geometry.
24  Basically, the class is responsible to generate a geometry element.
25 */
26 
27 // TerraLib
28 #include "Geometry.h"
29 #include "GeometryCollection.h"
30 #include "LineString.h"
31 #include "LinearRing.h"
32 #include "Point.h"
33 #include "PointM.h"
34 #include "PointZ.h"
35 #include "PointZM.h"
36 #include "Polygon.h"
37 #include "PolyhedralSurface.h"
38 #include "MultiLineString.h"
39 #include "MultiPoint.h"
40 #include "MultiPolygon.h"
41 #include "TIN.h"
42 #include "Triangle.h"
43 #include "WKTActions.h"
44 #include "../common/STLUtils.h"
45 
47 m_g(0)
48 {}
49 
51 {}
52 
54 {
55  m_g = 0;
56 
57  te::common::FreeContents(m_points);
58  m_points.clear();
59 
60  te::common::FreeContents(m_lines);
61  m_lines.clear();
62 
63  te::common::FreeContents(m_polygons);
64  m_polygons.clear();
65 
66  te::common::FreeContents(m_geometries);
67  m_geometries.clear();
68 }
69 
70 void te::gm::WKTActions::createPoint(const boost::fusion::vector2<double, double>& c)
71 {
72  te::gm::Point* p = new te::gm::Point(c.m0, c.m1);
73  m_points.push_back(p);
74  m_g = p;
75 }
76 
77 void te::gm::WKTActions::createPointZ(const boost::fusion::vector3<double, double, double>& c)
78 {
79  te::gm::PointZ* p = new te::gm::PointZ(c.m0, c.m1, c.m2);
80  m_points.push_back(p);
81  m_g = p;
82 }
83 
84 void te::gm::WKTActions::createPointM(const boost::fusion::vector3<double, double, double>& c)
85 {
86  te::gm::PointM* p = new te::gm::PointM(c.m0, c.m1, c.m2);
87  m_points.push_back(p);
88  m_g = p;
89 }
90 
91 void te::gm::WKTActions::createPointZM(const boost::fusion::vector4<double, double, double, double>& c)
92 {
93  te::gm::PointZM* p = new te::gm::PointZM(c.m0, c.m1, c.m2, c.m3);
94  m_points.push_back(p);
95  m_g = p;
96 }
97 
99 {
100  te::gm::Point* p = new te::gm::Point;
101  m_points.push_back(p);
102  m_g = p;
103 }
104 
106 {
108  m_points.push_back(p);
109  m_g = p;
110 }
111 
113 {
115  m_points.push_back(p);
116  m_g = p;
117 }
118 
120 {
122  m_points.push_back(p);
123  m_g = p;
124 }
125 
127 {
129  buildLine(l);
130 }
131 
133 {
135  buildLine(l);
136 }
137 
139 {
141  buildLine(l);
142 }
143 
145 {
147  buildLine(l);
148 }
149 
151 {
153  buildLine(l);
154 }
155 
157 {
159  buildLine(l);
160 }
161 
163 {
165  buildLine(l);
166 }
167 
169 {
171  buildLine(l);
172 }
173 
175 {
176  te::gm::Polygon* p = new te::gm::Polygon(m_lines.size(), te::gm::PolygonType);
177  buildPolygon(p);
178 }
179 
181 {
182  te::gm::Polygon* p = new te::gm::Polygon(m_lines.size(), te::gm::PolygonZType);
183  buildPolygon(p);
184 }
185 
187 {
188  te::gm::Polygon* p = new te::gm::Polygon(m_lines.size(), te::gm::PolygonMType);
189  buildPolygon(p);
190 }
191 
193 {
194  te::gm::Polygon* p = new te::gm::Polygon(m_lines.size(), te::gm::PolygonZMType);
195  buildPolygon(p);
196 }
197 
199 {
200  buildMultiPoint(te::gm::MultiPointType);
201 }
202 
204 {
205  buildMultiPoint(te::gm::MultiPointZType);
206 }
207 
209 {
210  buildMultiPoint(te::gm::MultiPointMType);
211 }
212 
214 {
215  buildMultiPoint(te::gm::MultiPointZMType);
216 }
217 
219 {
220  buildMultiLineString(te::gm::MultiLineStringType);
221 }
222 
224 {
225  buildMultiLineString(te::gm::MultiLineStringZType);
226 }
227 
229 {
230  buildMultiLineString(te::gm::MultiLineStringMType);
231 }
232 
234 {
235  buildMultiLineString(te::gm::MultiLineStringZMType);
236 }
237 
239 {
240  buildMultiPolygon(te::gm::MultiPolygonType);
241 }
242 
244 {
245  buildMultiPolygon(te::gm::MultiPolygonZType);
246 }
247 
249 {
250  buildMultiPolygon(te::gm::MultiPolygonMType);
251 }
252 
254 {
255  buildMultiPolygon(te::gm::MultiPolygonZMType);
256 }
257 
259 {
261  buildPolyhedralSurface(ps);
262 }
263 
265 {
267  buildPolyhedralSurface(ps);
268 }
269 
271 {
273  buildPolyhedralSurface(ps);
274 }
275 
277 {
279  buildPolyhedralSurface(ps);
280 }
281 
283 {
284  te::gm::PolyhedralSurface* tin = new te::gm::TIN(m_polygons.size(), te::gm::TINType);
285  buildPolyhedralSurface(tin);
286 }
287 
289 {
290  te::gm::PolyhedralSurface* tin = new te::gm::TIN(m_polygons.size(), te::gm::TINZType);
291  buildPolyhedralSurface(tin);
292 }
293 
295 {
296  te::gm::PolyhedralSurface* tin = new te::gm::TIN(m_polygons.size(), te::gm::TINMType);
297  buildPolyhedralSurface(tin);
298 }
299 
301 {
302  te::gm::PolyhedralSurface* tin = new te::gm::TIN(m_polygons.size(), te::gm::TINZMType);
303  buildPolyhedralSurface(tin);
304 }
305 
307 {
308  te::gm::Polygon* t = new te::gm::Triangle(m_lines.size(), te::gm::TriangleType);
309  buildPolygon(t);
310 }
311 
313 {
314  te::gm::Polygon* t = new te::gm::Triangle(m_lines.size(), te::gm::TriangleZType);
315  buildPolygon(t);
316 }
317 
319 {
320  te::gm::Polygon* t = new te::gm::Triangle(m_lines.size(), te::gm::TriangleMType);
321  buildPolygon(t);
322 }
323 
325 {
326  te::gm::Polygon* t = new te::gm::Triangle(m_lines.size(), te::gm::TriangleZMType);
327  buildPolygon(t);
328 }
329 
331 {
332  buildGeometryCollection(te::gm::GeometryCollectionType);
333 }
334 
336 {
337  buildGeometryCollection(te::gm::GeometryCollectionZType);
338 }
339 
341 {
342  buildGeometryCollection(te::gm::GeometryCollectionMType);
343 }
344 
346 {
347  buildGeometryCollection(te::gm::GeometryCollectionZMType);
348 }
349 
351 {
352  m_points.clear();
353  m_lines.clear();
354  m_polygons.clear();
355  m_geometries.push_back(m_g);
356 }
357 
359 {
360  m_geometries.clear();
361 }
362 
364 {
365  for(std::size_t i = 0; i < l->getNPoints(); ++i)
366  l->setPointN(i, *m_points[i]);
367 
368  m_lines.push_back(l);
369 
370  te::common::FreeContents(m_points);
371  m_points.clear();
372 
373  m_g = l;
374 }
375 
377 {
378  std::size_t size = m_lines.size();
379  for(std::size_t i = 0; i < size; ++i)
380  p->setRingN(i, dynamic_cast<te::gm::LinearRing*>(m_lines[i]));
381 
382  m_lines.clear();
383 
384  m_polygons.push_back(p);
385 
386  m_g = p;
387 }
388 
390 {
391  std::size_t size = m_lines.size();
392  te::gm::Polygon* p = new te::gm::Polygon(size, t);
393 
394  for(std::size_t i = 0; i < size; ++i)
395  p->setRingN(i, dynamic_cast<te::gm::LinearRing*>(m_lines[i]));
396 
397  m_lines.clear();
398 
399  m_polygons.push_back(p);
400 
401  m_g = p;
402 }
403 
405 {
406  std::size_t size = m_points.size();
407  te::gm::MultiPoint* mp = new te::gm::MultiPoint(size, t);
408 
409  for(std::size_t i = 0; i < size; ++i)
410  mp->setGeometryN(i, m_points[i]);
411 
412  m_points.clear();
413 
414  m_g = mp;
415 }
416 
418 {
419  std::size_t size = m_lines.size();
421 
422  for(std::size_t i = 0; i < size; ++i)
423  ml->setGeometryN(i, m_lines[i]);
424 
425  m_lines.clear();
426 
427  m_g = ml;
428 }
429 
431 {
432  std::size_t size = m_polygons.size();
433  te::gm::MultiPolygon* mp = new te::gm::MultiPolygon(size, t);
434 
435  for(std::size_t i = 0; i < size; ++i)
436  mp->setGeometryN(i, m_polygons[i]);
437 
438  m_polygons.clear();
439 
440  m_g = mp;
441 }
442 
444 {
445  std::size_t size = m_polygons.size();
446  for(std::size_t i = 0; i < size; ++i)
447  ps->setPatchN(i, m_polygons[i]);
448 
449  m_polygons.clear();
450 
451  m_g = ps;
452 }
453 
455 {
456  std::size_t size = m_geometries.size();
458  for(std::size_t i = 0; i < size; ++i)
459  gc->setGeometryN(i, m_geometries[i]);
460 
461  m_geometries.clear();
462 
463  m_g = gc;
464 }
465 
467 {
468  return m_g;
469 }
470 
471 
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments...
void buildMultiPoint(const GeomType &t)
Definition: WKTActions.cpp:404
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
A LinearRing is a LineString that is both closed and simple.
void createGeometryCollection()
Definition: WKTActions.cpp:330
void buildPolyhedralSurface(PolyhedralSurface *ps)
Definition: WKTActions.cpp:443
A point with x and y coordinate values.
void createGeometryCollectionZ()
Definition: WKTActions.cpp:335
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
MultiPoint is a GeometryCollection whose elements are restricted to points.
A point with a z-coordinate value and an associated measurement.
Definition: PointZM.h:51
void createPolyhedralSurfaceM()
Definition: WKTActions.cpp:270
A point with an associated measure.
Definition: PointM.h:51
TIN (triangulated irregular network) is a PolyhedralSurface consisting only of Triangle patches...
Definition: TIN.h:50
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:50
A point with z-coordinate value.
Definition: PointZ.h:51
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
Triangle is a polygon with 3 distinct, non-collinear vertices and no interior boundary.
Triangle is a polygon with 3 distinct, non-collinear vertices and no interior boundary.
Definition: Triangle.h:50
A point with x and y coordinate values.
Definition: Point.h:50
MultiLineString is a MultiCurve whose elements are LineStrings.
Geometry * getGeometry()
It returns the geometry generated by the parser process.
Definition: WKTActions.cpp:466
void createMultiLineStringZ()
Definition: WKTActions.cpp:223
MultiPolygon is a MultiSurface whose elements are Polygons.
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
Definition: LineString.h:193
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
void createPolyhedralSurfaceZM()
Definition: WKTActions.cpp:276
void buildLine(LineString *l)
Definition: WKTActions.cpp:363
TIN (triangulated irregular network) is a PolyhedralSurface consisting only of Triangle patches...
void buildPolygon(const GeomType &t)
Definition: WKTActions.cpp:389
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
MultiLineString is a MultiCurve whose elements are LineStrings.
void createMultiLineString()
Definition: WKTActions.cpp:218
void createGeometryCollectionZM()
Definition: WKTActions.cpp:345
void createMultiLineStringM()
Definition: WKTActions.cpp:228
void createMultiPolygonM()
Definition: WKTActions.cpp:248
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
void buildMultiPolygon(const GeomType &t)
Definition: WKTActions.cpp:430
~WKTActions()
Destructor.
Definition: WKTActions.cpp:50
void createMultiPolygonZ()
Definition: WKTActions.cpp:243
void buildGeometryCollection(const GeomType &t)
Definition: WKTActions.cpp:454
void createPolyhedralSurfaceZ()
Definition: WKTActions.cpp:264
void setGeometryN(std::size_t i, Geometry *g)
It sets the n-th geometry in this geometry collection.
void createMultiLineStringZM()
Definition: WKTActions.cpp:233
LineString is a curve with linear interpolation between points.
void setPointN(std::size_t i, const Point &p)
It sets the value of the specified point to this new one.
Definition: LineString.cpp:339
void buildMultiLineString(const GeomType &t)
Definition: WKTActions.cpp:417
void setPatchN(std::size_t i, Polygon *p)
It sets the informed position polygon to the new one.
It is a collection of other geometric objects.
A point with z-coordinate value.
A point with a z-coordinate value and an associated measurement.
A point with an associated measure.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
void reset()
This method resets the Action class to original state.
Definition: WKTActions.cpp:53
WKTActions()
Default constructor.
Definition: WKTActions.cpp:46
It is a collection of other geometric objects.
void createPolyhedralSurface()
Definition: WKTActions.cpp:258
void createMultiPolygonZM()
Definition: WKTActions.cpp:253
void createGeometryCollectionM()
Definition: WKTActions.cpp:340
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.
A class that implements the semanthic actions to grammar rules for well known text (WKT) format for G...