All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WKBSize.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/WKBSize.cpp
22 
23  \brief A class that serializes a geometry to the WKB format.
24 */
25 
26 // TerraLib
27 #include "GeometryCollection.h"
28 #include "LinearRing.h"
29 #include "MultiLineString.h"
30 #include "MultiPoint.h"
31 #include "MultiPolygon.h"
32 #include "PointM.h"
33 #include "PointZ.h"
34 #include "PointZM.h"
35 #include "Polygon.h"
36 #include "PolyhedralSurface.h"
37 #include "WKBSize.h"
38 
39 // STL
40 #include <cassert>
41 
43  : m_size(0)
44 {
45 }
46 
48 {
49 }
50 
51 std::size_t te::gm::WKBSize::size(const Geometry* geom)
52 {
53  WKBSize w;
54 
55  geom->accept(w);
56 
57  return w.m_size;
58 }
59 
60 std::size_t te::gm::WKBSize::size(const Geometry& geom)
61 {
62  WKBSize w;
63 
64  geom.accept(w);
65 
66  return w.m_size;
67 }
68 
70 {
71  m_size += 9; // byte order + type + ngeoms
72 
73  std::size_t nGeoms = visited.getNumGeometries();
74 
75  for(std::size_t i = 0; i < nGeoms; ++i)
76  {
77  assert(visited.getGeometryN(i) != 0);
78  visited.getGeometryN(i)->accept(*this);
79  }
80 }
81 
82 void te::gm::WKBSize::visit(const LinearRing& visited)
83 {
84  visit((const LineString&)visited);
85 }
86 
87 void te::gm::WKBSize::visit(const LineString& visited)
88 {
89  const std::size_t m_nPts = visited.size();
90 
91 // byte order + geom type + npts
92  m_size += 9 + (16 * m_nPts);
93 
94  if(visited.getZ())
95  m_size += (8 * m_nPts);
96 
97  if(visited.getM())
98  m_size += (8 * m_nPts);
99 }
100 
102 {
103  visit((const GeometryCollection&)visited);
104 }
105 
106 void te::gm::WKBSize::visit(const MultiPoint& visited)
107 {
108  visit((const GeometryCollection&)visited);
109 }
110 
112 {
113  visit((const GeometryCollection&)visited);
114 }
115 
116 void te::gm::WKBSize::visit(const Point& /*visited*/)
117 {
118  m_size += 21;
119 }
120 
121 void te::gm::WKBSize::visit(const PointM& /*visited*/)
122 {
123  m_size += 29;
124 }
125 
126 void te::gm::WKBSize::visit(const PointZ& /*visited*/)
127 {
128  m_size += 29;
129 }
130 
131 void te::gm::WKBSize::visit(const PointZM& /*visited*/)
132 {
133  m_size += 37;
134 }
135 
136 void te::gm::WKBSize::visit(const Polygon& visited)
137 {
138  m_size += 9; // byte order + type + nrings
139 
140  std::size_t nComponents = visited.getCoordinateDimension();
141  std::size_t nRings = visited.getNumRings();
142 
143  for(std::size_t i = 0; i < nRings; ++i)
144  m_size += ((visited.getRingN(i)->getNPoints() * nComponents * 8) + 4);
145 }
146 
148 {
149  m_size += 9; // byte order + type + npols
150 
151  std::size_t nPols = visited.getNumPatches();
152 
153  for(std::size_t i = 0; i < nPols; ++i)
154  visit(*(visited.getPatchN(i)));
155 }
156 
157 void te::gm::WKBSize::visit(const TIN& visited)
158 {
159  visit((const PolyhedralSurface&)visited);
160 }
161 
162 void te::gm::WKBSize::visit(const Triangle& visited)
163 {
164  visit((const Polygon&)visited);
165 }
166 
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments...
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
Definition: CurvePolygon.h:153
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
int getCoordinateDimension() const
It returns the number of measurements or axes needed to describe a position in a coordinate system...
Definition: Geometry.cpp:94
A LinearRing is a LineString that is both closed and simple.
Polygon * getPatchN(std::size_t i) const
It returns a polygon in this surface, the order is arbitrary.
static std::size_t size(const Geometry *geom)
It calculates the number of bytes required to encode the geometry in a WKB format.
Definition: WKBSize.cpp:51
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments...
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
A class that computes the number of bytes necessary to encode a geometry in WKB.
Definition: WKBSize.h:44
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.
Definition: Triangle.h:50
A point with x and y coordinate values.
Definition: Point.h:50
~WKBSize()
Destructor.
Definition: WKBSize.cpp:47
MultiLineString is a MultiCurve whose elements are LineStrings.
virtual std::size_t getNPoints() const =0
it returns the number of points (vertexes) in the geometry.
MultiPolygon is a MultiSurface whose elements are Polygons.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
MultiLineString is a MultiCurve whose elements are LineStrings.
std::size_t getNumPatches() const
It returns the number of including polygons.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
A class that computes the number of bytes necessary to encode a geometry in WKB.
std::size_t m_size
A counter for the number of bytes required to store a given geometry in WKB.
Definition: WKBSize.h:103
const double & getZ(std::size_t i) const
It returns the n-th z coordinate value.
Definition: LineString.cpp:397
const double & getM(std::size_t i) const
It returns the n-th m measure value.
Definition: LineString.cpp:403
It is a collection of other geometric objects.
A point with z-coordinate value.
void visit(const Curve &)
Definition: WKBSize.h:68
A point with a z-coordinate value and an associated measurement.
A point with an associated measure.
It is a collection of other geometric objects.
Curve * getRingN(std::size_t i) const
It returns the n-th ring for this curve polygon as a curve.
Definition: CurvePolygon.h:193
std::size_t size() const
It returns the number of points (vertexes) in the geometry.
Definition: LineString.h:262
WKBSize()
Not instantiable class.
Definition: WKBSize.cpp:42