GEOS  3.4.2
WKBWriter.h
00001 /**********************************************************************
00002  *
00003  * GEOS - Geometry Engine Open Source
00004  * http://geos.osgeo.org
00005  *
00006  * Copyright (C) 2005-2006 Refractions Research Inc.
00007  * Copyright (C) 2001-2002 Vivid Solutions Inc.
00008  *
00009  * This is free software; you can redistribute and/or modify it under
00010  * the terms of the GNU Lesser General Public Licence as published
00011  * by the Free Software Foundation. 
00012  * See the COPYING file for more information.
00013  *
00014  **********************************************************************
00015  *
00016  * Last port: io/WKBWriter.java rev. 1.1 (JTS-1.7)
00017  *
00018  **********************************************************************/
00019 
00020 #ifndef GEOS_IO_WKBWRITER_H
00021 #define GEOS_IO_WKBWRITER_H
00022 
00023 #include <geos/export.h>
00024 
00025 #include <geos/util/Machine.h> // for getMachineByteOrder
00026 #include <iosfwd>
00027 
00028 // Forward declarations
00029 namespace geos {
00030         namespace geom {
00031 
00032                 class CoordinateSequence;
00033                 class Geometry;
00034                 class GeometryCollection;
00035                 class Point;
00036                 class LineString;
00037                 class LinearRing;
00038                 class Polygon;
00039                 class MultiPoint;
00040                 class MultiLineString;
00041                 class MultiPolygon;
00042                 class PrecisionModel;
00043 
00044         } // namespace geom
00045 } // namespace geos
00046 
00047 namespace geos {
00048 namespace io {
00049 
00072 class GEOS_DLL WKBWriter {
00073 
00074 public:
00075         /*
00076          * \brief
00077          * Initializes writer with target coordinate dimension, endianness 
00078      * flag and SRID value.
00079      *
00080      * @param dims Supported values are 2 or 3.  Note that 3 indicates
00081      * up to 3 dimensions will be written but 2D WKB is still produced for 2D geometries.
00082      * @param bo output byte order - default to native machine byte order. 
00083      * Legal values include 0 (big endian/xdr) and 1 (little endian/ndr).
00084      * @param incudeSRID true if SRID should be included in WKB (an 
00085      * extension).
00086      */
00087         WKBWriter(int dims=2, int bo=getMachineByteOrder(), bool includeSRID=false);
00088 
00089         /*
00090          * \brief
00091          * Destructor.
00092          */
00093         virtual ~WKBWriter();
00094 
00095         /*
00096          * \brief
00097          * Returns the output dimension used by the
00098          * <code>WKBWriter</code>.
00099          */
00100         virtual int getOutputDimension() const { return defaultOutputDimension; }
00101 
00102         /*
00103          * Sets the output dimension used by the <code>WKBWriter</code>.  
00104          *
00105          * @param newOutputDimension Supported values are 2 or 3. 
00106          * Note that 3 indicates up to 3 dimensions will be written but
00107          * 2D WKB is still produced for 2D geometries.
00108          */
00109         virtual void setOutputDimension(int newOutputDimension);
00110         
00111         /*
00112          * \brief
00113          * Returns the byte order used by the
00114          * <code>WKBWriter</code>.
00115          */
00116         virtual int getByteOrder() const { return byteOrder; }
00117 
00118         /*
00119          * Sets the byte order used by the
00120          * <code>WKBWriter</code>.
00121          */
00122         virtual void setByteOrder(int newByteOrder);
00123 
00124         /*
00125          * \brief
00126          * Returns whether SRID values are output by the
00127          * <code>WKBWriter</code>.
00128          */
00129         virtual int getIncludeSRID() const { return includeSRID; }
00130 
00131         /*
00132          * Sets whether SRID values should be output by the
00133          * <code>WKBWriter</code>.
00134          */
00135         virtual void setIncludeSRID(int newIncludeSRID) { includeSRID = (0 == newIncludeSRID ? false : true); }
00136 
00144         void write(const geom::Geometry &g, std::ostream &os);
00145                 // throws IOException, ParseException
00146 
00154         void writeHEX(const geom::Geometry &g, std::ostream &os);
00155                 // throws IOException, ParseException
00156 
00157 private:
00158 
00159         int defaultOutputDimension;
00160     int outputDimension;
00161 
00162         int byteOrder;
00163         
00164         bool includeSRID;
00165 
00166         std::ostream *outStream;
00167 
00168         unsigned char buf[8];
00169 
00170         void writePoint(const geom::Point &p);
00171                 // throws IOException
00172 
00173         void writeLineString(const geom::LineString &ls);
00174                 // throws IOException
00175 
00176         void writePolygon(const geom::Polygon &p);
00177                 // throws IOException
00178 
00179         void writeGeometryCollection(const geom::GeometryCollection &c, int wkbtype);
00180                 // throws IOException, ParseException
00181 
00182         void writeCoordinateSequence(const geom::CoordinateSequence &cs, bool sized);
00183                 // throws IOException
00184 
00185         void writeCoordinate(const geom::CoordinateSequence &cs, int idx, bool is3d);
00186                 // throws IOException
00187 
00188         void writeGeometryType(int geometryType, int SRID);
00189                 // throws IOException
00190 
00191         void writeSRID(int SRID);
00192                 // throws IOException
00193 
00194         void writeByteOrder();
00195                 // throws IOException
00196 
00197         void writeInt(int intValue);
00198                 // throws IOException
00199 
00200 };
00201 
00202 } // namespace io
00203 } // namespace geos
00204 
00205 #endif // #ifndef GEOS_IO_WKBWRITER_H