GEOS  3.9.1dev
WKBWriter.h
Go to the documentation of this file.
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
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 
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(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
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
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 
174 private:
175 
178 
180 
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
uint8_t outputDimension
Definition: WKBWriter.h:177
virtual void setIncludeSRID(bool newIncludeSRID)
Definition: WKBWriter.h:149
#define GEOS_DLL
Definition: export.h:28
int getMachineByteOrder()
Definition: Machine.h:22
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
Writes a Geometry into Well-Known Binary format.
Definition: WKBWriter.h:73
std::ostream * outStream
Definition: WKBWriter.h:183
virtual bool getIncludeSRID() const
Definition: WKBWriter.h:139
Represents a collection of heterogeneous Geometry objects.
Basic namespace for all GEOS functionalities.
virtual uint8_t getOutputDimension() const
Definition: WKBWriter.h:102
virtual int getByteOrder() const
Definition: WKBWriter.h:122
The internal representation of a list of coordinates inside a Geometry.
uint8_t defaultOutputDimension
Definition: WKBWriter.h:176