GEOS: WKBWriter.h Source File

GEOS 3.3.8

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

WKBWriter.h
1 /**********************************************************************
2 * $Id: WKBWriter.h 3068 2010-06-24 09:01:54Z strk $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2005-2006 Refractions Research Inc.
8 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9 *
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
14 *
15 **********************************************************************
16 *
17 * Last port: io/WKBWriter.java rev. 1.1 (JTS-1.7)
18 *
19 **********************************************************************/
20
21 #ifndef GEOS_IO_WKBWRITER_H
22 #define GEOS_IO_WKBWRITER_H
23
24 #include <geos/export.h>
25
26 #include <geos/util/Machine.h> // for getMachineByteOrder
27 #include <iosfwd>
28
29 // Forward declarations
30 namespace geos {
31 namespace geom {
32
33 class CoordinateSequence;
34 class Geometry;
35 class GeometryCollection;
36 class Point;
37 class LineString;
38 class LinearRing;
39 class Polygon;
40 class MultiPoint;
41 class MultiLineString;
42 class MultiPolygon;
43 class PrecisionModel;
44
45 } // namespace geom
46 } // namespace geos
47
48 namespace geos {
49 namespace io {
50
73 class GEOS_DLL WKBWriter {
74
75 public:
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(int dims=2, int bo=getMachineByteOrder(), bool includeSRID=false);
89
90 /*
91 * \brief
92 * Destructor.
93 */
94 virtual ~WKBWriter();
95
96 /*
97 * \brief
98 * Returns the output dimension used by the
99 * <code>WKBWriter</code>.
100 */
101 virtual int getOutputDimension() const { return defaultOutputDimension; }
102
103 /*
104 * Sets the output dimension used by the <code>WKBWriter</code>.
105 *
106 * @param newOutputDimension Supported values are 2 or 3.
107 * Note that 3 indicates up to 3 dimensions will be written but
108 * 2D WKB is still produced for 2D geometries.
109 */
110 virtual void setOutputDimension(int newOutputDimension);
111
112 /*
113 * \brief
114 * Returns the byte order used by the
115 * <code>WKBWriter</code>.
116 */
117 virtual int getByteOrder() const { return byteOrder; }
118
119 /*
120 * Sets the byte order used by the
121 * <code>WKBWriter</code>.
122 */
123 virtual void setByteOrder(int newByteOrder);
124
125 /*
126 * \brief
127 * Returns whether SRID values are output by the
128 * <code>WKBWriter</code>.
129 */
130 virtual int getIncludeSRID() const { return includeSRID; }
131
132 /*
133 * Sets whether SRID values should be output by the
134 * <code>WKBWriter</code>.
135 */
136 virtual void setIncludeSRID(int newIncludeSRID) { includeSRID = (0 == newIncludeSRID ? false : true); }
137
145 void write(const geom::Geometry &g, std::ostream &os);
146 // throws IOException, ParseException
147
155 void writeHEX(const geom::Geometry &g, std::ostream &os);
156 // throws IOException, ParseException
157
158 private:
159
160 int defaultOutputDimension;
161 int outputDimension;
162
163 int byteOrder;
164
165 bool includeSRID;
166
167 std::ostream *outStream;
168
169 unsigned char buf[8];
170
171 void writePoint(const geom::Point &p);
172 // throws IOException
173
174 void writeLineString(const geom::LineString &ls);
175 // throws IOException
176
177 void writePolygon(const geom::Polygon &p);
178 // throws IOException
179
180 void writeGeometryCollection(const geom::GeometryCollection &c, int wkbtype);
181 // throws IOException, ParseException
182
183 void writeCoordinateSequence(const geom::CoordinateSequence &cs, bool sized);
184 // throws IOException
185
186 void writeCoordinate(const geom::CoordinateSequence &cs, int idx, bool is3d);
187 // throws IOException
188
189 void writeGeometryType(int geometryType, int SRID);
190 // throws IOException
191
192 void writeSRID(int SRID);
193 // throws IOException
194
195 void writeByteOrder();
196 // throws IOException
197
198 void writeInt(int intValue);
199 // throws IOException
200
201 };
202
203 } // namespace io
204 } // namespace geos
205
206 #endif // #ifndef GEOS_IO_WKBWRITER_H
207
208 /**********************************************************************
209 * $Log$
210 * Revision 1.2 2006/03/28 11:26:13 strk
211 * ByteOrderDataInStream inlines moved to .inl file, updated
212 * implementation files includes.
213 *
214 * Revision 1.1 2006/03/20 18:18:14 strk
215 * io.h header split
216 *
217 **********************************************************************/