geometry/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 "Polygon.h"
34 #include "PolyhedralSurface.h"
35 #include "MultiLineString.h"
36 #include "MultiPoint.h"
37 #include "MultiPolygon.h"
38 #include "TIN.h"
39 #include "Triangle.h"
40 #include "WKTActions.h"
41 #include "../common/STLUtils.h"
42 
44 m_g(nullptr)
45 {}
46 
48 
50 {
51  m_g = nullptr;
52 
54  m_points.clear();
55 
57  m_lines.clear();
58 
60  m_polygons.clear();
61 
63  m_geometries.clear();
64 }
65 
66 void te::gm::WKTActions::createPoint(const boost::fusion::vector2<double, double>& c)
67 {
68  te::gm::Point* p = new te::gm::Point(boost::fusion::at_c<0>(c), boost::fusion::at_c<1>(c));
69  m_points.push_back(p);
70  m_g = p;
71 }
72 
73 void te::gm::WKTActions::createPointZ(const boost::fusion::vector3<double, double, double>& c)
74 {
76  p->setX(boost::fusion::at_c<0>(c));
77  p->setY(boost::fusion::at_c<1>(c));
78  p->setZ(boost::fusion::at_c<2>(c));
79  m_points.push_back(p);
80  m_g = p;
81 }
82 
83 void te::gm::WKTActions::createPointM(const boost::fusion::vector3<double, double, double>& c)
84 {
86  p->setX(boost::fusion::at_c<0>(c));
87  p->setY(boost::fusion::at_c<1>(c));
88  p->setM(boost::fusion::at_c<2>(c));
89  m_points.push_back(p);
90  m_g = p;
91 }
92 
93 void te::gm::WKTActions::createPointZM(const boost::fusion::vector4<double, double, double, double>& c)
94 {
96  p->setX(boost::fusion::at_c<0>(c));
97  p->setY(boost::fusion::at_c<1>(c));
98  p->setZ(boost::fusion::at_c<2>(c));
99  p->setM(boost::fusion::at_c<3>(c));
100  m_points.push_back(p);
101  m_g = p;
102 }
103 
105 {
106  te::gm::Point* p = new te::gm::Point();
107  m_points.push_back(p);
108  m_g = p;
109 }
110 
112 {
114  m_points.push_back(p);
115  m_g = p;
116 }
117 
119 {
121  m_points.push_back(p);
122  m_g = p;
123 }
124 
126 {
128  m_points.push_back(p);
129  m_g = p;
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 {
177  buildLine(l);
178 }
179 
181 {
183  buildPolygon(p);
184 }
185 
187 {
189  buildPolygon(p);
190 }
191 
193 {
195  buildPolygon(p);
196 }
197 
199 {
201  buildPolygon(p);
202 }
203 
205 {
207 }
208 
210 {
212 }
213 
215 {
217 }
218 
220 {
222 }
223 
225 {
227 }
228 
230 {
232 }
233 
235 {
237 }
238 
240 {
242 }
243 
245 {
247 }
248 
250 {
252 }
253 
255 {
257 }
258 
260 {
262 }
263 
265 {
267 }
268 
270 {
272 }
273 
275 {
277 }
278 
280 {
282 }
283 
285 {
288 }
289 
291 {
294 }
295 
297 {
300 }
301 
303 {
306 }
307 
309 {
312 }
313 
315 {
318 }
319 
321 {
324 }
325 
327 {
330 }
331 
333 {
335  buildPolygon(t);
336 }
337 
339 {
341  buildPolygon(t);
342 }
343 
345 {
347  buildPolygon(t);
348 }
349 
351 {
353  buildPolygon(t);
354 }
355 
357 {
359 }
360 
362 {
364 }
365 
367 {
369 }
370 
372 {
374 }
375 
377 {
378  m_points.clear();
379  m_lines.clear();
380  m_polygons.clear();
381  m_geometries.push_back(m_g);
382 }
383 
385 {
386  m_geometries.clear();
387 }
388 
390 {
391  for(std::size_t i = 0; i < l->getNPoints(); ++i)
392  l->setPointN(i, *m_points[i]);
393 
394  m_lines.push_back(l);
395 
397  m_points.clear();
398 
399  m_g = l;
400 }
401 
403 {
404  std::size_t size = m_lines.size();
405  for(std::size_t i = 0; i < size; ++i)
406  p->setRingN(i, dynamic_cast<te::gm::LinearRing*>(m_lines[i]));
407 
408  m_lines.clear();
409 
410  m_polygons.push_back(p);
411 
412  m_g = p;
413 }
414 
416 {
417  std::size_t size = m_lines.size();
418  te::gm::Polygon* p = new te::gm::Polygon(size, t);
419 
420  for(std::size_t i = 0; i < size; ++i)
421  p->setRingN(i, dynamic_cast<te::gm::LinearRing*>(m_lines[i]));
422 
423  m_lines.clear();
424 
425  m_polygons.push_back(p);
426 
427  m_g = p;
428 }
429 
431 {
432  std::size_t size = m_points.size();
433  te::gm::MultiPoint* mp = new te::gm::MultiPoint(size, t);
434 
435  for(std::size_t i = 0; i < size; ++i)
436  mp->setGeometryN(i, m_points[i]);
437 
438  m_points.clear();
439 
440  m_g = mp;
441 }
442 
444 {
445  std::size_t size = m_lines.size();
447 
448  for(std::size_t i = 0; i < size; ++i)
449  ml->setGeometryN(i, m_lines[i]);
450 
451  m_lines.clear();
452 
453  m_g = ml;
454 }
455 
457 {
458  std::size_t size = m_polygons.size();
459  te::gm::MultiPolygon* mp = new te::gm::MultiPolygon(size, t);
460 
461  for(std::size_t i = 0; i < size; ++i)
462  mp->setGeometryN(i, m_polygons[i]);
463 
464  m_polygons.clear();
465 
466  m_g = mp;
467 }
468 
470 {
471  std::size_t size = m_geometries.size();
472  te::gm::MultiSurface* ms = new te::gm::MultiSurface(size, t);
473  for (std::size_t i = 0; i < size; ++i)
474  ms->setGeometryN(i, m_geometries[i]);
475 
476  m_geometries.clear();
477 
478  m_g = ms;
479 }
480 
482 {
483  std::size_t size = m_polygons.size();
484  for(std::size_t i = 0; i < size; ++i)
485  ps->setPatchN(i, m_polygons[i]);
486 
487  m_polygons.clear();
488 
489  m_g = ps;
490 }
491 
493 {
494  std::size_t size = m_geometries.size();
496  for(std::size_t i = 0; i < size; ++i)
497  gc->setGeometryN(i, m_geometries[i]);
498 
499  m_geometries.clear();
500 
501  m_g = gc;
502 }
503 
505 {
506  return m_g;
507 }
508 
509 
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments...
void buildMultiPoint(const GeomType &t)
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.
A LinearRing is a LineString that is both closed and simple.
std::vector< Point * > m_points
std::vector< LineString * > m_lines
void buildPolyhedralSurface(PolyhedralSurface *ps)
A point with x and y coordinate values.
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.
te::gm::GeometryCollection * gc
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
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
std::vector< Geometry * > m_geometries
MultiLineString is a MultiCurve whose elements are LineStrings.
Geometry * getGeometry()
It returns the geometry generated by the parser process.
void setM(const double &m)
It sets the Point m-coordinate value.
Definition: Point.h:187
std::vector< Polygon * > m_polygons
te::gm::Polygon * p
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.
void buildLine(LineString *l)
TIN (triangulated irregular network) is a PolyhedralSurface consisting only of Triangle patches...
void buildPolygon(const GeomType &t)
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
MultiLineString is a MultiCurve whose elements are LineStrings.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
void buildMultiPolygon(const GeomType &t)
void setX(const double &x)
It sets the Point x-coordinate value.
Definition: Point.h:145
~WKTActions()
Destructor.
MultiSurface is a class that represents a 2-dimensional GeometryCollection whose elements are surface...
Definition: MultiSurface.h:54
void buildGeometryCollection(const GeomType &t)
void buildMultiSurface(const GeomType &t)
void setGeometryN(std::size_t i, Geometry *g)
It sets the n-th geometry in this geometry collection.
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.
void buildMultiLineString(const GeomType &t)
void setPatchN(std::size_t i, Polygon *p)
It sets the informed position polygon to the new one.
void setY(const double &y)
It sets the Point y-coordinate value.
Definition: Point.h:159
It is a collection of other geometric objects.
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.
WKTActions()
Default constructor.
It is a collection of other geometric objects.
void setZ(const double &z)
It sets the Point z-coordinate value.
Definition: Point.h:173
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...