GEOS  3.6.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 
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 getOutputDimension() const { return defaultOutputDimension; }
101 
102  /*
103  * Sets the output dimension used by the <code>WKBWriter</code>.
104  *
105  * @param newOutputDimension Supported values are 2 or 3.
106  * Note that 3 indicates up to 3 dimensions will be written but
107  * 2D WKB is still produced for 2D geometries.
108  */
109  virtual void setOutputDimension(int newOutputDimension);
110 
111  /*
112  * \brief
113  * Returns the byte order used by the
114  * <code>WKBWriter</code>.
115  */
116  virtual int getByteOrder() const { return byteOrder; }
117 
118  /*
119  * Sets the byte order used by the
120  * <code>WKBWriter</code>.
121  */
122  virtual void setByteOrder(int newByteOrder);
123 
124  /*
125  * \brief
126  * Returns whether SRID values are output by the
127  * <code>WKBWriter</code>.
128  */
129  virtual int getIncludeSRID() const { return includeSRID; }
130 
131  /*
132  * Sets whether SRID values should be output by the
133  * <code>WKBWriter</code>.
134  */
135  virtual void setIncludeSRID(int newIncludeSRID) { includeSRID = (0 == newIncludeSRID ? false : true); }
136 
144  void write(const geom::Geometry &g, std::ostream &os);
145  // throws IOException, ParseException
146 
154  void writeHEX(const geom::Geometry &g, std::ostream &os);
155  // throws IOException, ParseException
156 
157 private:
158 
159  int defaultOutputDimension;
160  int outputDimension;
161 
162  int byteOrder;
163 
164  bool includeSRID;
165 
166  std::ostream *outStream;
167 
168  unsigned char buf[8];
169 
170  void writePoint(const geom::Point &p);
171  // throws IOException
172 
173  void writeLineString(const geom::LineString &ls);
174  // throws IOException
175 
176  void writePolygon(const geom::Polygon &p);
177  // throws IOException
178 
179  void writeGeometryCollection(const geom::GeometryCollection &c, int wkbtype);
180  // throws IOException, ParseException
181 
182  void writeCoordinateSequence(const geom::CoordinateSequence &cs, bool sized);
183  // throws IOException
184 
185  void writeCoordinate(const geom::CoordinateSequence &cs, int idx, bool is3d);
186  // throws IOException
187 
188  void writeGeometryType(int geometryType, int SRID);
189  // throws IOException
190 
191  void writeSRID(int SRID);
192  // throws IOException
193 
194  void writeByteOrder();
195  // throws IOException
196 
197  void writeInt(int intValue);
198  // throws IOException
199 
200 };
201 
202 } // namespace io
203 } // namespace geos
204 
205 #endif // #ifndef GEOS_IO_WKBWRITER_H
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:167
Definition: LineString.h:70
Represents a linear polygon, which may include holes.
Definition: Polygon.h:66
Writes a Geometry into Well-Known Binary format.
Definition: WKBWriter.h:72
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:56
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:59
Definition: Point.h:67