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 "Point.h"
33 #include "Polygon.h"
34 #include "PolyhedralSurface.h"
35 #include "WKBSize.h"
36 
37 // STL
38 #include <cassert>
39 
41  : m_size(0)
42 {
43 }
44 
45 te::gm::WKBSize::~WKBSize() = default;
46 
47 std::size_t te::gm::WKBSize::size(const Geometry* geom)
48 {
49  WKBSize w;
50 
51  geom->accept(w);
52 
53  return w.m_size;
54 }
55 
56 std::size_t te::gm::WKBSize::size(const Geometry& geom)
57 {
58  WKBSize w;
59 
60  geom.accept(w);
61 
62  return w.m_size;
63 }
64 
66 {
67  m_size += 9; // byte order + type + ngeoms
68 
69  std::size_t nGeoms = visited.getNumGeometries();
70 
71  for(std::size_t i = 0; i < nGeoms; ++i)
72  {
73  assert(visited.getGeometryN(i) != nullptr);
74  visited.getGeometryN(i)->accept(*this);
75  }
76 }
77 
78 void te::gm::WKBSize::visit(const LinearRing& visited)
79 {
80  visit((const LineString&)visited);
81 }
82 
83 void te::gm::WKBSize::visit(const LineString& visited)
84 {
85  const std::size_t m_nPts = visited.size();
86 
87 // byte order + geom type + npts
88  m_size += 9 + (16 * m_nPts);
89 
90  if(visited.getZ())
91  m_size += (8 * m_nPts);
92 
93  if(visited.getM())
94  m_size += (8 * m_nPts);
95 }
96 
98 {
99  visit((const GeometryCollection&)visited);
100 }
101 
102 void te::gm::WKBSize::visit(const MultiPoint& visited)
103 {
104  visit((const GeometryCollection&)visited);
105 }
106 
108 {
109  visit((const GeometryCollection&)visited);
110 }
111 
112 void te::gm::WKBSize::visit(const Point& visited)
113 {
114  switch (visited.getGeomTypeId()) {
115  case te::gm::PointType:
116  m_size += 21;
117  break;
118  case te::gm::PointMType:
119  case te::gm::PointZType:
120  m_size += 29;
121  break;
122  default:
123  m_size += 37;
124  break;
125  }
126 }
127 
128 void te::gm::WKBSize::visit(const Polygon& visited)
129 {
130  m_size += 9; // byte order + type + nrings
131 
132  std::size_t nComponents = visited.getCoordinateDimension();
133  std::size_t nRings = visited.getNumRings();
134 
135  for(std::size_t i = 0; i < nRings; ++i)
136  m_size += ((visited.getRingN(i)->getNPoints() * nComponents * 8) + 4);
137 }
138 
140 {
141  m_size += 9; // byte order + type + npols
142 
143  std::size_t nPols = visited.getNumPatches();
144 
145  for(std::size_t i = 0; i < nPols; ++i)
146  visit(*(visited.getPatchN(i)));
147 }
148 
149 void te::gm::WKBSize::visit(const TIN& visited)
150 {
151  visit((const PolyhedralSurface&)visited);
152 }
153 
154 void te::gm::WKBSize::visit(const Triangle& visited)
155 {
156  visit((const Polygon&)visited);
157 }
158 
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
A LinearRing is a LineString that is both closed and simple.
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
A point with x and y coordinate values.
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:47
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments...
MultiPoint is a GeometryCollection whose elements are restricted to points.
A class that computes the number of bytes necessary to encode a geometry in WKB.
Definition: WKBSize.h:44
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
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.
MultiLineString is a MultiCurve whose elements are LineStrings.
MultiPolygon is a MultiSurface whose elements are Polygons.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
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
A class that computes the number of bytes necessary to encode a geometry in WKB.
virtual std::size_t getNPoints() const _NOEXCEPT_OP(true)=0
it returns the number of points (vertexes) in the geometry.
std::size_t m_size
A counter for the number of bytes required to store a given geometry in WKB.
Definition: WKBSize.h:98
const double & getZ(std::size_t i) const
It returns the n-th z coordinate value.
const double & getM(std::size_t i) const
It returns the n-th m measure value.
It is a collection of other geometric objects.
void visit(const Curve &)
Definition: WKBSize.h:68
int getCoordinateDimension() const _NOEXCEPT_OP(true)
It returns the number of measurements or axes needed to describe a position in a coordinate system...
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:40