Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

io.h

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

Generated on Fri Nov 26 21:30:45 2004 for GEOS by  doxygen 1.3.9.1