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

- File List

# WKTWriter.h

    00001 /**********************************************************************
    00002  * $Id: WKTWriter.h 3293 2011-04-22 13:51:38Z strk $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
    00008  * Copyright (C) 2005-2006 Refractions Research Inc.
    00009  * Copyright (C) 2001-2002 Vivid Solutions Inc.
    00010  *
    00011  * This is free software; you can redistribute and/or modify it under
    00012  * the terms of the GNU Lesser General Public Licence as published
    00013  * by the Free Software Foundation.
    00014  * See the COPYING file for more information.
    00015  *
    00016  **********************************************************************
    00017  *
    00018  * Last port: io/WKTWriter.java rev. 1.34 (JTS-1.7)
    00019  *
    00020  **********************************************************************/
    00021
    00022 #ifndef GEOS_IO_WKTWRITER_H
    00023 #define GEOS_IO_WKTWRITER_H
    00024
    00025 #include <geos/export.h>
    00026
    00027 #include <string>
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma warning(push)
    00031 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
    00032 #endif
    00033
    00034 // Forward declarations
    00035 namespace geos {
    00036         namespace geom {
    00037                 class Coordinate;
    00038                 class CoordinateSequence;
    00039                 class Geometry;
    00040                 class GeometryCollection;
    00041                 class Point;
    00042                 class LineString;
    00043                 class LinearRing;
    00044                 class Polygon;
    00045                 class MultiPoint;
    00046                 class MultiLineString;
    00047                 class MultiPolygon;
    00048                 class PrecisionModel;
    00049         }
    00050         namespace io {
    00051                 class Writer;
    00052         }
    00053 }
    00054
    00055
    00056 namespace geos {
    00057 namespace io {
    00058
    00080 class GEOS_DLL WKTWriter {
    00081 public:
    00082         WKTWriter();
    00083         ~WKTWriter();
    00084
    00085         //string(count, ch) can be used for this
    00086         //static string stringOfChar(char ch, int count);
    00087
    00089         std::string write(const geom::Geometry *geometry);
    00090
    00091         // Send Geometry's WKT to the given Writer
    00092         void write(const geom::Geometry *geometry, Writer *writer);
    00093
    00094         std::string writeFormatted(const geom::Geometry *geometry);
    00095
    00096         void writeFormatted(const geom::Geometry *geometry, Writer *writer);
    00097
    00105         static std::string toLineString(const geom::CoordinateSequence& seq);
    00106
    00115         static std::string toLineString(const geom::Coordinate& p0, const geom::Coordinate& p1);
    00116
    00124         static std::string toPoint(const geom::Coordinate& p0);
    00125
    00133         void setRoundingPrecision(int p0);
    00134
    00141         void setTrim(bool p0);
    00142
    00153         void setOld3D(bool useOld3D ) { old3D = useOld3D; }
    00154
    00155         /*
    00156          * \brief
    00157          * Returns the output dimension used by the
    00158          * <code>WKBWriter</code>.
    00159          */
    00160         int getOutputDimension() const { return defaultOutputDimension; }
    00161
    00162         /*
    00163          * Sets the output dimension used by the <code>WKBWriter</code>.
    00164          *
    00165          * @param newOutputDimension Supported values are 2 or 3.
    00166          *        Note that 3 indicates up to 3 dimensions will be
    00167          *        written but 2D WKB is still produced for 2D geometries.
    00168          */
    00169         void setOutputDimension(int newOutputDimension);
    00170
    00171 protected:
    00172
    00173   int decimalPlaces;
    00174
    00175         void appendGeometryTaggedText(const geom::Geometry *geometry, int level, Writer *writer);
    00176
    00177         void appendPointTaggedText(
    00178                         const geom::Coordinate* coordinate,
    00179                         int level, Writer *writer);
    00180
    00181         void appendLineStringTaggedText(
    00182                         const geom::LineString *lineString,
    00183                         int level, Writer *writer);
    00184
    00185         void appendLinearRingTaggedText(
    00186                         const geom::LinearRing *lineString,
    00187                         int level, Writer *writer);
    00188
    00189         void appendPolygonTaggedText(
    00190                         const geom::Polygon *polygon,
    00191                         int level, Writer *writer);
    00192
    00193         void appendMultiPointTaggedText(
    00194                         const geom::MultiPoint *multipoint,
    00195                         int level, Writer *writer);
    00196
    00197         void appendMultiLineStringTaggedText(
    00198                         const geom::MultiLineString *multiLineString,
    00199                         int level,Writer *writer);
    00200
    00201         void appendMultiPolygonTaggedText(
    00202                         const geom::MultiPolygon *multiPolygon,
    00203                         int level, Writer *writer);
    00204
    00205         void appendGeometryCollectionTaggedText(
    00206                         const geom::GeometryCollection *geometryCollection,
    00207                         int level,Writer *writer);
    00208
    00209         void appendPointText(const geom::Coordinate* coordinate, int level,
    00210                         Writer *writer);
    00211
    00212         void appendCoordinate(const geom::Coordinate* coordinate,
    00213                         Writer *writer);
    00214
    00215         std::string writeNumber(double d);
    00216
    00217         void appendLineStringText(
    00218                         const geom::LineString *lineString,
    00219                         int level, bool doIndent, Writer *writer);
    00220
    00221         void appendPolygonText(
    00222                         const geom::Polygon *polygon,
    00223                         int level, bool indentFirst, Writer *writer);
    00224
    00225         void appendMultiPointText(
    00226                         const geom::MultiPoint *multiPoint,
    00227                         int level, Writer *writer);
    00228
    00229         void appendMultiLineStringText(
    00230                         const geom::MultiLineString *multiLineString,
    00231                         int level, bool indentFirst,Writer *writer);
    00232
    00233         void appendMultiPolygonText(
    00234                         const geom::MultiPolygon *multiPolygon,
    00235                         int level, Writer *writer);
    00236
    00237         void appendGeometryCollectionText(
    00238                         const geom::GeometryCollection *geometryCollection,
    00239                         int level,Writer *writer);
    00240
    00241 private:
    00242
    00243         enum {
    00244                 INDENT = 2
    00245         };
    00246
    00247 //      static const int INDENT = 2;
    00248
    00249         bool isFormatted;
    00250
    00251         int roundingPrecision;
    00252
    00253         bool trim;
    00254
    00255         int level;
    00256
    00257         int defaultOutputDimension;
    00258     int outputDimension;
    00259     bool old3D;
    00260
    00261         void writeFormatted(
    00262                         const geom::Geometry *geometry,
    00263                         bool isFormatted, Writer *writer);
    00264
    00265         void indent(int level, Writer *writer);
    00266 };
    00267
    00268 } // namespace geos::io
    00269 } // namespace geos
    00270
    00271 #ifdef _MSC_VER
    00272 #pragma warning(pop)
    00273 #endif
    00274
    00275 #endif // #ifndef GEOS_IO_WKTWRITER_H
    00276
    00277 /**********************************************************************
    00278  * $Log$
    00279  * Revision 1.3  2006/06/12 16:55:53  strk
    00280  * fixed compiler warnings, fixed some methods to omit unused parameters.
    00281  *
    00282  * Revision 1.2  2006/03/22 16:58:35  strk
    00283  * Removed (almost) all inclusions of geom.h.
    00284  * Removed obsoleted .cpp files.
    00285  * Fixed a bug in WKTReader not using the provided CoordinateSequence
    00286  * implementation, optimized out some memory allocations.
    00287  *
    00288  * Revision 1.1  2006/03/20 18:18:15  strk
    00289  * io.h header split
    00290  *
    00291  **********************************************************************/