GEOS  3.8.0dev
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 
28 // Forward declarations
29 namespace geos {
30 namespace geom {
31 
32 class CoordinateSequence;
33 class Geometry;
34 class GeometryCollection;
35 class Point;
36 class LineString;
37 class LinearRing;
38 class Polygon;
39 class MultiPoint;
40 class MultiLineString;
41 class MultiPolygon;
42 class PrecisionModel;
43 
44 } // namespace geom
45 } // namespace geos
46 
47 namespace geos {
48 namespace io {
49 
72 class GEOS_DLL WKBWriter {
73 
74 public:
75  /*
76  * \brief
77  * Initializes writer with target coordinate dimension, endianness
78  * flag and SRID value.
79  *
80  * @param dims Supported values are 2 or 3. Note that 3 indicates
81  * up to 3 dimensions will be written but 2D WKB is still produced for 2D geometries.
82  * @param bo output byte order - default to native machine byte order.
83  * Legal values include 0 (big endian/xdr) and 1 (little endian/ndr).
84  * @param incudeSRID true if SRID should be included in WKB (an
85  * extension).
86  */
87  WKBWriter(int dims = 2, int bo = getMachineByteOrder(), bool includeSRID = false);
88 
89  /*
90  * \brief
91  * Destructor.
92  */
93  virtual ~WKBWriter();
94 
95  /*
96  * \brief
97  * Returns the output dimension used by the
98  * <code>WKBWriter</code>.
99  */
100  virtual int
101  getOutputDimension() const
102  {
103  return defaultOutputDimension;
104  }
105 
106  /*
107  * Sets the output dimension used by the <code>WKBWriter</code>.
108  *
109  * @param newOutputDimension Supported values are 2 or 3.
110  * Note that 3 indicates up to 3 dimensions will be written but
111  * 2D WKB is still produced for 2D geometries.
112  */
113  virtual void setOutputDimension(int newOutputDimension);
114 
115  /*
116  * \brief
117  * Returns the byte order used by the
118  * <code>WKBWriter</code>.
119  */
120  virtual int
121  getByteOrder() const
122  {
123  return byteOrder;
124  }
125 
126  /*
127  * Sets the byte order used by the
128  * <code>WKBWriter</code>.
129  */
130  virtual void setByteOrder(int newByteOrder);
131 
132  /*
133  * \brief
134  * Returns whether SRID values are output by the
135  * <code>WKBWriter</code>.
136  */
137  virtual int
138  getIncludeSRID() const
139  {
140  return includeSRID;
141  }
142 
143  /*
144  * Sets whether SRID values should be output by the
145  * <code>WKBWriter</code>.
146  */
147  virtual void
148  setIncludeSRID(int newIncludeSRID)
149  {
150  includeSRID = (0 == newIncludeSRID ? false : true);
151  }
152 
160  void write(const geom::Geometry& g, std::ostream& os);
161  // throws IOException, ParseException
162 
170  void writeHEX(const geom::Geometry& g, std::ostream& os);
171  // throws IOException, ParseException
172 
173 private:
174 
175  int defaultOutputDimension;
176  int outputDimension;
177 
178  int byteOrder;
179 
180  bool includeSRID;
181 
182  std::ostream* outStream;
183 
184  unsigned char buf[8];
185 
186  void writePoint(const geom::Point& p);
187  // throws IOException
188 
189  void writeLineString(const geom::LineString& ls);
190  // throws IOException
191 
192  void writePolygon(const geom::Polygon& p);
193  // throws IOException
194 
195  void writeGeometryCollection(const geom::GeometryCollection& c, int wkbtype);
196  // throws IOException, ParseException
197 
198  void writeCoordinateSequence(const geom::CoordinateSequence& cs, bool sized);
199  // throws IOException
200 
201  void writeCoordinate(const geom::CoordinateSequence& cs, size_t idx, bool is3d);
202  // throws IOException
203 
204  void writeGeometryType(int geometryType, int SRID);
205  // throws IOException
206 
207  void writeSRID(int SRID);
208  // throws IOException
209 
210  void writeByteOrder();
211  // throws IOException
212 
213  void writeInt(int intValue);
214  // throws IOException
215 
216 };
217 
218 } // namespace io
219 } // namespace geos
220 
221 #endif // #ifndef GEOS_IO_WKBWRITER_H
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:187
Definition: LineString.h:69
Represents a linear polygon, which may include holes.
Definition: Polygon.h:65
Writes a Geometry into Well-Known Binary format.
Definition: WKBWriter.h:72
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:55
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
Definition: Point.h:66