GEOS: WKBWriter.h Source File

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

- File List

# WKBWriter.h

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