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