io.h

00001 /**********************************************************************
00002  * $Id: io.h,v 1.5.2.1 2005/05/23 18:16:40 strk Exp $
00003  *
00004  * GEOS - Geometry Engine Open Source
00005  * http://geos.refractions.net
00006  *
00007  * Copyright (C) 2001-2002 Vivid Solutions Inc.
00008  * Copyright (C) 2005 Refractions Research 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  * $Log: io.h,v $
00017  * Revision 1.5.2.1  2005/05/23 18:16:40  strk
00018  * more math.h to cmath conversions
00019  *
00020  * Revision 1.5  2004/07/19 10:33:12  strk
00021  * Class documentation changed to report geos.h as WKT writer/parser header file
00022  *
00023  * Revision 1.4  2004/07/08 19:34:49  strk
00024  * Mirrored JTS interface of CoordinateSequence, factory and
00025  * default implementations.
00026  * Added DefaultCoordinateSequenceFactory::instance() function.
00027  *
00028  * Revision 1.3  2004/07/07 10:29:54  strk
00029  * Adjusted exceptions documentation.
00030  *
00031  * Revision 1.2  2004/07/07 09:38:12  strk
00032  * Dropped WKTWriter::stringOfChars (implemented by std::string).
00033  * Dropped WKTWriter default constructor (internally created GeometryFactory).
00034  * Updated XMLTester to respect the changes.
00035  * Main documentation page made nicer.
00036  *
00037  * Revision 1.1  2004/07/02 13:20:42  strk
00038  * Header files moved under geos/ dir.
00039  *
00040  * Revision 1.15  2004/07/01 14:12:44  strk
00041  *
00042  * Geometry constructors come now in two flavors:
00043  *      - deep-copy args (pass-by-reference)
00044  *      - take-ownership of args (pass-by-pointer)
00045  * Same functionality is available through GeometryFactory,
00046  * including buildGeometry().
00047  *
00048  * Revision 1.14  2004/03/18 10:42:44  ybychkov
00049  * "IO" and "Util" upgraded to JTS 1.4
00050  * "Geometry" partially upgraded.
00051  *
00052  * Revision 1.13  2003/11/07 01:23:42  pramsey
00053  * Add standard CVS headers licence notices and copyrights to all cpp and h
00054  * files.
00055  *
00056  *
00057  **********************************************************************/
00058 
00059 
00060 #ifndef GEOS_IO_H
00061 #define GEOS_IO_H
00062 
00063 #include <memory>
00064 #include <iostream>
00065 #include <string>
00066 #include <geos/platform.h>
00067 #include <geos/geom.h>
00068 #include <geos/util.h>
00069 
00070 using namespace std;
00071 
00072 namespace geos {
00073 
00078 class ParseException: public GEOSException {
00079 public:
00080         ParseException();
00081         ParseException(string msg);
00082         ParseException(string msg, string var);
00083         ParseException(string msg, double num);
00084         ~ParseException();
00085 };
00086 
00087 class StringTokenizer {
00088 public:
00089         enum {
00090                 TT_EOF,
00091                 TT_EOL,
00092                 TT_NUMBER,
00093                 TT_WORD
00094         };
00095         StringTokenizer();
00096         StringTokenizer(string txt);
00097         ~StringTokenizer();
00098         int nextToken();
00099         int peekNextToken();
00100         double getNVal();
00101         string getSVal();
00102 private:
00103         string str;
00104         string stok;
00105         double ntok;
00106 };
00107 
00112 class WKTReader {
00113 public:
00114         //WKTReader();
00115 
00124         WKTReader(const GeometryFactory *gf);
00125 
00126         ~WKTReader();
00127 
00129         Geometry* read(string wellKnownText);
00130 
00131 //      Geometry* read(Reader reader);  //Not implemented yet
00132 
00133 protected:
00134         CoordinateSequence* getCoordinates(StringTokenizer *tokenizer);
00135         double getNextNumber(StringTokenizer *tokenizer);
00136         string getNextEmptyOrOpener(StringTokenizer *tokenizer);
00137         string getNextCloserOrComma(StringTokenizer *tokenizer);
00138         string getNextCloser(StringTokenizer *tokenizer);
00139         string getNextWord(StringTokenizer *tokenizer);
00140         Geometry* readGeometryTaggedText(StringTokenizer *tokenizer);
00141         Point* readPointText(StringTokenizer *tokenizer);
00142         LineString* readLineStringText(StringTokenizer *tokenizer);
00143         LinearRing* readLinearRingText(StringTokenizer *tokenizer);
00144         MultiPoint* readMultiPointText(StringTokenizer *tokenizer);
00145         Polygon* readPolygonText(StringTokenizer *tokenizer);
00146         MultiLineString* readMultiLineStringText(StringTokenizer *tokenizer);
00147         MultiPolygon* readMultiPolygonText(StringTokenizer *tokenizer);
00148         GeometryCollection* readGeometryCollectionText(StringTokenizer *tokenizer);
00149 private:
00150         const GeometryFactory *geometryFactory;
00151         const PrecisionModel *precisionModel;
00152         Coordinate* getPreciseCoordinate(StringTokenizer *tokenizer);
00153         bool isNumberNext(StringTokenizer *tokenizer);
00154 };
00155 
00156 class Writer {
00157 public:
00158         Writer();
00159         ~Writer();
00160         void write(string txt);
00161         string toString();
00162 private:
00163         string str;
00164 };
00165 
00187 class WKTWriter {
00188 public:
00189         WKTWriter();
00190         ~WKTWriter();
00191 
00192         //string(count, ch) can be used for this
00193         //static string stringOfChar(char ch, int count);
00194 
00196         string write(const Geometry *geometry);
00197 
00198         // Send Geometry's WKT to the given Writer
00199         void write(const Geometry *geometry, Writer *writer);
00200 
00201         string writeFormatted(const Geometry *geometry);
00202 
00203         void writeFormatted(const Geometry *geometry, Writer *writer);
00204 
00205 protected:
00206         string formatter;
00207         void appendGeometryTaggedText(const Geometry *geometry, int level, Writer *writer);
00208         void appendPointTaggedText(const Coordinate* coordinate, int level, Writer *writer, const PrecisionModel* precisionModel);
00209         void appendLineStringTaggedText(const LineString *lineString, int level, Writer *writer);
00210         void appendLinearRingTaggedText(const LinearRing *lineString, int level, Writer *writer);
00211         void appendPolygonTaggedText(const Polygon *polygon, int level, Writer *writer);
00212         void appendMultiPointTaggedText(const MultiPoint *multipoint, int level, Writer *writer);
00213         void appendMultiLineStringTaggedText(const MultiLineString *multiLineString, int level,Writer *writer);
00214         void appendMultiPolygonTaggedText(const MultiPolygon *multiPolygon, int level, Writer *writer);
00215         void appendGeometryCollectionTaggedText(const GeometryCollection *geometryCollection, int level,Writer *writer);
00216         void appendPointText(const Coordinate* coordinate, int level, Writer *writer, const PrecisionModel* precisionModel);
00217         void appendCoordinate(const Coordinate* coordinate, Writer *writer, const PrecisionModel* precisionModel);
00218         string writeNumber(double d);
00219         void appendLineStringText(const LineString *lineString, int level, bool doIndent, Writer *writer);
00220         void appendPolygonText(const Polygon *polygon, int level, bool indentFirst, Writer *writer);
00221         void appendMultiPointText(const MultiPoint *multiPoint, int level, Writer *writer);
00222         void appendMultiLineStringText(const MultiLineString *multiLineString, int level, bool indentFirst,Writer *writer);
00223         void appendMultiPolygonText(const MultiPolygon *multiPolygon, int level, Writer *writer);
00224         void appendGeometryCollectionText(const GeometryCollection *geometryCollection, int level,Writer *writer);
00225 private:
00226         enum {
00227                 INDENT = 2
00228         };
00229 //      static const int INDENT = 2;
00230         static string createFormatter(const PrecisionModel* precisionModel);
00231         bool isFormatted;
00232         int level;
00233         void writeFormatted(const Geometry *geometry, bool isFormatted, Writer *writer);
00234         void indent(int level, Writer *writer);
00235 };
00236 }
00237 #endif

Generated on Sun Dec 11 18:28:29 2005 for GEOS by  doxygen 1.4.5