GEOS 3.9.1
WKBWriter.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2005-2006 Refractions Research Inc.
7 * Copyright (C) 2001-2002 Vivid Solutions Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: io/WKBWriter.java rev. 1.1 (JTS-1.7)
17 *
18 **********************************************************************/
19
20#ifndef GEOS_IO_WKBWRITER_H
21#define GEOS_IO_WKBWRITER_H
22
23#include <geos/export.h>
24
25#include <geos/util/Machine.h> // for getMachineByteOrder
26#include <iosfwd>
27#include <cstdint>
28
29// Forward declarations
30namespace geos {
31namespace geom {
32
33class CoordinateSequence;
34class Geometry;
35class GeometryCollection;
36class Point;
37class LineString;
38class LinearRing;
39class Polygon;
40class MultiPoint;
41class MultiLineString;
42class MultiPolygon;
43class PrecisionModel;
44
45} // namespace geom
46} // namespace geos
47
48namespace geos {
49namespace io {
50
73class GEOS_DLL WKBWriter {
74
75public:
76 /*
77 * \brief
78 * Initializes writer with target coordinate dimension, endianness
79 * flag and SRID value.
80 *
81 * @param dims Supported values are 2 or 3. Note that 3 indicates
82 * up to 3 dimensions will be written but 2D WKB is still produced for 2D geometries.
83 * @param bo output byte order - default to native machine byte order.
84 * Legal values include 0 (big endian/xdr) and 1 (little endian/ndr).
85 * @param incudeSRID true if SRID should be included in WKB (an
86 * extension).
87 */
88 WKBWriter(uint8_t dims = 2, int bo = getMachineByteOrder(), bool includeSRID = false);
89
90 /*
91 * \brief
92 * Destructor.
93 */
94 virtual ~WKBWriter() = default;
95
96 /*
97 * \brief
98 * Returns the output dimension used by the
99 * <code>WKBWriter</code>.
100 */
101 virtual uint8_t
102 getOutputDimension() const
103 {
104 return defaultOutputDimension;
105 }
106
107 /*
108 * Sets the output dimension used by the <code>WKBWriter</code>.
109 *
110 * @param newOutputDimension Supported values are 2 or 3.
111 * Note that 3 indicates up to 3 dimensions will be written but
112 * 2D WKB is still produced for 2D geometries.
113 */
114 virtual void setOutputDimension(uint8_t newOutputDimension);
115
116 /*
117 * \brief
118 * Returns the byte order used by the
119 * <code>WKBWriter</code>.
120 */
121 virtual int
122 getByteOrder() const
123 {
124 return byteOrder;
125 }
126
127 /*
128 * Sets the byte order used by the
129 * <code>WKBWriter</code>.
130 */
131 virtual void setByteOrder(int newByteOrder);
132
133 /*
134 * \brief
135 * Returns whether SRID values are output by the
136 * <code>WKBWriter</code>.
137 */
138 virtual bool
139 getIncludeSRID() const
140 {
141 return includeSRID;
142 }
143
144 /*
145 * Sets whether SRID values should be output by the
146 * <code>WKBWriter</code>.
147 */
148 virtual void
149 setIncludeSRID(bool newIncludeSRID)
150 {
151 includeSRID = newIncludeSRID;
152 }
153
161 void write(const geom::Geometry& g, std::ostream& os);
162 // throws IOException, ParseException
163
171 void writeHEX(const geom::Geometry& g, std::ostream& os);
172 // throws IOException, ParseException
173
174private:
175
176 uint8_t defaultOutputDimension;
177 uint8_t outputDimension;
178
179 int byteOrder;
180
181 bool includeSRID;
182
183 std::ostream* outStream;
184
185 unsigned char buf[8];
186
187 void writePoint(const geom::Point& p);
188 void writePointEmpty(const geom::Point& p);
189 // throws IOException
190
191 void writeLineString(const geom::LineString& ls);
192 // throws IOException
193
194 void writePolygon(const geom::Polygon& p);
195 // throws IOException
196
197 void writeGeometryCollection(const geom::GeometryCollection& c, int wkbtype);
198 // throws IOException, ParseException
199
200 void writeCoordinateSequence(const geom::CoordinateSequence& cs, bool sized);
201 // throws IOException
202
203 void writeCoordinate(const geom::CoordinateSequence& cs, size_t idx, bool is3d);
204 // throws IOException
205
206 void writeGeometryType(int geometryType, int SRID);
207 // throws IOException
208
209 void writeSRID(int SRID);
210 // throws IOException
211
212 void writeByteOrder();
213 // throws IOException
214
215 void writeInt(int intValue);
216 // throws IOException
217
218};
219
220} // namespace io
221} // namespace geos
222
223#endif // #ifndef GEOS_IO_WKBWRITER_H
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:55
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Definition: LineString.h:68
Definition: Point.h:66
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
Writes a Geometry into Well-Known Binary format.
Definition: WKBWriter.h:73
void writeHEX(const geom::Geometry &g, std::ostream &os)
Write a Geometry to an ostream in binary hex format.
void write(const geom::Geometry &g, std::ostream &os)
Write a Geometry to an ostream.
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26