GEOS 3.10.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 <geos/io/WKBConstants.h>
27#include <iosfwd>
28#include <cstdint>
29#include <cstddef>
30
31// Forward declarations
32namespace geos {
33namespace geom {
34
35class CoordinateSequence;
36class Geometry;
37class GeometryCollection;
38class Point;
39class LineString;
40class LinearRing;
41class Polygon;
42class MultiPoint;
43class MultiLineString;
44class MultiPolygon;
45class PrecisionModel;
46
47} // namespace geom
48} // namespace geos
49
50namespace geos {
51namespace io {
52
75class GEOS_DLL WKBWriter {
76
77public:
78 /*
79 * \brief
80 * Initializes writer with target coordinate dimension, endianness
81 * flag and SRID value.
82 *
83 * @param dims Supported values are 2 or 3. Note that 3 indicates
84 * up to 3 dimensions will be written but 2D WKB is still produced for 2D geometries.
85 * @param bo output byte order - default to native machine byte order.
86 * Legal values include 0 (big endian/xdr) and 1 (little endian/ndr).
87 * @param incudeSRID true if SRID should be included in WKB (an
88 * extension).
89 */
91 uint8_t dims = 2,
92 int bo = getMachineByteOrder(),
93 bool includeSRID = false,
94 int flv = WKBConstants::wkbExtended);
95
96 /*
97 * \brief
98 * Destructor.
99 */
100 ~WKBWriter() = default;
101
102 /*
103 * \brief
104 * Returns the output dimension used by the
105 * <code>WKBWriter</code>.
106 */
107 uint8_t
108 getOutputDimension() const
109 {
110 return defaultOutputDimension;
111 }
112
113 /*
114 * Sets the output dimension used by the <code>WKBWriter</code>.
115 *
116 * @param newOutputDimension Supported values are 2 or 3.
117 * Note that 3 indicates up to 3 dimensions will be written but
118 * 2D WKB is still produced for 2D geometries.
119 */
120 void setOutputDimension(uint8_t newOutputDimension);
121
122 /*
123 * \brief
124 * Returns the byte order used by the
125 * <code>WKBWriter</code>.
126 */
127 int
128 getByteOrder() const
129 {
130 return byteOrder;
131 }
132
133 /*
134 * Sets the byte order used by the
135 * <code>WKBWriter</code>.
136 */
137 void setByteOrder(int newByteOrder);
138
139 /*
140 * \brief
141 * Returns whether SRID values are output by the
142 * <code>WKBWriter</code>.
143 */
144 bool
145 getIncludeSRID() const
146 {
147 return includeSRID;
148 }
149
150 /*
151 * Sets whether SRID values should be output by the
152 * <code>WKBWriter</code>.
153 */
154 void
155 setIncludeSRID(bool newIncludeSRID)
156 {
157 includeSRID = newIncludeSRID;
158 }
159
160 /*
161 * \brief
162 * Returns the WKB flavor the writer will emit.
163 */
164 int
165 getFlavor() const
166 {
167 return flavor;
168 }
169
170 /*
171 * \brief
172 * Set the WKB flavor the writer will emit.
173 */
174 void setFlavor(int newFlavor);
175
183 void write(const geom::Geometry& g, std::ostream& os);
184 // throws IOException, ParseException
185
193 void writeHEX(const geom::Geometry& g, std::ostream& os);
194 // throws IOException, ParseException
195
196private:
197
198 // 2 or 3
199 uint8_t defaultOutputDimension;
200 uint8_t outputDimension;
201
202 // WKBConstants::wkbwkbXDR | WKBConstants::wkbNDR
203 int byteOrder;
204 // WKBConstants::wkbIso | WKBConstants::wkbExtended
205 int flavor;
206
207 bool includeSRID;
208
209 std::ostream* outStream;
210
211 unsigned char buf[8];
212
213 void writePoint(const geom::Point& p);
214 void writePointEmpty(const geom::Point& p);
215 // throws IOException
216
217 void writeLineString(const geom::LineString& ls);
218 // throws IOException
219
220 void writePolygon(const geom::Polygon& p);
221 // throws IOException
222
223 void writeGeometryCollection(const geom::GeometryCollection& c, int wkbtype);
224 // throws IOException, ParseException
225
226 void writeCoordinateSequence(const geom::CoordinateSequence& cs, bool sized);
227 // throws IOException
228
229 void writeCoordinate(const geom::CoordinateSequence& cs, std::size_t idx, bool is3d);
230 // throws IOException
231
232 void writeGeometryType(int geometryType, int SRID);
233 // throws IOException
234
235 void writeSRID(int SRID);
236 // throws IOException
237
238 void writeByteOrder();
239 // throws IOException
240
241 void writeInt(int intValue);
242 // throws IOException
243
244};
245
246} // namespace io
247} // namespace geos
248
249#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:75
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: geos.h:40