WKBWriter.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/WKBWriter.h
22 
23  \brief A class that serializes a geometry to the WKB format.
24 */
25 
26 #ifndef __TERRALIB_GEOMETRY_INTERNAL_WKBWRITER_H
27 #define __TERRALIB_GEOMETRY_INTERNAL_WKBWRITER_H
28 
29 // TerraLib
30 #include "../common/Enums.h"
31 #include "Visitor.h"
32 
33 namespace te
34 {
35  namespace gm
36  {
37  /*!
38  \class WKBWriter
39 
40  \brief A class that serializes a geometry to the WKB format.
41 
42  \ingroup geometry
43 
44  \sa WKBReader
45  */
47  {
48  public:
49 
50  /*!
51  \brief It constructs a new WKB writer.
52 
53  \param wkb A pointer to a buffer to output the wkb. It must have at least the size in bytes necessary to write the WKB.
54  \param byteOrder The byte order to be used to encode the WKB.
55  */
57 
58  /*! \brief Destructor. */
60 
61  /*!
62  \brief It serializes the geometry to a WKB representation into the specified buffer.
63 
64  \param geom The geometry to be serialized.
65 
66  \note You must call reset in successive calls to this method.
67  */
68  void write(const Geometry* geom);
69 
70  /*!
71  \brief It serializes the geometry to a WKB representation into the specified buffer.
72 
73  The wkb parameter must have at least geom.getWkbSize() in order to be used. Don't
74  pass a NULL pointer or a buffer smaller than the size needed. Note that
75  the WKB will be on the specified byte order.
76 
77  \param geom The geometry to be serialized.
78  \param wkb The buffer where the geometry will be serialized.
79  \param byteOrder The byte order used to store/serialize the geometry.
80  */
81  static void write(const Geometry* geom, char* wkb, te::common::MachineByteOrder byteOrder = te::common::NDR);
82 
83  /*!
84  \brief It resets the WKB writer an allows a new geometry to be seriealized to a new buffer.
85 
86  \param wkb A pointer to a buffer to output the wkb. It must have at least the size in bytes necessary to write the WKB.
87  \param byteOrder The byte order to be used to encode the WKB.
88  */
89  void reset(char* wkb, te::common::MachineByteOrder byteOrder = te::common::NDR);
90 
91  protected:
92 
93  void visit(const Curve& /*visited*/) {}
94  void visit(const Geometry& /*visited*/) {}
95  void visit(const GeometryCollection& visited);
96  void visit(const LinearRing& visited);
97  void visit(const LineString& visited);
98  void visit(const MultiCurve& /*visited*/) {}
99  void visit(const MultiLineString& visited);
100  void visit(const MultiPoint& visited);
101  void visit(const MultiPolygon& visited);
102  void visit(const MultiSurface& /*visited*/) {}
103  void visit(const Point& visited);
104  void visit(const Polygon& visited);
105  void visit(const PolyhedralSurface& visited);
106  void visit(const Surface& /*visited*/) {}
107  void visit(const TIN& visited);
108  void visit(const Triangle& visited);
109  void visit(const CircularString& /*visited*/) {}
110  void visit(const CompoundCurve& /*visited*/) {}
111  void visit(const CurvePolygon& /*visited*/) {}
112 
113  private:
114 
115  char* m_wkb; //!< A pointer that marks the current position in a buffer to be write when parsing the geometry.
116  te::common::MachineByteOrder m_byteOrder; //!< The byte order used to encode the WKB.
117  };
118 
119  } // namespace gm
120 } // namespace te
121 
122 #endif // __TERRALIB_GEOMETRY_INTERNAL_WKBWRITER_H
CircularString is a curve with circular interpolation between points.
CompoundCurve is a curve that may have circular and linear segments.
Definition: CompoundCurve.h:54
CurvePolygon is a planar surface defined by 1 exterior boundary and 0 or more interior boundaries.
Definition: CurvePolygon.h:58
Curve is an abstract class that represents 1-dimensional geometric objects stored as a sequence of co...
Definition: Curve.h:59
It is a collection of other geometric objects.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
LineString is a curve with linear interpolation between points.
Definition: LineString.h:65
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:54
MultiCurve is a class that represents a 1-dimensional GeometryCollection whose elements are curves.
Definition: MultiCurve.h:51
MultiLineString is a MultiCurve whose elements are LineStrings.
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:54
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:51
MultiSurface is a class that represents a 2-dimensional GeometryCollection whose elements are surface...
Definition: MultiSurface.h:55
A point with x and y coordinate values.
Definition: Point.h:51
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:51
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments.
Surface is an abstract class that represents a 2-dimensional geometric objects.
Definition: Surface.h:55
TIN (triangulated irregular network) is a PolyhedralSurface consisting only of Triangle patches.
Definition: TIN.h:51
Triangle is a polygon with 3 distinct, non-collinear vertices and no interior boundary.
Definition: Triangle.h:51
A visitor interface for the Geometry hierarchy.
Definition: Visitor.h:45
A class that serializes a geometry to the WKB format.
Definition: WKBWriter.h:47
void visit(const Curve &)
Definition: WKBWriter.h:93
static void write(const Geometry *geom, char *wkb, te::common::MachineByteOrder byteOrder=te::common::NDR)
It serializes the geometry to a WKB representation into the specified buffer.
void visit(const LinearRing &visited)
void visit(const TIN &visited)
void visit(const Triangle &visited)
void reset(char *wkb, te::common::MachineByteOrder byteOrder=te::common::NDR)
It resets the WKB writer an allows a new geometry to be seriealized to a new buffer.
void visit(const MultiCurve &)
Definition: WKBWriter.h:98
void visit(const Point &visited)
void visit(const Polygon &visited)
void visit(const GeometryCollection &visited)
void write(const Geometry *geom)
It serializes the geometry to a WKB representation into the specified buffer.
void visit(const MultiPolygon &visited)
WKBWriter(char *wkb, te::common::MachineByteOrder byteOrder=te::common::NDR)
It constructs a new WKB writer.
~WKBWriter()
Destructor.
void visit(const PolyhedralSurface &visited)
void visit(const MultiLineString &visited)
void visit(const Geometry &)
Definition: WKBWriter.h:94
void visit(const Surface &)
Definition: WKBWriter.h:106
te::common::MachineByteOrder m_byteOrder
The byte order used to encode the WKB.
Definition: WKBWriter.h:116
void visit(const MultiPoint &visited)
char * m_wkb
A pointer that marks the current position in a buffer to be write when parsing the geometry.
Definition: WKBWriter.h:115
void visit(const CompoundCurve &)
Definition: WKBWriter.h:110
void visit(const MultiSurface &)
Definition: WKBWriter.h:102
void visit(const CurvePolygon &)
Definition: WKBWriter.h:111
void visit(const LineString &visited)
void visit(const CircularString &)
Definition: WKBWriter.h:109
MachineByteOrder
Endianness.
Definition: Enums.h:123
TerraLib.
A visitor interface for the SymbologyEncoding hierarchy.
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76